From 36766888494259d9738142ada904570b72a0d91f Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Fri, 24 Jul 2026 18:16:47 +0330 Subject: [PATCH] up --- src/config/Paths.tsx | 2 +- src/pages/product/Create.tsx | 8 +- src/pages/product/List.tsx | 4 + src/pages/product/category/Create.tsx | 104 +++++++++++--------- src/pages/product/category/List.tsx | 78 +++++++++------ src/pages/product/hooks/useProductData.ts | 5 +- src/pages/product/service/ProductService.ts | 2 + src/router/MainRouter.tsx | 3 +- 8 files changed, 122 insertions(+), 84 deletions(-) diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index f24df0f..d88c187 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -8,8 +8,8 @@ export const Paths = { create: '/product/create', update: '/product/update/', category: { - create: '/product/category/create', list: '/product/category/list', + children: '/product/category/list/', update: '/product/category/update/', }, attribute: { diff --git a/src/pages/product/Create.tsx b/src/pages/product/Create.tsx index c45a678..c8276c7 100644 --- a/src/pages/product/Create.tsx +++ b/src/pages/product/Create.tsx @@ -15,6 +15,8 @@ import { toast } from 'react-toastify'; import type { ErrorType } from '@/helpers/types'; import { extractErrorMessage } from '@/config/func'; import { useNavigate } from 'react-router-dom'; +import { Paths } from '@/config/Paths' +import BackButton from '@/components/BackButton' const CreateProduct: FC = () => { @@ -71,8 +73,10 @@ const CreateProduct: FC = () => { return (
- -

محصول جدید

+
+ +

محصول جدید

+
-
-
+ -
+ +
setFile(files[0])} />
-
+
- - { />
-
+
formik.setFieldValue('isActive', value)} />
-
+ +
+ +
+
) } -export default ProductCategory \ No newline at end of file +export default CreateCategory diff --git a/src/pages/product/category/List.tsx b/src/pages/product/category/List.tsx index 90a41df..766b0b1 100644 --- a/src/pages/product/category/List.tsx +++ b/src/pages/product/category/List.tsx @@ -1,24 +1,34 @@ import { type FC, useMemo } from 'react' import PresignedImage from '@/components/PresignedImage' -import { useDeleteCategory, useGetCategory } from '../hooks/useProductData' +import { useDeleteCategory, useGetCategory, useGetCategoryDetail } from '../hooks/useProductData' import Table from '@/components/Table' import type { ColumnType, RowDataType } from '@/components/types/TableTypes' import type { CategoryType } from '../types/Types' -import Button from '@/components/Button' -import { AddSquare, Edit } from 'iconsax-react' +import { ArrowLeft2, Edit } from 'iconsax-react' import TrashWithConfrim from '@/components/TrashWithConfrim' import { toast } from 'react-toastify' import { extractErrorMessage } from '@/config/func' -import { Link } from 'react-router-dom' +import { Link, useParams } from 'react-router-dom' import { Paths } from '@/config/Paths' import BackButton from '@/components/BackButton' +import CreateCategory from './Create' const CategoryList: FC = () => { + const { parentId } = useParams<{ parentId?: string }>() - const { data, refetch } = useGetCategory() + const { data, refetch } = useGetCategory({ + limit: 1000, + parentId: parentId ?? 'null', + }) + const { data: parentDetail } = useGetCategoryDetail(parentId ?? '') const { mutate, isPending } = useDeleteCategory() const categories = (data?.data ?? []) as (CategoryType & RowDataType)[] + const parentCategory = parentDetail?.data + const backTo = parentCategory?.parent?.id + ? Paths.product.category.children + parentCategory.parent.id + : Paths.product.category.list + const handleDelete = (id: string) => { mutate(id, { onSuccess: () => { @@ -39,19 +49,34 @@ const CategoryList: FC = () => { { title: 'عنوان', key: 'title', + render: (item) => { + return ( + + {item.title} + + + ) + } }, { - title: 'والد', - key: 'parent', - render: (item) => item.parent?.title || '-', - }, - { - title: 'تعداد زیر دسته', + title: 'زیر دسته‌ها', key: 'children', - render: (item) =>
{item.children?.length || 0}
+ render: (item) => { + if (!item.children?.length) return '0' + return ( +
+ {item.children.map((child) => ( + {child.title} + ))} +
+ ) + } }, { - title: 'اولویت', + title: 'ترتیب', key: 'order', render: (item) => item.order ?? '-', }, @@ -75,33 +100,30 @@ const CategoryList: FC = () => { } ], [isPending]) + const title = parentCategory + ? `زیر دسته‌های «${parentCategory.title}»` + : 'دسته بندی محصولات' + return (
- -

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

+ +

{title}

- - - +
- - columns={columns} - data={categories} - /> + + columns={columns} + data={categories} + />
) } -export default CategoryList \ No newline at end of file +export default CategoryList diff --git a/src/pages/product/hooks/useProductData.ts b/src/pages/product/hooks/useProductData.ts index cc97aad..cc3b96c 100644 --- a/src/pages/product/hooks/useProductData.ts +++ b/src/pages/product/hooks/useProductData.ts @@ -16,10 +16,11 @@ export const useGetCategory = (params?: api.GetCategoryParams) => { const page = params?.page ?? 1; const limit = params?.limit; const search = params?.search; + const parentId = params?.parentId; return useQuery({ - queryKey: ["category", page, limit, search], - queryFn: () => api.getCategory({ page, limit, search }), + queryKey: ["category", page, limit, search, parentId], + queryFn: () => api.getCategory({ page, limit, search, parentId }), }); }; diff --git a/src/pages/product/service/ProductService.ts b/src/pages/product/service/ProductService.ts index 404bce3..820a1dd 100644 --- a/src/pages/product/service/ProductService.ts +++ b/src/pages/product/service/ProductService.ts @@ -5,6 +5,7 @@ export type GetCategoryParams = { page?: number; limit?: number; search?: string; + parentId?: string; }; export const getCategory = async (params?: GetCategoryParams) => { @@ -13,6 +14,7 @@ export const getCategory = async (params?: GetCategoryParams) => { page: params?.page, limit: params?.limit, search: params?.search || undefined, + parentId: params?.parentId || undefined, }, }); return data; diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index 657cb34..dcc65b7 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -28,7 +28,6 @@ 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/product/category/Create"; import UpdateCategory from "@/pages/product/category/Update"; import UpdateProduct from "@/pages/product/Update"; import CreateAttribute from "@/pages/product/attribute/Create"; @@ -108,7 +107,7 @@ const MainRouter: FC = () => { )} /> )} /> )} /> - )} /> + )} /> )} /> )} />