fix(frontend): update categoryForm to use mutate

This commit is contained in:
yassinedorbozgithub 2025-02-04 11:37:21 +01:00
parent 658bfbc924
commit dfff8cab10
4 changed files with 14 additions and 23 deletions

View File

@ -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 = <T,>({
onCancel,
onSubmit,
}: FormButtonsProps<T>) => {
export const DialogFormButtons = ({ onCancel, onSubmit }: FormButtonsProps) => {
const { t } = useTranslate();
return (

View File

@ -13,12 +13,12 @@ import { FormDialogProps } from "@/types/common/dialogs.types";
import { DialogFormButtons } from "../buttons/FormButtons";
export const FormDialog = <T,>({
export const FormDialog = ({
title,
children,
onSubmit,
...rest
}: FormDialogProps<T>) => {
}: FormDialogProps) => {
const handleClose = () => rest.onClose?.({}, "backdropClick");
return (

View File

@ -37,14 +37,8 @@ export const CategoryForm: FC<ComponentFormProps<ICategory>> = ({
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<ComponentFormProps<ICategory>> = ({
};
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<ICategory>((resolve) => {
return await new Promise<void>((resolve) => {
handleSubmit((params) => {
resolve(onSubmitForm(params));
})(e);

View File

@ -137,10 +137,10 @@ export interface DialogProviderProps {
}
// form dialog
export interface FormDialogProps<T> extends MuiDialogProps {
export interface FormDialogProps extends MuiDialogProps {
title?: string;
children?: React.ReactNode;
onSubmit: (e: BaseSyntheticEvent) => Promise<T>;
onSubmit: (e: BaseSyntheticEvent) => void;
}
// form
@ -148,13 +148,13 @@ export type ComponentFormProps<T> = {
data: T | null;
onError?: () => void;
onSuccess?: () => void;
Wrapper?: React.FC<FormDialogProps<T>>;
WrapperProps?: Partial<FormDialogProps<T>>;
Wrapper?: React.FC<FormDialogProps>;
WrapperProps?: Partial<FormDialogProps>;
};
export interface FormButtonsProps<T> {
export interface FormButtonsProps {
onCancel?: () => void;
onSubmit: (e: BaseSyntheticEvent) => Promise<T>;
onSubmit: (e: BaseSyntheticEvent) => void;
}
export type ComponentFormDialogProps<T> = DialogProps<T | null, boolean>;