+
-
-
-
+
{
/>
-
+
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 = () => {
)} />
)} />
)} />
- )} />
+ )} />
)} />
)} />