From d54fab07d0b9e8cee767723854767c61df19d3aa Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Thu, 29 May 2025 07:19:28 +0100 Subject: [PATCH] fix(frontend): add limit validation based on block list type --- frontend/public/locales/en/translation.json | 1 + frontend/public/locales/fr/translation.json | 1 + .../visual-editor/form/ListMessageForm.tsx | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json index 703cf684..fd7b1ec1 100644 --- a/frontend/public/locales/en/translation.json +++ b/frontend/public/locales/en/translation.json @@ -103,6 +103,7 @@ "message_is_required": "Message is required", "context_var_is_required": "You need to add a context variable", "invalid_list_limit": "List limit must be >=2 and <= 4", + "invalid_carousel_limit": "List limit must be >=1 and <= 10", "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", diff --git a/frontend/public/locales/fr/translation.json b/frontend/public/locales/fr/translation.json index 783f03dc..0e746c98 100644 --- a/frontend/public/locales/fr/translation.json +++ b/frontend/public/locales/fr/translation.json @@ -103,6 +103,7 @@ "message_is_required": "Le message est requis", "context_var_is_required": "Vous devez ajouter une variable contextuelle", "invalid_list_limit": "La limite doit être >=2 et <= 4", + "invalid_carousel_limit": "La limite doit être >=1 et <= 10", "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", diff --git a/frontend/src/components/visual-editor/form/ListMessageForm.tsx b/frontend/src/components/visual-editor/form/ListMessageForm.tsx index f4b4e786..4a4caecc 100644 --- a/frontend/src/components/visual-editor/form/ListMessageForm.tsx +++ b/frontend/src/components/visual-editor/form/ListMessageForm.tsx @@ -120,9 +120,19 @@ const ListMessageForm = () => { }} {...register("options.content.limit", { validate: { - min: (value) => - (value && value >= 2 && value <= 4) || - t("message.invalid_list_limit"), + min: (value) => { + if ( + displayMode === OutgoingMessageFormat.list && + (value < 2 || value > 4) + ) { + return t("message.invalid_list_limit"); + } else if ( + displayMode === OutgoingMessageFormat.carousel && + (value < 1 || value > 10) + ) { + return t("message.invalid_carousel_limit"); + } + }, }, valueAsNumber: true, })}