2025-01-21 20:33:05 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
2025-02-19 19:15:57 +03:00
|
|
|
import { KEYS } from '@/backend/configuration';
|
|
|
|
|
2025-02-12 20:53:01 +03:00
|
|
|
import { authApi } from './api';
|
|
|
|
import { IChangePasswordDTO } from './types';
|
2025-01-21 20:33:05 +03:00
|
|
|
|
|
|
|
export const useChangePassword = () => {
|
2025-01-23 19:41:31 +03:00
|
|
|
const client = useQueryClient();
|
2025-01-21 20:33:05 +03:00
|
|
|
const mutation = useMutation({
|
2025-02-19 19:15:57 +03:00
|
|
|
mutationKey: [KEYS.auth, 'change-password'],
|
2025-01-21 20:33:05 +03:00
|
|
|
mutationFn: authApi.changePassword,
|
2025-01-29 14:51:34 +03:00
|
|
|
onSettled: () => client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
return {
|
2025-02-11 20:15:34 +03:00
|
|
|
changePassword: (data: IChangePasswordDTO) => mutation.mutateAsync(data),
|
2025-01-21 20:33:05 +03:00
|
|
|
isPending: mutation.isPending,
|
|
|
|
error: mutation.error,
|
|
|
|
reset: mutation.reset
|
|
|
|
};
|
|
|
|
};
|