feat: OTP Resend
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
TLoginRequest,
|
||||
TLoginResponse,
|
||||
TRegisterRequest,
|
||||
TSendOTPRequest,
|
||||
TVerifyEmailRequest,
|
||||
} from '../../types/auth';
|
||||
import { TResponseMessage } from '../../types/common';
|
||||
@@ -39,3 +40,14 @@ export const postVerifyEmail = async (
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
export const postSendOtp = async (
|
||||
payload: TSendOTPRequest
|
||||
): Promise<TResponseMessage> => {
|
||||
const { data } = await api({
|
||||
method: 'POST',
|
||||
url: '/auth/send-otp',
|
||||
data: payload,
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useMutation, UseMutationResult } from '@tanstack/react-query';
|
||||
import { postLogin, postRegister, postVerifyEmail } from '../../api/auth';
|
||||
import { postLogin, postRegister, postSendOtp, postVerifyEmail } from '../../api/auth';
|
||||
import {
|
||||
TLoginRequest,
|
||||
TLoginResponse,
|
||||
TRegisterRequest,
|
||||
TSendOTPRequest,
|
||||
TVerifyEmailRequest,
|
||||
} from '../../types/auth';
|
||||
|
||||
@@ -44,3 +45,16 @@ export const usePostVerifyEmail = (): UseMutationResult<
|
||||
mutationFn: async (payload) => await postVerifyEmail(payload),
|
||||
});
|
||||
};
|
||||
|
||||
export const usePostSendOTP = (): UseMutationResult<
|
||||
TResponseMessage,
|
||||
TResponseError,
|
||||
TSendOTPRequest,
|
||||
unknown
|
||||
> => {
|
||||
return useMutation({
|
||||
mutationKey: ['post-send-otp'],
|
||||
mutationFn: async (payload) => await postSendOtp(payload),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -27,3 +27,7 @@ export type TVerifyEmailRequest = {
|
||||
email: string;
|
||||
otp: string;
|
||||
};
|
||||
|
||||
export type TSendOTPRequest = {
|
||||
email: string
|
||||
};
|
||||
@@ -3,4 +3,5 @@ export * from './use-auth-store';
|
||||
export * from './use-modal-login';
|
||||
export * from './use-session';
|
||||
export * from './use-register';
|
||||
export * from './use-otp';
|
||||
export * from './use-otp';
|
||||
export * from './use-send-otp';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { TSendOTPRequest, usePostSendOTP } from '@imphnen-frontend-service/service';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export const useSendOTP = () => {
|
||||
const { mutate, isPending } = usePostSendOTP();
|
||||
|
||||
const resendOTP = (payload: TSendOTPRequest) => {
|
||||
mutate(payload, {
|
||||
onSuccess: (data) => {
|
||||
toast.success('Berhasil Mengirim Ulang OTP');
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err?.response?.data?.message ??
|
||||
'Terjadi Kesalahan yang tidak diketahui'
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
resendOTP,
|
||||
isLoading: isPending,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user