diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx
index 6dc674e..e08e873 100644
--- a/src/config/Paths.tsx
+++ b/src/config/Paths.tsx
@@ -77,5 +77,6 @@ export const Paths = {
print: {
list: '/print/list',
create: '/print/create',
+ update: '/print/update/',
}
}
\ No newline at end of file
diff --git a/src/pages/print/List.tsx b/src/pages/print/List.tsx
index aad4574..90cd314 100644
--- a/src/pages/print/List.tsx
+++ b/src/pages/print/List.tsx
@@ -3,7 +3,7 @@ import { useGetSections } from './hooks/usePrintData'
import { Link } from 'react-router-dom'
import { Paths } from '@/config/Paths'
import Button from '@/components/Button'
-import { AddSquare, More2 } from 'iconsax-react'
+import { AddSquare, Edit, More2 } from 'iconsax-react'
import Table from '@/components/Table'
const SectionList: FC = () => {
@@ -52,6 +52,24 @@ const SectionList: FC = () => {
)
}
},
+ {
+ key: 'actions',
+ title: '',
+ render: (item) => {
+ return (
+
+
+
+
+ {/* handleDelete(item.id)}
+ isloading={isDeleting}
+ colorIcon='red'
+ /> */}
+
+ )
+ }
+ },
]}
/>
diff --git a/src/pages/print/Update.tsx b/src/pages/print/Update.tsx
new file mode 100644
index 0000000..7252336
--- /dev/null
+++ b/src/pages/print/Update.tsx
@@ -0,0 +1,89 @@
+import Button from '@/components/Button'
+import { Edit } from 'iconsax-react'
+import { useEffect, type FC } from 'react'
+import { useGetSectionsDetail, useUpdateSection } from './hooks/usePrintData'
+import { useFormik } from 'formik'
+import type { CreateSectionType } from './types/Types'
+import * as Yup from 'yup'
+import { toast } from '@/shared/toast'
+import { useNavigate, useParams } from 'react-router-dom'
+import { extractErrorMessage } from '@/config/func'
+import Input from '@/components/Input'
+
+const UpdateSection: FC = () => {
+
+ const { id } = useParams()
+ const navigate = useNavigate()
+ const { data } = useGetSectionsDetail(+id!)
+ const { isPending, mutate } = useUpdateSection()
+
+ const formik = useFormik({
+ initialValues: {
+ order: 1,
+ title: ''
+ },
+ validationSchema: Yup.object({
+ title: Yup.string().required('این فیلد اجباری می باشد.')
+ }),
+ onSubmit: (values) => {
+ mutate({ id: +id!, params: values }, {
+ onSuccess: () => {
+ toast('با موفقیت ثبت شد', 'success')
+ navigate(-1)
+ },
+ onError: (error) => {
+ toast(extractErrorMessage(error), 'error')
+ }
+ })
+ }
+ })
+
+ useEffect(() => {
+
+ if (data?.data) {
+ formik.setValues({
+ ...data?.data
+ })
+ }
+
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [data])
+
+
+ return (
+
+
+
+
ویرایش بخش
+
+
+
+
+
+ )
+}
+
+export default UpdateSection
\ No newline at end of file
diff --git a/src/pages/print/hooks/usePrintData.ts b/src/pages/print/hooks/usePrintData.ts
index a769b61..d6568ad 100644
--- a/src/pages/print/hooks/usePrintData.ts
+++ b/src/pages/print/hooks/usePrintData.ts
@@ -1,5 +1,6 @@
-import { useMutation, useQuery } from "@tanstack/react-query";
+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import * as api from "../service/PrintService";
+import type { CreateSectionType } from "../types/Types";
export const useGetSections = () => {
return useQuery({
@@ -8,8 +9,31 @@ export const useGetSections = () => {
});
};
+export const useGetSectionsDetail = (id: number) => {
+ return useQuery({
+ queryKey: ["section", id],
+ queryFn: () => api.getSectionDetail(id),
+ });
+};
+
export const useCreateSection = () => {
return useMutation({
mutationFn: api.createSection,
});
};
+
+export const useUpdateSection = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: ({ id, params }: { id: number; params: CreateSectionType }) =>
+ api.updateSection(id, params),
+ onSuccess: (_, params) => {
+ queryClient.refetchQueries({
+ queryKey: ["sections"],
+ });
+ queryClient.refetchQueries({
+ queryKey: ["section", params.id],
+ });
+ },
+ });
+};
diff --git a/src/pages/print/service/PrintService.ts b/src/pages/print/service/PrintService.ts
index a033ad8..c4e1316 100644
--- a/src/pages/print/service/PrintService.ts
+++ b/src/pages/print/service/PrintService.ts
@@ -1,5 +1,9 @@
import axios from "@/config/axios";
-import type { CreateSectionType, SectionsResponseType } from "../types/Types";
+import type {
+ CreateSectionType,
+ SectionDetailResponseType,
+ SectionsResponseType,
+} from "../types/Types";
export const getSections = async () => {
const { data } = await axios.get(`/admin/section`);
@@ -10,3 +14,15 @@ export const createSection = async (params: CreateSectionType) => {
const { data } = await axios.post(`/admin/section`, params);
return data;
};
+
+export const updateSection = async (id: number, params: CreateSectionType) => {
+ const { data } = await axios.patch(`/admin/section/${id}`, params);
+ return data;
+};
+
+export const getSectionDetail = async (id: number) => {
+ const { data } = await axios.get(
+ `/admin/section/${id}`
+ );
+ return data;
+};
diff --git a/src/pages/print/types/Types.ts b/src/pages/print/types/Types.ts
index ae5b626..6355c08 100644
--- a/src/pages/print/types/Types.ts
+++ b/src/pages/print/types/Types.ts
@@ -13,3 +13,4 @@ export type SectionItemType = {
};
export type SectionsResponseType = BaseResponse;
+export type SectionDetailResponseType = BaseResponse;
diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx
index 5602212..e06aeaf 100644
--- a/src/router/MainRouter.tsx
+++ b/src/router/MainRouter.tsx
@@ -42,6 +42,7 @@ import NewOrder from '@/pages/order/NewOrder'
import EditOrder from '@/pages/order/EditOrder'
import SectionList from '@/pages/print/List'
import CreateSection from '@/pages/print/Create'
+import UpdateSection from '@/pages/print/Update'
const MainRouter: FC = () => {
return (
@@ -82,6 +83,7 @@ const MainRouter: FC = () => {
} />
} />
+ } />
} />
} />