mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
26 lines
737 B
TypeScript
26 lines
737 B
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { toast } from 'react-hot-toast';
|
|
|
|
// Services
|
|
import { updateAccount as updateAccountFn } from '@service/authenticationService';
|
|
|
|
// Constants
|
|
import { UPDATE_ACCOUNT_SUCCESSFUL } from '@constant/messages';
|
|
|
|
const useUpdateAccount = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
const { mutate: updateAccount, isPending: isUpdating } = useMutation({
|
|
mutationFn: updateAccountFn,
|
|
onSuccess: (account) => {
|
|
toast.success(UPDATE_ACCOUNT_SUCCESSFUL);
|
|
queryClient.setQueryData(['account'], account.user);
|
|
},
|
|
onError: (err) => toast.error(err.message),
|
|
});
|
|
|
|
return { updateAccount, isUpdating };
|
|
};
|
|
|
|
export { useUpdateAccount };
|