mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(frontend): enhance empty regex+invalid regex+UI issue
This commit is contained in:
parent
fac05d3721
commit
84e27094f7
@ -100,6 +100,7 @@
|
|||||||
"no_content_type": "No content type available, please create one first",
|
"no_content_type": "No content type available, please create one first",
|
||||||
"invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value",
|
"invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value",
|
||||||
"regex_is_invalid": "Regex is invalid",
|
"regex_is_invalid": "Regex is invalid",
|
||||||
|
"regex_is_empty": "Regex cannot be empty",
|
||||||
"attachment_not_found": "Attachment is not found",
|
"attachment_not_found": "Attachment is not found",
|
||||||
"title_length_exceeded": "You have reached the maximum length",
|
"title_length_exceeded": "You have reached the maximum length",
|
||||||
"no_label_found": "No label found",
|
"no_label_found": "No label found",
|
||||||
|
@ -100,6 +100,7 @@
|
|||||||
"no_content_type": "Il n'y a aucun type de contenu pour le moment, veuillez en ajouter un.",
|
"no_content_type": "Il n'y a aucun type de contenu pour le moment, veuillez en ajouter un.",
|
||||||
"invalid_max_fallback_attempt_limit": "La limite des tentatives de secours doit être un nombre positif.",
|
"invalid_max_fallback_attempt_limit": "La limite des tentatives de secours doit être un nombre positif.",
|
||||||
"regex_is_invalid": "Le regex est invalide",
|
"regex_is_invalid": "Le regex est invalide",
|
||||||
|
"regex_is_empty": "Le regex ne peut pas être vide",
|
||||||
"attachment_not_found": "La pièce jointe est introuvable",
|
"attachment_not_found": "La pièce jointe est introuvable",
|
||||||
"title_length_exceeded": "Vous avez atteint la longueur maximale",
|
"title_length_exceeded": "Vous avez atteint la longueur maximale",
|
||||||
"no_label_found": "Aucune étiquette trouvée",
|
"no_label_found": "Aucune étiquette trouvée",
|
||||||
|
@ -32,12 +32,7 @@ import { ContentPostbackInput } from "./ContentPostbackInput";
|
|||||||
import { PostbackInput } from "./PostbackInput";
|
import { PostbackInput } from "./PostbackInput";
|
||||||
|
|
||||||
const isRegex = (str: Pattern) => {
|
const isRegex = (str: Pattern) => {
|
||||||
return (
|
return typeof str === "string" && str.startsWith("/") && str.endsWith("/");
|
||||||
typeof str === "string" &&
|
|
||||||
str.startsWith("/") &&
|
|
||||||
str.endsWith("/") &&
|
|
||||||
str.length > 1
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
const getType = (pattern: Pattern): PatternType => {
|
const getType = (pattern: Pattern): PatternType => {
|
||||||
if (isRegex(pattern)) {
|
if (isRegex(pattern)) {
|
||||||
@ -270,10 +265,14 @@ const PatternInput: FC<PatternInputProps> = ({
|
|||||||
) : null}
|
) : null}
|
||||||
{typeof value === "string" && patternType === "regex" ? (
|
{typeof value === "string" && patternType === "regex" ? (
|
||||||
<RegexInput
|
<RegexInput
|
||||||
{...registerInput(t("message.regex_is_invalid"), idx, {
|
{...registerInput(t("message.regex_is_empty"), idx, {
|
||||||
validate: (pattern) => {
|
validate: (pattern) => {
|
||||||
try {
|
try {
|
||||||
new RegExp(pattern.slice(1, -1));
|
const parsedPattern = new RegExp(pattern.slice(1, -1));
|
||||||
|
|
||||||
|
if (String(parsedPattern) !== pattern) {
|
||||||
|
throw t("message.regex_is_invalid");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
@ -285,6 +284,7 @@ const PatternInput: FC<PatternInputProps> = ({
|
|||||||
label={t("label.regex")}
|
label={t("label.regex")}
|
||||||
value={value.slice(1, -1)}
|
value={value.slice(1, -1)}
|
||||||
onChange={(v) => onChange(v)}
|
onChange={(v) => onChange(v)}
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{typeof value === "string" && patternType === "text" ? (
|
{typeof value === "string" && patternType === "text" ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user