From 9e029674e1fa49221946024f223f1f779172ee54 Mon Sep 17 00:00:00 2001 From: hexastack Date: Tue, 4 Feb 2025 16:21:31 +0100 Subject: [PATCH] fix: reset form --- .../content-types/ContentTypeDialog.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/content-types/ContentTypeDialog.tsx b/frontend/src/components/content-types/ContentTypeDialog.tsx index 854e4735..ca4bfacc 100644 --- a/frontend/src/components/content-types/ContentTypeDialog.tsx +++ b/frontend/src/components/content-types/ContentTypeDialog.tsx @@ -6,7 +6,6 @@ * 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 AddIcon from "@mui/icons-material/Add"; import { Button, Dialog, DialogActions, DialogContent } from "@mui/material"; import { FC, useEffect } from "react"; @@ -53,30 +52,34 @@ export const ContentTypeDialog: FC = ({ name: "fields", control, }); + const CloseAndReset = () => { + closeDialog(); + reset(); + }; + + useEffect(() => { + if (open) reset(); + }, [open, reset]); useEffect(() => { if (data) { reset({ name: data.name, - fields: data.fields, }); } else { reset(); } }, [data, reset]); - const { mutateAsync: createContentType } = useCreate( - EntityType.CONTENT_TYPE, - { - onError: (error) => { - toast.error(error); - }, - onSuccess: () => { - closeDialog(); - toast.success(t("message.success_save")); - }, + const { mutate: createContentType } = useCreate(EntityType.CONTENT_TYPE, { + onError: (error) => { + toast.error(error); }, - ); + onSuccess: () => { + closeDialog(); + toast.success(t("message.success_save")); + }, + }); const { mutateAsync: updateContentType } = useUpdate( EntityType.CONTENT_TYPE, { @@ -98,9 +101,9 @@ export const ContentTypeDialog: FC = ({ }; return ( - +
- + {data ? t("title.edit_content_type") : t("title.new_content_type")}