From dfff8cab10e130f6c2b8e846b7b11f015cf6c6d4 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Tue, 4 Feb 2025 11:37:21 +0100 Subject: [PATCH] fix(frontend): update categoryForm to use mutate --- .../src/app-components/buttons/FormButtons.tsx | 5 +---- .../src/app-components/dialogs/FormDialog.tsx | 4 ++-- .../src/components/categories/CategoryForm.tsx | 16 +++++----------- frontend/src/types/common/dialogs.types.ts | 12 ++++++------ 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/frontend/src/app-components/buttons/FormButtons.tsx b/frontend/src/app-components/buttons/FormButtons.tsx index 04a9f520..469b9cf5 100644 --- a/frontend/src/app-components/buttons/FormButtons.tsx +++ b/frontend/src/app-components/buttons/FormButtons.tsx @@ -13,10 +13,7 @@ import { Button, Grid } from "@mui/material"; import { useTranslate } from "@/hooks/useTranslate"; import { FormButtonsProps } from "@/types/common/dialogs.types"; -export const DialogFormButtons = ({ - onCancel, - onSubmit, -}: FormButtonsProps) => { +export const DialogFormButtons = ({ onCancel, onSubmit }: FormButtonsProps) => { const { t } = useTranslate(); return ( diff --git a/frontend/src/app-components/dialogs/FormDialog.tsx b/frontend/src/app-components/dialogs/FormDialog.tsx index 874d507a..8a5bfe24 100644 --- a/frontend/src/app-components/dialogs/FormDialog.tsx +++ b/frontend/src/app-components/dialogs/FormDialog.tsx @@ -13,12 +13,12 @@ import { FormDialogProps } from "@/types/common/dialogs.types"; import { DialogFormButtons } from "../buttons/FormButtons"; -export const FormDialog = ({ +export const FormDialog = ({ title, children, onSubmit, ...rest -}: FormDialogProps) => { +}: FormDialogProps) => { const handleClose = () => rest.onClose?.({}, "backdropClick"); return ( diff --git a/frontend/src/components/categories/CategoryForm.tsx b/frontend/src/components/categories/CategoryForm.tsx index 47bb9dcb..77d1d52a 100644 --- a/frontend/src/components/categories/CategoryForm.tsx +++ b/frontend/src/components/categories/CategoryForm.tsx @@ -37,14 +37,8 @@ export const CategoryForm: FC> = ({ toast.success(t("message.success_save")); }, }; - const { mutateAsync: createCategory } = useCreate( - EntityType.CATEGORY, - options, - ); - const { mutateAsync: updateCategory } = useUpdate( - EntityType.CATEGORY, - options, - ); + const { mutate: createCategory } = useCreate(EntityType.CATEGORY, options); + const { mutate: updateCategory } = useUpdate(EntityType.CATEGORY, options); const { reset, register, @@ -60,13 +54,13 @@ export const CategoryForm: FC> = ({ }; const onSubmitForm = async (params: ICategoryAttributes) => { if (data) { - return await updateCategory({ id: data.id, params }); + updateCategory({ id: data.id, params }); } else { - return await createCategory(params); + createCategory(params); } }; const submitAsync = async (e: BaseSyntheticEvent) => { - return await new Promise((resolve) => { + return await new Promise((resolve) => { handleSubmit((params) => { resolve(onSubmitForm(params)); })(e); diff --git a/frontend/src/types/common/dialogs.types.ts b/frontend/src/types/common/dialogs.types.ts index e4e9b8b2..52b88c07 100644 --- a/frontend/src/types/common/dialogs.types.ts +++ b/frontend/src/types/common/dialogs.types.ts @@ -137,10 +137,10 @@ export interface DialogProviderProps { } // form dialog -export interface FormDialogProps extends MuiDialogProps { +export interface FormDialogProps extends MuiDialogProps { title?: string; children?: React.ReactNode; - onSubmit: (e: BaseSyntheticEvent) => Promise; + onSubmit: (e: BaseSyntheticEvent) => void; } // form @@ -148,13 +148,13 @@ export type ComponentFormProps = { data: T | null; onError?: () => void; onSuccess?: () => void; - Wrapper?: React.FC>; - WrapperProps?: Partial>; + Wrapper?: React.FC; + WrapperProps?: Partial; }; -export interface FormButtonsProps { +export interface FormButtonsProps { onCancel?: () => void; - onSubmit: (e: BaseSyntheticEvent) => Promise; + onSubmit: (e: BaseSyntheticEvent) => void; } export type ComponentFormDialogProps = DialogProps;