mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-08-16 13:50:36 +03:00
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
![]() |
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||
|
|
||
|
import { authApi, IPasswordTokenDTO, IResetPasswordDTO } from './api';
|
||
|
|
||
|
export const useResetPassword = () => {
|
||
|
const client = useQueryClient();
|
||
|
const validateMutation = useMutation({
|
||
|
mutationKey: ['reset-password'],
|
||
|
mutationFn: authApi.validatePasswordToken,
|
||
|
onSuccess: async () => await client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
||
|
});
|
||
|
const resetMutation = useMutation({
|
||
|
mutationKey: ['reset-password'],
|
||
|
mutationFn: authApi.resetPassword,
|
||
|
onSuccess: async () => await client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
||
|
});
|
||
|
return {
|
||
|
validateToken: (
|
||
|
data: IPasswordTokenDTO, //
|
||
|
onSuccess?: () => void
|
||
|
) => validateMutation.mutate(data, { onSuccess }),
|
||
|
resetPassword: (
|
||
|
data: IResetPasswordDTO, //
|
||
|
onSuccess?: () => void
|
||
|
) => resetMutation.mutate(data, { onSuccess }),
|
||
|
isPending: resetMutation.isPending,
|
||
|
error: resetMutation.error,
|
||
|
reset: resetMutation.reset
|
||
|
};
|
||
|
};
|