mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix(frontend): support contentType default name value
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user