mirror of
https://github.com/hexastack/hexabot
synced 2025-04-16 21:56:00 +00:00
fix: duplicate and empty fields value and typo
This commit is contained in:
parent
40bd6a3813
commit
d563530ccf
@ -112,7 +112,8 @@
|
|||||||
"text_is_required": "Text is required",
|
"text_is_required": "Text is required",
|
||||||
"invalid_file_type": "Invalid file type. Please select a file in the supported format.",
|
"invalid_file_type": "Invalid file type. Please select a file in the supported format.",
|
||||||
"select_category": "Select a flow",
|
"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": {
|
"menu": {
|
||||||
"terms": "Terms of Use",
|
"terms": "Terms of Use",
|
||||||
|
@ -112,7 +112,8 @@
|
|||||||
"text_is_required": "Texte requis",
|
"text_is_required": "Texte requis",
|
||||||
"invalid_file_type": "Type de fichier invalide. Veuillez choisir un fichier dans un format pris en charge.",
|
"invalid_file_type": "Type de fichier invalide. Veuillez choisir un fichier dans un format pris en charge.",
|
||||||
"select_category": "Sélectionner une catégorie",
|
"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": {
|
"menu": {
|
||||||
"terms": "Conditions d'utilisation",
|
"terms": "Conditions d'utilisation",
|
||||||
|
@ -52,7 +52,7 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
|||||||
name: "fields",
|
name: "fields",
|
||||||
control,
|
control,
|
||||||
});
|
});
|
||||||
const CloseAndReset = () => {
|
const closeAndReset = () => {
|
||||||
closeDialog();
|
closeDialog();
|
||||||
reset({
|
reset({
|
||||||
name: "",
|
name: "",
|
||||||
@ -79,6 +79,25 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const onSubmitForm = async (params) => {
|
const onSubmitForm = async (params) => {
|
||||||
|
const labelCounts: Record<string, number> = params.fields.reduce(
|
||||||
|
(acc, field) => {
|
||||||
|
if (!field.label.trim()) return acc;
|
||||||
|
acc[field.label] = (acc[field.label] || 0) + 1;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, number>,
|
||||||
|
);
|
||||||
|
const hasDuplicates = Object.values(labelCounts).some(
|
||||||
|
(count: number) => count > 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasDuplicates) {
|
||||||
|
toast.error(t("message.duplicate_labels_not_allowed"));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
updateContentType({ id: data.id, params });
|
updateContentType({ id: data.id, params });
|
||||||
} else {
|
} else {
|
||||||
@ -104,9 +123,9 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
|||||||
}, [open, data, reset, replace]);
|
}, [open, data, reset, replace]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} fullWidth onClose={CloseAndReset}>
|
<Dialog open={open} fullWidth onClose={closeAndReset}>
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<DialogTitle onClose={CloseAndReset}>
|
<DialogTitle onClose={closeAndReset}>
|
||||||
{data ? t("title.edit_content_type") : t("title.new_content_type")}
|
{data ? t("title.edit_content_type") : t("title.new_content_type")}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
@ -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:
|
* 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.
|
* 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).
|
* 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 DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
|
||||||
import { MenuItem } from "@mui/material";
|
import { MenuItem } from "@mui/material";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
@ -59,11 +60,14 @@ export const FieldInput = ({
|
|||||||
<Controller
|
<Controller
|
||||||
control={props.control}
|
control={props.control}
|
||||||
name={`fields.${index}.label`}
|
name={`fields.${index}.label`}
|
||||||
render={({ field }) => (
|
rules={{ required: t("message.label_is_required") }}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
<Input
|
<Input
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
{...field}
|
{...field}
|
||||||
label={t("label.label")}
|
label={t("label.label")}
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user