update
This commit is contained in:
@@ -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',
|
||||||
|
|||||||
+16
-21
@@ -1,16 +1,24 @@
|
|||||||
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>
|
||||||
|
|
||||||
|
<Link
|
||||||
|
to={Paths.product.create}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
className='w-fit px-6'
|
className='w-fit px-6'
|
||||||
>
|
>
|
||||||
@@ -19,6 +27,7 @@ const ProductList: FC = () => {
|
|||||||
<div className='text-[13px] font-light'>محصول جدید</div>
|
<div className='text-[13px] font-light'>محصول جدید</div>
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
</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 (
|
||||||
|
<Link to={Paths.product.update + item.id}>
|
||||||
<Edit size={20} color='#0037FF' />
|
<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>
|
||||||
|
|||||||
@@ -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,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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[]>;
|
||||||
|
|||||||
Reference in New Issue
Block a user