From c3cb697faeda06c313344858b23976d139dc49ab Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 2 Feb 2026 09:33:19 +0330 Subject: [PATCH] create section --- .env | 2 +- src/config/Paths.tsx | 3 +- src/pages/print/Create.tsx | 75 +++++++++++++++++++++++++ src/pages/print/List.tsx | 6 +- src/pages/print/hooks/usePrintData.ts | 8 ++- src/pages/print/service/PrintService.ts | 6 ++ src/pages/print/types/Types.ts | 4 ++ src/router/MainRouter.tsx | 2 + 8 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 src/pages/print/Create.tsx create mode 100644 src/pages/print/types/Types.ts diff --git a/.env b/.env index 71a052a..52ebffc 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -VITE_API_BASE_URL = 'http://192.168.99.220:4000' +VITE_API_BASE_URL = 'http://10.24.161.1:4000' VITE_TOKEN_NAME = 'negareh_at' VITE_REFRESH_TOKEN_NAME = 'negareh_art' \ No newline at end of file diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index 88162f4..6dc674e 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -75,6 +75,7 @@ export const Paths = { category: "/learning/category", }, print: { - list: '/print/list' + list: '/print/list', + create: '/print/create', } } \ No newline at end of file diff --git a/src/pages/print/Create.tsx b/src/pages/print/Create.tsx new file mode 100644 index 0000000..7cd571e --- /dev/null +++ b/src/pages/print/Create.tsx @@ -0,0 +1,75 @@ +import Button from '@/components/Button' +import { AddSquare } from 'iconsax-react' +import { type FC } from 'react' +import { useCreateSection } 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 } from 'react-router-dom' +import { extractErrorMessage } from '@/config/func' +import Input from '@/components/Input' + +const CreateSection: FC = () => { + + const navigate = useNavigate() + const { isPending, mutate } = useCreateSection() + + const formik = useFormik({ + initialValues: { + order: 1, + title: '' + }, + validationSchema: Yup.object({ + title: Yup.string().required('این فیلد اجباری می باشد.') + }), + onSubmit: (values) => { + mutate(values, { + onSuccess: () => { + toast('با موفقیت ثبت شد', 'success') + navigate(-1) + }, + onError: (error) => { + toast(extractErrorMessage(error), 'error') + } + }) + } + }) + + return ( +
+
+ +

دسته جدید

+ +
+
+
+ +
+
+ +
+
+ +
+ ) +} + +export default CreateSection \ No newline at end of file diff --git a/src/pages/print/List.tsx b/src/pages/print/List.tsx index ad1014f..1c75a10 100644 --- a/src/pages/print/List.tsx +++ b/src/pages/print/List.tsx @@ -12,17 +12,17 @@ const SectionList: FC = () => { return (
-

محصولات

+

بخش

diff --git a/src/pages/print/hooks/usePrintData.ts b/src/pages/print/hooks/usePrintData.ts index b2e2474..a769b61 100644 --- a/src/pages/print/hooks/usePrintData.ts +++ b/src/pages/print/hooks/usePrintData.ts @@ -1,4 +1,4 @@ -import { useQuery } from "@tanstack/react-query"; +import { useMutation, useQuery } from "@tanstack/react-query"; import * as api from "../service/PrintService"; export const useGetSections = () => { @@ -7,3 +7,9 @@ export const useGetSections = () => { queryFn: api.getSections, }); }; + +export const useCreateSection = () => { + return useMutation({ + mutationFn: api.createSection, + }); +}; diff --git a/src/pages/print/service/PrintService.ts b/src/pages/print/service/PrintService.ts index b48b03e..a0f0b1b 100644 --- a/src/pages/print/service/PrintService.ts +++ b/src/pages/print/service/PrintService.ts @@ -1,6 +1,12 @@ import axios from "@/config/axios"; +import type { CreateSectionType } from "../types/Types"; export const getSections = async () => { const { data } = await axios.get(`/admin/section`); return data; }; + +export const createSection = async (params: CreateSectionType) => { + const { data } = await axios.post(`/admin/section`, params); + return data; +}; diff --git a/src/pages/print/types/Types.ts b/src/pages/print/types/Types.ts new file mode 100644 index 0000000..3284944 --- /dev/null +++ b/src/pages/print/types/Types.ts @@ -0,0 +1,4 @@ +export type CreateSectionType = { + title: string; + order: number; +}; diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index 932a935..5602212 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -41,6 +41,7 @@ import OrderDetail from '@/pages/order/OrderDetail' import NewOrder from '@/pages/order/NewOrder' import EditOrder from '@/pages/order/EditOrder' import SectionList from '@/pages/print/List' +import CreateSection from '@/pages/print/Create' const MainRouter: FC = () => { return ( @@ -80,6 +81,7 @@ const MainRouter: FC = () => { } /> } /> + } /> } /> } />