list of attributes

This commit is contained in:
hamid zarghami
2026-01-25 09:55:45 +03:30
parent a37a7191dd
commit f8f79e3a9d
5 changed files with 107 additions and 2 deletions
+78
View File
@@ -0,0 +1,78 @@
import Button from '@/components/Button'
import { Paths } from '@/config/Paths'
import { AddSquare, Edit } from 'iconsax-react'
import { type FC } from 'react'
import { Link, useParams } from 'react-router-dom'
import { useGetAttributes } from '../hooks/useProductData'
import Table from '@/components/Table'
const AttributeList: FC = () => {
const { id } = useParams()
const { data } = useGetAttributes(Number(id))
return (
<div className='mt-5'>
<div className='flex justify-between items-center'>
<h1 className='text-lg font-light'>ویژگی ها</h1>
<Link
to={Paths.product.attribute.create + id}
>
<Button
className='w-fit px-6'
>
<div className='flex gap-1.5'>
<AddSquare size={18} color='black' />
<div className='text-[13px] font-light'>ویژگی جدید</div>
</div>
</Button>
</Link>
</div>
<div className='mt-8'>
<Table
columns={[
{
key: 'name',
title: 'نام'
},
{
key: 'type',
title: 'نوع'
},
{
key: 'isRequired',
title: 'احباری',
render: (item) => {
return (
<div>{item.isRequired ? 'اجباری' : 'اختیاری'}</div>
)
}
},
{
key: 'actions',
title: '',
render: (item) => {
return (
<div className='flex gap-2 items-center'>
<Link to={Paths.product.attribute.update + item.id}>
<Edit
color='#0037FF'
size={20}
/>
</Link>
</div>
)
}
}
]}
data={data?.data}
/>
</div>
</div>
)
}
export default AttributeList
@@ -97,3 +97,11 @@ export const useCreateAttribute = () => {
api.createAttribute(id, params),
});
};
export const useGetAttributes = (id: number) => {
return useQuery({
queryKey: ["product-attributes", id],
queryFn: () => api.getAttributes(id),
enabled: !!id,
});
};
+6 -1
View File
@@ -1,5 +1,5 @@
import axios from "@/config/axios";
import { type CategoriesResponse, type CategoryResponse, type CreateAttributeType, type CreateCategoryType, type CreateProductType, type ProductDetailResponeType, type ProductResponeType } from "../types/Types";
import { type AttributeResponseType, type CategoriesResponse, type CategoryResponse, type CreateAttributeType, type CreateCategoryType, type CreateProductType, type ProductDetailResponeType, type ProductResponeType } from "../types/Types";
export const getCategory = async () => {
const { data } = await axios.get<CategoriesResponse>("/admin/category");
@@ -54,4 +54,9 @@ export const deleteProduct = async (id: number) => {
export const createAttribute = async (id: number, params:CreateAttributeType) => {
const { data } = await axios.post(`/admin/product/${id}/attribute`, params);
return data;
};
export const getAttributes = async (id: number) => {
const { data } = await axios.get<AttributeResponseType>(`/admin/products/${id}/attributes`);
return data;
};
+13 -1
View File
@@ -57,4 +57,16 @@ export type CreateAttributeType = {
isRequired: boolean,
type: FieldTypeEnum,
order: number
}
}
export type AttributeType = {
createdAt: string,
id: number,
isRequired: boolean,
name: string,
order: number,
product: number,
type: FieldTypeEnum
}
export type AttributeResponseType = BaseResponse<AttributeType[]>;