mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
30 lines
773 B
TypeScript
30 lines
773 B
TypeScript
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 };
|