Portal/rsconcept/frontend/src/features/auth/backend/useResetPassword.tsx

28 lines
868 B
TypeScript
Raw Normal View History

2025-01-30 11:38:13 +03:00
import { useMutation } from '@tanstack/react-query';
2025-01-21 20:33:05 +03:00
import { authApi, IPasswordTokenDTO, IResetPasswordDTO } from './api';
export const useResetPassword = () => {
const validateMutation = useMutation({
2025-01-30 11:38:13 +03:00
mutationKey: ['validate-token'],
mutationFn: authApi.validatePasswordToken
2025-01-21 20:33:05 +03:00
});
const resetMutation = useMutation({
mutationKey: ['reset-password'],
2025-01-30 11:38:13 +03:00
mutationFn: authApi.resetPassword
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 }),
isPending: resetMutation.isPending || validateMutation.isPending,
2025-02-04 23:33:35 +03:00
error: resetMutation.error ?? validateMutation.error,
reset: resetMutation.reset
2025-01-21 20:33:05 +03:00
};
};