From d563530ccfb8004e18d4bf8a8937ad3e82f9b1a6 Mon Sep 17 00:00:00 2001 From: hexastack Date: Thu, 6 Feb 2025 10:36:09 +0100 Subject: [PATCH] fix: duplicate and empty fields value and typo --- frontend/public/locales/en/translation.json | 3 ++- frontend/public/locales/fr/translation.json | 3 ++- .../content-types/ContentTypeDialog.tsx | 25 ++++++++++++++++--- .../content-types/components/FieldInput.tsx | 8 ++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json index 7474b471..5a762558 100644 --- a/frontend/public/locales/en/translation.json +++ b/frontend/public/locales/en/translation.json @@ -112,7 +112,8 @@ "text_is_required": "Text is required", "invalid_file_type": "Invalid file type. Please select a file in the supported format.", "select_category": "Select a flow", - "logout_failed": "Something went wrong during logout" + "logout_failed": "Something went wrong during logout", + "duplicate_labels_not_allowed": "Duplicate labels are not allowed" }, "menu": { "terms": "Terms of Use", diff --git a/frontend/public/locales/fr/translation.json b/frontend/public/locales/fr/translation.json index 2bb48ec8..aadde707 100644 --- a/frontend/public/locales/fr/translation.json +++ b/frontend/public/locales/fr/translation.json @@ -112,7 +112,8 @@ "text_is_required": "Texte requis", "invalid_file_type": "Type de fichier invalide. Veuillez choisir un fichier dans un format pris en charge.", "select_category": "Sélectionner une catégorie", - "logout_failed": "Une erreur s'est produite lors de la déconnexion" + "logout_failed": "Une erreur s'est produite lors de la déconnexion", + "duplicate_labels_not_allowed": "Les étiquettes en double ne sont pas autorisées" }, "menu": { "terms": "Conditions d'utilisation", diff --git a/frontend/src/components/content-types/ContentTypeDialog.tsx b/frontend/src/components/content-types/ContentTypeDialog.tsx index 91547560..9dada742 100644 --- a/frontend/src/components/content-types/ContentTypeDialog.tsx +++ b/frontend/src/components/content-types/ContentTypeDialog.tsx @@ -52,7 +52,7 @@ export const ContentTypeDialog: FC = ({ name: "fields", control, }); - const CloseAndReset = () => { + const closeAndReset = () => { closeDialog(); reset({ name: "", @@ -79,6 +79,25 @@ export const ContentTypeDialog: FC = ({ }, }); const onSubmitForm = async (params) => { + const labelCounts: Record = params.fields.reduce( + (acc, field) => { + if (!field.label.trim()) return acc; + acc[field.label] = (acc[field.label] || 0) + 1; + + return acc; + }, + {} as Record, + ); + const hasDuplicates = Object.values(labelCounts).some( + (count: number) => count > 1, + ); + + if (hasDuplicates) { + toast.error(t("message.duplicate_labels_not_allowed")); + + return; + } + if (data) { updateContentType({ id: data.id, params }); } else { @@ -104,9 +123,9 @@ export const ContentTypeDialog: FC = ({ }, [open, data, reset, replace]); return ( - +
- + {data ? t("title.edit_content_type") : t("title.new_content_type")} diff --git a/frontend/src/components/content-types/components/FieldInput.tsx b/frontend/src/components/content-types/components/FieldInput.tsx index 5d5d5b3c..74455ac4 100644 --- a/frontend/src/components/content-types/components/FieldInput.tsx +++ b/frontend/src/components/content-types/components/FieldInput.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; import { MenuItem } from "@mui/material"; import { useEffect } from "react"; @@ -59,11 +60,14 @@ export const FieldInput = ({ ( + rules={{ required: t("message.label_is_required") }} + render={({ field, fieldState }) => ( )} />