30
common/resources/client/auth/requests/use-resend-verification-email.ts
Executable file
30
common/resources/client/auth/requests/use-resend-verification-email.ts
Executable file
@@ -0,0 +1,30 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {BackendResponse} from '../../http/backend-response/backend-response';
|
||||
import {toast} from '../../ui/toast/toast';
|
||||
import {message} from '../../i18n/message';
|
||||
import {apiClient} from '../../http/query-client';
|
||||
import {showHttpErrorToast} from '../../utils/http/show-http-error-toast';
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ResendConfirmEmailPayload {
|
||||
email: string;
|
||||
}
|
||||
|
||||
export function useResendVerificationEmail() {
|
||||
return useMutation({
|
||||
mutationFn: (payload: ResendConfirmEmailPayload) => resendEmail(payload),
|
||||
onSuccess: () => {
|
||||
toast(message('Email sent'));
|
||||
},
|
||||
onError: err => showHttpErrorToast(err),
|
||||
});
|
||||
}
|
||||
|
||||
function resendEmail(payload: ResendConfirmEmailPayload): Promise<Response> {
|
||||
return apiClient
|
||||
.post('resend-email-verification', payload)
|
||||
.then(response => response.data);
|
||||
}
|
||||
Reference in New Issue
Block a user