From 2995bb86b41b6cfd24941296a68e7aec86666eea Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 24 Jan 2026 09:24:18 +0330 Subject: [PATCH] structure category product --- .env | 1 + package-lock.json | 11 ++++++++ package.json | 1 + src/config/Paths.tsx | 6 ++++- src/config/axios.ts | 2 +- src/pages/product/category/Create.tsx | 11 ++++++++ src/pages/product/category/List.tsx | 29 +++++++++++++++++++++ src/pages/product/hooks/useProductData.ts | 9 +++++++ src/pages/product/service/ProductService.ts | 7 +++++ src/pages/product/types/Types.ts | 16 ++++++++++++ src/router/MainRouter.tsx | 6 +++++ src/shared/types/Types.ts | 12 +++++++++ 12 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/pages/product/category/Create.tsx create mode 100644 src/pages/product/category/List.tsx create mode 100644 src/pages/product/hooks/useProductData.ts create mode 100644 src/pages/product/service/ProductService.ts create mode 100644 src/pages/product/types/Types.ts diff --git a/.env b/.env index c2ef360..0810ff4 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ +VITE_API_BASE_URL = 'http://172.27.64.88:4000' VITE_TOKEN_NAME = 'negareh_t' VITE_REFRESH_TOKEN_NAME = 'negareh_rt' \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 893b49b..93f110d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "react-infinite-scroll-component": "^6.1.0", "react-loading-skeleton": "^3.5.0", "react-multi-date-picker": "^4.5.2", + "react-otp-input": "^3.1.1", "react-router-dom": "^7.9.4", "react-spinners": "^0.17.0", "react-toastify": "^11.0.5", @@ -4493,6 +4494,16 @@ "react-dom": ">=16.8.0" } }, + "node_modules/react-otp-input": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/react-otp-input/-/react-otp-input-3.1.1.tgz", + "integrity": "sha512-bjPavgJ0/Zmf/AYi4onj8FbH93IjeD+e8pWwxIJreDEWsU1ILR5fs8jEJmMGWSBe/yyvPP6X/W6Mk9UkOCkTPw==", + "license": "MIT", + "peerDependencies": { + "react": ">=16.8.6 || ^17.0.0 || ^18.0.0", + "react-dom": ">=16.8.6 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react-refresh": { "version": "0.17.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz", diff --git a/package.json b/package.json index 574ea9d..7dc1b98 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "react-infinite-scroll-component": "^6.1.0", "react-loading-skeleton": "^3.5.0", "react-multi-date-picker": "^4.5.2", + "react-otp-input": "^3.1.1", "react-router-dom": "^7.9.4", "react-spinners": "^0.17.0", "react-toastify": "^11.0.5", diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index e2527cd..5b63c3d 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -4,7 +4,11 @@ export const Paths = { }, product: { list: '/product/list', - create: '/product/create' + create: '/product/create', + category: { + create: '/product/category/create', + list: '/product/category/list', + } }, order: { list: '/order/list' diff --git a/src/config/axios.ts b/src/config/axios.ts index 231213b..269b6d4 100644 --- a/src/config/axios.ts +++ b/src/config/axios.ts @@ -2,7 +2,7 @@ import axios from "axios"; import { getToken } from "./func"; const instance = axios.create({ - baseURL: import.meta.env.VITE_API_URL || "http://localhost:3000/api", + baseURL: import.meta.env.VITE_API_BASE_URL || "http://localhost:3000/api", timeout: 10000, }); diff --git a/src/pages/product/category/Create.tsx b/src/pages/product/category/Create.tsx new file mode 100644 index 0000000..5cb8ddf --- /dev/null +++ b/src/pages/product/category/Create.tsx @@ -0,0 +1,11 @@ +import { type FC } from 'react' + +const ProductCategory: FC = () => { + return ( +
+

دسته بندی محصولات

+
+ ) +} + +export default ProductCategory \ No newline at end of file diff --git a/src/pages/product/category/List.tsx b/src/pages/product/category/List.tsx new file mode 100644 index 0000000..59cb797 --- /dev/null +++ b/src/pages/product/category/List.tsx @@ -0,0 +1,29 @@ +import { type FC } from 'react' +import { useGetCategory } from '../hooks/useProductData' +import Table from '@/components/Table' +import type { RowDataType } from '@/components/types/TableTypes' +import type { CategoryType } from '../types/Types' + +const CategoryList: FC = () => { + + const { data } = useGetCategory() + + const column = [{ + title: 'عنوان', + key: 'title', + }] + + return ( +
+

دسته بندی محصولات

+ + + + + ) +} + +export default CategoryList \ No newline at end of file diff --git a/src/pages/product/hooks/useProductData.ts b/src/pages/product/hooks/useProductData.ts new file mode 100644 index 0000000..e41fed2 --- /dev/null +++ b/src/pages/product/hooks/useProductData.ts @@ -0,0 +1,9 @@ +import { useQuery } from "@tanstack/react-query"; +import * as api from "../service/ProductService"; + +export const useGetCategory = () => { + return useQuery({ + queryKey: ["category"], + queryFn: api.getCategory, + }); +}; diff --git a/src/pages/product/service/ProductService.ts b/src/pages/product/service/ProductService.ts new file mode 100644 index 0000000..c15e80c --- /dev/null +++ b/src/pages/product/service/ProductService.ts @@ -0,0 +1,7 @@ +import axios from "@/config/axios"; +import { type CategoriesResponse } from "../types/Types"; + +export const getCategory = async () => { + const { data } = await axios.get("/admin/category"); + return data; +}; diff --git a/src/pages/product/types/Types.ts b/src/pages/product/types/Types.ts new file mode 100644 index 0000000..be9a24a --- /dev/null +++ b/src/pages/product/types/Types.ts @@ -0,0 +1,16 @@ +import type { RowDataType } from "@/components/types/TableTypes"; +import { type BaseResponse } from "@/shared/types/Types"; + +export interface CategoryType extends RowDataType { + avatarUrl: string | null; + children: CategoryType[]; + createdAt: string; + deletedAt: string | null; + id: string; + isActive: boolean; + order: number | null; + parent: CategoryType | null; + title: string; +} + +export type CategoriesResponse = BaseResponse; diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index fab5509..6342395 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -25,6 +25,8 @@ import CriticismsDetail from '@/pages/criticisms/Detail' import LearningList from '@/pages/learning/List' import LearningCreate from '@/pages/learning/Create' import LearningCategory from '@/pages/learning/Category' +import CategoryList from '@/pages/product/category/List' +import CreateCategory from '@/pages/learning/components/CreateCategory' const MainRouter: FC = () => { return (
@@ -40,8 +42,12 @@ const MainRouter: FC = () => { } /> } /> } /> + } /> } /> + } /> + } /> + } /> } /> } /> diff --git a/src/shared/types/Types.ts b/src/shared/types/Types.ts index 99a81ed..c8cf3eb 100644 --- a/src/shared/types/Types.ts +++ b/src/shared/types/Types.ts @@ -2,3 +2,15 @@ export type SharedStoreType = { openSidebar: boolean; setOpenSidebar: (open: boolean) => void; }; + +export interface BaseResponse { + success: boolean; + statusCode: number; + data: T; + meta?: { + limit: number; + page: number; + total: number; + totalPages: number; + }; +}