fix(frontend): apply feedback

This commit is contained in:
yassinedorbozgithub 2025-06-05 16:53:27 +01:00
parent 74beb9426c
commit da5200eb1b
2 changed files with 15 additions and 12 deletions

View File

@ -131,9 +131,14 @@ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
gap={2}
>
<FieldInput
{...{ index, remove, control, setValue }}
uuid={f.uuid}
index={index}
remove={remove}
control={control}
setValue={setValue}
disabled={READ_ONLY_FIELDS.includes(f.label as any)}
contentTypeField={contentType?.fields?.find(
({ uuid }) => uuid === f.uuid,
)}
/>
</ContentItem>
))}

View File

@ -18,13 +18,17 @@ import {
import { IconButton } from "@/app-components/buttons/IconButton";
import { Input } from "@/app-components/inputs/Input";
import { useTranslate } from "@/hooks/useTranslate";
import { ContentFieldType, IContentType } from "@/types/content-type.types";
import {
ContentField,
ContentFieldType,
IContentType,
} from "@/types/content-type.types";
import { slugify } from "@/utils/string";
export const FieldInput = ({
setValue,
index,
uuid,
contentTypeField,
...props
}: {
index: number;
@ -32,7 +36,7 @@ export const FieldInput = ({
remove: UseFieldArrayRemove;
control: Control<IContentType>;
setValue: UseFormSetValue<IContentType>;
uuid?: string;
contentTypeField?: ContentField;
}) => {
const { t } = useTranslate();
@ -61,14 +65,8 @@ export const FieldInput = ({
helperText={fieldState.error?.message}
onChange={(e) => {
const currentValue = e.target.value;
const { label, name } =
props.control._defaultValues.fields?.find(
(field) => field?.uuid === uuid,
) || {};
if (label && name !== slugify(label)) {
name && setValue(`fields.${index}.name`, name);
} else {
if (!contentTypeField?.label || !contentTypeField?.name) {
setValue(
`fields.${index}.name`,
currentValue ? slugify(currentValue) : "",