mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-23 04:19:48 +00:00
Create booking hooks and update room, user hooks
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
// Services
|
||||
import { deleteBooking as deleteBookingFn } from '@service/bookingServices';
|
||||
|
||||
// Constants
|
||||
import { DELETE_SUCCESS } from '@constant/messages';
|
||||
|
||||
/**
|
||||
* Delete the booking from database
|
||||
* @returns The boolean of status deleting and deleteBooking function
|
||||
*/
|
||||
const useDeleteBooking = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const {
|
||||
isPending: isDeleting,
|
||||
mutate: deleteBooking,
|
||||
isSuccess,
|
||||
} = useMutation({
|
||||
mutationFn: deleteBookingFn,
|
||||
onSuccess: () => {
|
||||
toast.success(DELETE_SUCCESS);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['bookings'],
|
||||
});
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
});
|
||||
|
||||
return { isDeleting, deleteBooking, isSuccess };
|
||||
};
|
||||
|
||||
export { useDeleteBooking };
|
||||
Reference in New Issue
Block a user