fix(frontend): support contentType default name value

This commit is contained in:
yassinedorbozgithub
2025-06-02 10:42:13 +01:00
parent 420f81d853
commit 8d67cf69cd
2 changed files with 11 additions and 1 deletions

View File

@@ -130,6 +130,8 @@ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
gap={2}
>
<FieldInput
defaultLabel={contentType?.fields?.[index]?.label}
defaultName={contentType?.fields?.[index]?.name}
setValue={setValue}
control={control}
remove={remove}

View File

@@ -26,6 +26,8 @@ import { slugify } from "@/utils/string";
export const FieldInput = ({
setValue,
index,
defaultLabel,
defaultName,
...props
}: {
index: number;
@@ -33,6 +35,8 @@ export const FieldInput = ({
remove: UseFieldArrayRemove;
control: Control<Partial<IContentType>>;
setValue: UseFormSetValue<Partial<IContentType>>;
defaultLabel?: string;
defaultName?: string;
}) => {
const { t } = useTranslate();
const label = useWatch({
@@ -41,7 +45,11 @@ export const FieldInput = ({
});
useEffect(() => {
setValue(`fields.${index}.name`, label ? slugify(label) : "");
if (defaultLabel && defaultName !== slugify(defaultLabel)) {
defaultName && setValue(`fields.${index}.name`, defaultName);
} else {
setValue(`fields.${index}.name`, label ? slugify(label) : "");
}
}, [label, setValue, index]);
return (