mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Update hooks and services
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
// Services
|
||||
import { updateRoom as updateRoomFn } from '@service/roomServices';
|
||||
|
||||
// Constants
|
||||
import { UPDATE_SUCCESS } from '@constant/messages';
|
||||
|
||||
/**
|
||||
* Update room from database
|
||||
* @returns The status of updating and updateRoom function
|
||||
*/
|
||||
const useUpdateRoom = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { mutate: updateRoom, isPending: isUpdating } = useMutation({
|
||||
mutationFn: updateRoomFn,
|
||||
onSuccess: () => {
|
||||
toast.success(UPDATE_SUCCESS);
|
||||
queryClient.invalidateQueries({ queryKey: ['rooms'] });
|
||||
},
|
||||
onError: (err) => toast.error(err.message),
|
||||
});
|
||||
|
||||
return { isUpdating, updateRoom };
|
||||
};
|
||||
|
||||
export { useUpdateRoom };
|
||||
Reference in New Issue
Block a user