This commit is contained in:
hamid zarghami
2026-01-24 15:52:56 +03:30
parent cb174bf0dc
commit 480fc056f9
5 changed files with 56 additions and 40 deletions
+1
View File
@@ -5,6 +5,7 @@ export const Paths = {
product: { product: {
list: '/product/list', list: '/product/list',
create: '/product/create', create: '/product/create',
update: '/product/update/',
category: { category: {
create: '/product/category/create', create: '/product/category/create',
list: '/product/category/list', list: '/product/category/list',
+24 -29
View File
@@ -1,24 +1,33 @@
import Button from '@/components/Button' import Button from '@/components/Button'
import Filters from '@/components/Filters' import Filters from '@/components/Filters'
import SwitchComponent from '@/components/Switch'
import Table from '@/components/Table' import Table from '@/components/Table'
import { AddSquare, Edit, More2 } from 'iconsax-react' import { AddSquare, Edit, More2 } from 'iconsax-react'
import { type FC } from '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 ProductList: FC = () => {
const { data: products } = useGetProducts()
return ( return (
<div className='mt-5'> <div className='mt-5'>
<div className='flex justify-between items-center'> <div className='flex justify-between items-center'>
<h1 className='text-lg font-light'>محصولات</h1> <h1 className='text-lg font-light'>محصولات</h1>
<Button <Link
className='w-fit px-6' to={Paths.product.create}
> >
<div className='flex gap-1.5'> <Button
<AddSquare size={18} color='black' /> className='w-fit px-6'
<div className='text-[13px] font-light'>محصول جدید</div> >
</div> <div className='flex gap-1.5'>
</Button> <AddSquare size={18} color='black' />
<div className='text-[13px] font-light'>محصول جدید</div>
</div>
</Button>
</Link>
</div> </div>
<div className='mt-8'> <div className='mt-8'>
@@ -60,39 +69,25 @@ const ProductList: FC = () => {
{ {
key: 'status', key: 'status',
title: 'وضعیت', title: 'وضعیت',
render: () => { render: (item) => {
return ( return (
<SwitchComponent <div>{item.isActive ? 'فعال' : 'غیر فعال'}</div>
active={true}
onChange={() => { }}
/>
) )
} }
}, },
{ {
key: 'actions', key: 'actions',
title: '', title: '',
render: () => { render: (item) => {
return ( return (
<Edit size={20} color='#0037FF' /> <Link to={Paths.product.update + item.id}>
<Edit size={20} color='#0037FF' />
</Link>
) )
} }
}, },
]} ]}
data={[ data={products?.data}
{
id: 1,
title: 'محصول 1',
attribute: 'رنگ: قرمز، سایز: متوسط',
status: 'فعال',
},
{
id: 2,
title: 'محصول 2',
attribute: 'رنگ: آبی، سایز: بزرگ',
status: 'غیرفعال',
}
]}
/> />
</div> </div>
</div> </div>
+1 -1
View File
@@ -39,7 +39,7 @@ export const useGetCategoryDetail = (id: string) => {
export const useGetProducts = () => { export const useGetProducts = () => {
return useQuery({ return useQuery({
queryKey: ["products"], queryKey: ["products"],
queryFn: api.getCategory, queryFn: api.getProducts,
}); });
}; };
+6 -1
View File
@@ -1,5 +1,5 @@
import axios from "@/config/axios"; 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 () => { export const getCategory = async () => {
const { data } = await axios.get<CategoriesResponse>("/admin/category"); const { data } = await axios.get<CategoriesResponse>("/admin/category");
@@ -26,6 +26,11 @@ export const getCategoryDetail = async(id:string) => {
return data return data
} }
export const getProducts = async () => {
const { data } = await axios.get<ProductResponeType>("/admin/products");
return data;
};
export const createProduct = async (params:CreateProductType) => { export const createProduct = async (params:CreateProductType) => {
const { data } = await axios.post("/admin/product", params); const { data } = await axios.post("/admin/product", params);
return data; return data;
+23 -8
View File
@@ -25,12 +25,27 @@ export type CreateCategoryType = {
} }
export type CreateProductType = { export type CreateProductType = {
categoryId?: number, categoryId?: number,
title: string, title: string,
desc: string, desc: string,
linkUrl: string, linkUrl: string,
quantities: number[], quantities: number[],
isActive: boolean, isActive: boolean,
images: string[], images: string[],
order: number 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<ProductType[]>;