delete section
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
import { type FC } from 'react'
|
import { type FC } from 'react'
|
||||||
import { useGetSections } from './hooks/usePrintData'
|
import { useDeleteSection, useGetSections } from './hooks/usePrintData'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { Paths } from '@/config/Paths'
|
import { Paths } from '@/config/Paths'
|
||||||
import Button from '@/components/Button'
|
import Button from '@/components/Button'
|
||||||
import { AddSquare, Edit, More2 } from 'iconsax-react'
|
import { AddSquare, Edit, More2 } from 'iconsax-react'
|
||||||
import Table from '@/components/Table'
|
import Table from '@/components/Table'
|
||||||
|
import TrashWithConfrim from '@/components/TrashWithConfrim'
|
||||||
|
|
||||||
const SectionList: FC = () => {
|
const SectionList: FC = () => {
|
||||||
|
|
||||||
const { data } = useGetSections()
|
const { data } = useGetSections()
|
||||||
|
const { mutate, isPending } = useDeleteSection()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mt-5'>
|
<div className='mt-5'>
|
||||||
@@ -61,11 +63,11 @@ const SectionList: FC = () => {
|
|||||||
<Link to={Paths.print.update + item.id}>
|
<Link to={Paths.print.update + item.id}>
|
||||||
<Edit size={20} color='#0037FF' />
|
<Edit size={20} color='#0037FF' />
|
||||||
</Link>
|
</Link>
|
||||||
{/* <TrashWithConfrim
|
<TrashWithConfrim
|
||||||
onDelete={() => handleDelete(item.id)}
|
onDelete={() => mutate(item.id)}
|
||||||
isloading={isDeleting}
|
isloading={isPending}
|
||||||
colorIcon='red'
|
colorIcon='red'
|
||||||
/> */}
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,14 @@ export const useGetSectionsDetail = (id: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useCreateSection = () => {
|
export const useCreateSection = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: api.createSection,
|
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;
|
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