2025-01-21 20:33:05 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
import { authApi, IPasswordTokenDTO, IResetPasswordDTO } from './api';
|
|
|
|
|
|
|
|
export const useResetPassword = () => {
|
2025-01-23 19:41:31 +03:00
|
|
|
const client = useQueryClient();
|
2025-01-21 20:33:05 +03:00
|
|
|
const validateMutation = useMutation({
|
|
|
|
mutationKey: ['reset-password'],
|
|
|
|
mutationFn: authApi.validatePasswordToken,
|
2025-01-29 14:51:34 +03:00
|
|
|
onSuccess: () => client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
const resetMutation = useMutation({
|
|
|
|
mutationKey: ['reset-password'],
|
|
|
|
mutationFn: authApi.resetPassword,
|
2025-01-29 14:51:34 +03:00
|
|
|
onSuccess: () => client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
return {
|
2025-01-23 19:41:31 +03:00
|
|
|
validateToken: (
|
|
|
|
data: IPasswordTokenDTO, //
|
|
|
|
onSuccess?: () => void
|
|
|
|
) => validateMutation.mutate(data, { onSuccess }),
|
|
|
|
resetPassword: (
|
|
|
|
data: IResetPasswordDTO, //
|
|
|
|
onSuccess?: () => void
|
|
|
|
) => resetMutation.mutate(data, { onSuccess }),
|
2025-01-29 16:17:50 +03:00
|
|
|
isPending: resetMutation.isPending || validateMutation.isPending,
|
2025-01-21 20:33:05 +03:00
|
|
|
error: resetMutation.error,
|
|
|
|
reset: resetMutation.reset
|
|
|
|
};
|
|
|
|
};
|