fix(frontend): apply feedback

This commit is contained in:
yassinedorbozgithub 2025-06-10 09:43:00 +01:00
parent e528dcc2c2
commit 8490d4f253
2 changed files with 3 additions and 16 deletions

View File

@ -8,7 +8,7 @@
import AddIcon from "@mui/icons-material/Add"; import AddIcon from "@mui/icons-material/Add";
import { Button } from "@mui/material"; import { Button } from "@mui/material";
import { FC, Fragment, useMemo } from "react"; import { FC, Fragment } from "react";
import { useFieldArray, useForm } from "react-hook-form"; import { useFieldArray, useForm } from "react-hook-form";
import { ContentContainer, ContentItem } from "@/app-components/dialogs"; import { ContentContainer, ContentItem } from "@/app-components/dialogs";
@ -24,29 +24,17 @@ import {
IContentType, IContentType,
IContentTypeAttributes, IContentTypeAttributes,
} from "@/types/content-type.types"; } from "@/types/content-type.types";
import { generateId } from "@/utils/generateId";
import { slugify } from "@/utils/string"; import { slugify } from "@/utils/string";
import { FieldInput } from "./components/FieldInput"; import { FieldInput } from "./components/FieldInput";
import { FIELDS_FORM_DEFAULT_VALUES } from "./constants"; import { FIELDS_FORM_DEFAULT_VALUES } from "./constants";
export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
data: { defaultValues: contentTypeWithoutUuid }, data: { defaultValues: contentType },
Wrapper = Fragment, Wrapper = Fragment,
WrapperProps, WrapperProps,
...rest ...rest
}) => { }) => {
const contentType = useMemo(
() =>
contentTypeWithoutUuid && {
...contentTypeWithoutUuid,
fields: contentTypeWithoutUuid?.fields?.map((field) => ({
...field,
uuid: generateId(),
})),
},
[contentTypeWithoutUuid],
);
const { toast } = useToast(); const { toast } = useToast();
const { t } = useTranslate(); const { t } = useTranslate();
const { const {
@ -140,7 +128,7 @@ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
control={control} control={control}
onLabelChange={(value) => { onLabelChange={(value) => {
const fieldName = contentType?.fields?.find( const fieldName = contentType?.fields?.find(
({ uuid }) => uuid === field.uuid, ({ name }) => name === field.name,
)?.name; )?.name;
if (!fieldName) { if (!fieldName) {

View File

@ -23,7 +23,6 @@ export type ContentField = {
name: string; name: string;
label: string; label: string;
type: ContentFieldType; type: ContentFieldType;
uuid?: string;
}; };
export interface IContentTypeAttributes { export interface IContentTypeAttributes {