delete category

This commit is contained in:
hamid zarghami
2026-01-24 11:44:41 +03:30
parent 13db24d13b
commit 3dc13d1830
6 changed files with 130 additions and 5 deletions
+22 -3
View File
@@ -1,13 +1,28 @@
import { type FC } from 'react'
import { useGetCategory } from '../hooks/useProductData'
import { useDeleteCategory, useGetCategory } from '../hooks/useProductData'
import Table from '@/components/Table'
import type { ColumnType, RowDataType } from '@/components/types/TableTypes'
import type { CategoryType } from '../types/Types'
import { Edit } from 'iconsax-react'
import TrashWithConfrim from '@/components/TrashWithConfrim'
import { toast } from 'react-toastify'
import { extractErrorMessage } from '@/config/func'
const CategoryList: FC = () => {
const { data } = useGetCategory()
const { data, refetch } = useGetCategory()
const { mutate, isPending } = useDeleteCategory()
const handleDelete = (id: string) => {
mutate(id, {
onSuccess: () => {
refetch()
},
onError: (error) => {
toast.error(extractErrorMessage(error))
}
})
}
const column: ColumnType<CategoryType>[] = [
{
@@ -41,7 +56,7 @@ const CategoryList: FC = () => {
{
title: '',
key: 'action',
render: () => {
render: (item) => {
return (
<div className='flex items-center gap-2'>
<Edit
@@ -49,6 +64,10 @@ const CategoryList: FC = () => {
color='#8C90A3'
/>
<TrashWithConfrim
onDelete={() => handleDelete(item.id)}
isloading={isPending}
/>
</div>
)
@@ -13,3 +13,9 @@ export const useCreateCategory = () => {
mutationFn: api.createCategory,
});
};
export const useDeleteCategory = () => {
return useMutation({
mutationFn: (id: string) => api.deleteCategory(id),
});
};
+6 -1
View File
@@ -9,4 +9,9 @@ export const getCategory = async () => {
export const createCategory = async (params:CreateCategoryType) => {
const { data } = await axios.post("/admin/category", params);
return data;
};
};
export const deleteCategory = async(id:string) => {
const { data } = await axios.delete(`/admin/category/${id}`)
return data
}