delete category
This commit is contained in:
@@ -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),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user