From a4aaf21803121978c7e8253e5866d2da33653cfd Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 29 Nov 2025 10:00:15 +0330 Subject: [PATCH] update category theme --- src/pages/theme/List.tsx | 2 +- src/pages/theme/Update.tsx | 102 ++++++++++++++++++++++++ src/pages/theme/hooks/useThemeData.ts | 31 +++++++ src/pages/theme/service/ThemeService.ts | 28 ++++++- src/pages/theme/type/Types.ts | 8 ++ src/router/Main.tsx | 2 + 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/pages/theme/Update.tsx diff --git a/src/pages/theme/List.tsx b/src/pages/theme/List.tsx index 98a1e21..2cf69fc 100644 --- a/src/pages/theme/List.tsx +++ b/src/pages/theme/List.tsx @@ -50,7 +50,7 @@ const ThemeList: FC = () => {
- + { + const { id } = useParams<{ id: string }>() + const navigate = useNavigate() + const { data } = useGetThemeById(id!) + const { mutate: updateTheme, isPending } = useUpdateTheme() + + const formik = useFormik({ + initialValues: { + title: '', + inputType: ThemeInputType.Color, + }, + validationSchema: Yup.object({ + title: Yup.string().required('عنوان تم الزامی است'), + inputType: Yup.string().required('نوع ورودی تم الزامی است'), + }), + onSubmit: (values) => { + updateTheme({ id: id!, params: values }, { + onSuccess: () => { + toast.success('تم با موفقیت ویرایش شد') + navigate(Pages.products.theme.list) + }, + onError: (error) => { + toast.error(extractErrorMessage(error)) + } + }) + }, + }) + + useEffect(() => { + if (data?.results?.data) { + formik.setValues({ + title: data?.results?.data?.title, + inputType: data?.results?.data?.inputType, + }) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [data]) + + return ( +
+ + +
+
+ +
+ +
+