delete section
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import { type FC } from 'react'
|
||||
import { useGetSections } from './hooks/usePrintData'
|
||||
import { useDeleteSection, useGetSections } from './hooks/usePrintData'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Paths } from '@/config/Paths'
|
||||
import Button from '@/components/Button'
|
||||
import { AddSquare, Edit, More2 } from 'iconsax-react'
|
||||
import Table from '@/components/Table'
|
||||
import TrashWithConfrim from '@/components/TrashWithConfrim'
|
||||
|
||||
const SectionList: FC = () => {
|
||||
|
||||
const { data } = useGetSections()
|
||||
const { mutate, isPending } = useDeleteSection()
|
||||
|
||||
return (
|
||||
<div className='mt-5'>
|
||||
@@ -61,11 +63,11 @@ const SectionList: FC = () => {
|
||||
<Link to={Paths.print.update + item.id}>
|
||||
<Edit size={20} color='#0037FF' />
|
||||
</Link>
|
||||
{/* <TrashWithConfrim
|
||||
onDelete={() => handleDelete(item.id)}
|
||||
isloading={isDeleting}
|
||||
<TrashWithConfrim
|
||||
onDelete={() => mutate(item.id)}
|
||||
isloading={isPending}
|
||||
colorIcon='red'
|
||||
/> */}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,14 @@ export const useGetSectionsDetail = (id: number) => {
|
||||
};
|
||||
|
||||
export const useCreateSection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: api.createSection,
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({
|
||||
queryKey: ["sections"],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -37,3 +43,15 @@ export const useUpdateSection = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteSection = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => api.deleteSection(id),
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({
|
||||
queryKey: ["sections"],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -26,3 +26,8 @@ export const getSectionDetail = async (id: number) => {
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const deleteSection = async (id: number) => {
|
||||
const { data } = await axios.delete(`/admin/section/${id}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user