mirror of
https://github.com/hexastack/hexabot
synced 2024-11-23 01:55:15 +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",
|
||||
"invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value",
|
||||
"regex_is_invalid": "Regex is invalid",
|
||||
"regex_is_empty": "Regex cannot be empty",
|
||||
"attachment_not_found": "Attachment is not found",
|
||||
"title_length_exceeded": "You have reached the maximum length",
|
||||
"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.",
|
||||
"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_empty": "Le regex ne peut pas être vide",
|
||||
"attachment_not_found": "La pièce jointe est introuvable",
|
||||
"title_length_exceeded": "Vous avez atteint la longueur maximale",
|
||||
"no_label_found": "Aucune étiquette trouvée",
|
||||
|
@ -32,12 +32,7 @@ import { ContentPostbackInput } from "./ContentPostbackInput";
|
||||
import { PostbackInput } from "./PostbackInput";
|
||||
|
||||
const isRegex = (str: Pattern) => {
|
||||
return (
|
||||
typeof str === "string" &&
|
||||
str.startsWith("/") &&
|
||||
str.endsWith("/") &&
|
||||
str.length > 1
|
||||
);
|
||||
return typeof str === "string" && str.startsWith("/") && str.endsWith("/");
|
||||
};
|
||||
const getType = (pattern: Pattern): PatternType => {
|
||||
if (isRegex(pattern)) {
|
||||
@ -270,10 +265,14 @@ const PatternInput: FC<PatternInputProps> = ({
|
||||
) : null}
|
||||
{typeof value === "string" && patternType === "regex" ? (
|
||||
<RegexInput
|
||||
{...registerInput(t("message.regex_is_invalid"), idx, {
|
||||
{...registerInput(t("message.regex_is_empty"), idx, {
|
||||
validate: (pattern) => {
|
||||
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;
|
||||
} catch (_e) {
|
||||
@ -285,6 +284,7 @@ const PatternInput: FC<PatternInputProps> = ({
|
||||
label={t("label.regex")}
|
||||
value={value.slice(1, -1)}
|
||||
onChange={(v) => onChange(v)}
|
||||
required
|
||||
/>
|
||||
) : null}
|
||||
{typeof value === "string" && patternType === "text" ? (
|
||||
|
Loading…
Reference in New Issue
Block a user