mirror of
https://github.com/hexastack/hexabot
synced 2025-04-06 22:14:26 +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",
|
||||
"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",
|
||||
|
@ -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",
|
||||
|
@ -52,7 +52,7 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
||||
name: "fields",
|
||||
control,
|
||||
});
|
||||
const CloseAndReset = () => {
|
||||
const closeAndReset = () => {
|
||||
closeDialog();
|
||||
reset({
|
||||
name: "",
|
||||
@ -79,6 +79,25 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
||||
},
|
||||
});
|
||||
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) {
|
||||
updateContentType({ id: data.id, params });
|
||||
} else {
|
||||
@ -104,9 +123,9 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
||||
}, [open, data, reset, replace]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} fullWidth onClose={CloseAndReset}>
|
||||
<Dialog open={open} fullWidth onClose={closeAndReset}>
|
||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||
<DialogTitle onClose={CloseAndReset}>
|
||||
<DialogTitle onClose={closeAndReset}>
|
||||
{data ? t("title.edit_content_type") : t("title.new_content_type")}
|
||||
</DialogTitle>
|
||||
<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:
|
||||
* 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 = ({
|
||||
<Controller
|
||||
control={props.control}
|
||||
name={`fields.${index}.label`}
|
||||
render={({ field }) => (
|
||||
rules={{ required: t("message.label_is_required") }}
|
||||
render={({ field, fieldState }) => (
|
||||
<Input
|
||||
disabled={props.disabled}
|
||||
{...field}
|
||||
label={t("label.label")}
|
||||
error={!!fieldState.error}
|
||||
helperText={fieldState.error?.message}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user