diff --git a/src/config/Paths.tsx b/src/config/Paths.tsx index f573876..8613d45 100644 --- a/src/config/Paths.tsx +++ b/src/config/Paths.tsx @@ -5,6 +5,7 @@ export const Paths = { product: { list: '/product/list', create: '/product/create', + update: '/product/update/', category: { create: '/product/category/create', list: '/product/category/list', diff --git a/src/pages/product/List.tsx b/src/pages/product/List.tsx index f26ec9e..5b47cb8 100644 --- a/src/pages/product/List.tsx +++ b/src/pages/product/List.tsx @@ -1,24 +1,33 @@ import Button from '@/components/Button' import Filters from '@/components/Filters' -import SwitchComponent from '@/components/Switch' import Table from '@/components/Table' import { AddSquare, Edit, More2 } from 'iconsax-react' import { type FC } from 'react' +import { useGetProducts } from './hooks/useProductData' +import { Link } from 'react-router-dom' +import { Paths } from '@/config/Paths' const ProductList: FC = () => { + + const { data: products } = useGetProducts() + return (

محصولات

- + +
@@ -60,39 +69,25 @@ const ProductList: FC = () => { { key: 'status', title: 'وضعیت', - render: () => { + render: (item) => { return ( - { }} - /> +
{item.isActive ? 'فعال' : 'غیر فعال'}
) } }, { key: 'actions', title: '', - render: () => { + render: (item) => { return ( - + + + ) } }, ]} - data={[ - { - id: 1, - title: 'محصول 1', - attribute: 'رنگ: قرمز، سایز: متوسط', - status: 'فعال', - }, - { - id: 2, - title: 'محصول 2', - attribute: 'رنگ: آبی، سایز: بزرگ', - status: 'غیرفعال', - } - ]} + data={products?.data} />
diff --git a/src/pages/product/hooks/useProductData.ts b/src/pages/product/hooks/useProductData.ts index ddf0f9b..acc704b 100644 --- a/src/pages/product/hooks/useProductData.ts +++ b/src/pages/product/hooks/useProductData.ts @@ -39,7 +39,7 @@ export const useGetCategoryDetail = (id: string) => { export const useGetProducts = () => { return useQuery({ queryKey: ["products"], - queryFn: api.getCategory, + queryFn: api.getProducts, }); }; diff --git a/src/pages/product/service/ProductService.ts b/src/pages/product/service/ProductService.ts index 7956286..312b9bf 100644 --- a/src/pages/product/service/ProductService.ts +++ b/src/pages/product/service/ProductService.ts @@ -1,5 +1,5 @@ import axios from "@/config/axios"; -import { type CategoriesResponse, type CategoryResponse, type CreateCategoryType, type CreateProductType } from "../types/Types"; +import { type CategoriesResponse, type CategoryResponse, type CreateCategoryType, type CreateProductType, type ProductResponeType } from "../types/Types"; export const getCategory = async () => { const { data } = await axios.get("/admin/category"); @@ -26,6 +26,11 @@ export const getCategoryDetail = async(id:string) => { return data } +export const getProducts = async () => { + const { data } = await axios.get("/admin/products"); + return data; +}; + export const createProduct = async (params:CreateProductType) => { const { data } = await axios.post("/admin/product", params); return data; diff --git a/src/pages/product/types/Types.ts b/src/pages/product/types/Types.ts index b0a6708..f8cbf60 100644 --- a/src/pages/product/types/Types.ts +++ b/src/pages/product/types/Types.ts @@ -25,12 +25,27 @@ export type CreateCategoryType = { } export type CreateProductType = { -categoryId?: number, -title: string, -desc: string, -linkUrl: string, -quantities: number[], -isActive: boolean, -images: string[], -order: number -} \ No newline at end of file + categoryId?: number, + title: string, + desc: string, + linkUrl: string, + quantities: number[], + isActive: boolean, + images: string[], + order: number +} + +export type ProductType = { + category: CategoryType, + createdAt: string, + desc: string, + id: number, + images: string[], + isActive: boolean, + linkUrl: string, + order: number, + quantities: number[], + title: string +} + +export type ProductResponeType = BaseResponse;