Resend OTP (#34)
* feat: responsive * fix: success register * feat: auth login responsive && auth login implementation * fix: login page button disabled & register page * fix: conflict * fix: button disabled when loading * feat: register and otp integration * Update middleware.ts * feat: OTP Resend
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { useSendOTP } from '@imphnen-frontend-service/utils';
|
||||
|
||||
export const useResendOtpHook = () => {
|
||||
|
||||
const { resendOTP, isLoading } = useSendOTP();
|
||||
|
||||
return {
|
||||
resendOTP
|
||||
};
|
||||
};
|
||||
@@ -1,12 +1,38 @@
|
||||
import { FC, ReactElement } from 'react';
|
||||
import { FC, ReactElement, useEffect, useState } from 'react';
|
||||
import { ControlledInputField, RegisterResetBanner } from "@imphnen-frontend-service/ui/organisms";
|
||||
import { useOtpHook } from '../../../_hooks/use-otp';
|
||||
import { Button } from '@imphnen-frontend-service/ui/atoms';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useResendOtpHook } from '../../../_hooks/use-resend-otp';
|
||||
|
||||
export const Components: FC = (): ReactElement => {
|
||||
const { form, onSubmit, isLoading } = useOtpHook()
|
||||
const [ searchParams ] = useSearchParams()
|
||||
const [ disabled, setDisabled] = useState(true);
|
||||
const [ timeLeft, setTimeLeft ] = useState(5 * 60);
|
||||
const { resendOTP } = useResendOtpHook()
|
||||
|
||||
useEffect(() => {
|
||||
if (disabled) {
|
||||
const interval = setInterval(() => {
|
||||
setTimeLeft(prev => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(interval);
|
||||
setDisabled(false);
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
}, [disabled]);
|
||||
|
||||
const formatTime = (seconds: number) => {
|
||||
const m = Math.floor(seconds / 60);
|
||||
const s = seconds % 60;
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='flex flex-col justify-center items-center min-h-screen py-[60px] px-[80px]'>
|
||||
@@ -26,6 +52,13 @@ export const Components: FC = (): ReactElement => {
|
||||
maxLength={6}
|
||||
control={form.control}
|
||||
/>
|
||||
<Button type="button" className="mt-2" disabled={disabled} onClick={
|
||||
() => {
|
||||
resendOTP({email: searchParams.get("email") || ""})
|
||||
setDisabled(true)
|
||||
setTimeLeft(5 * 60)
|
||||
}
|
||||
}>Kirim ulang otp {disabled? `(${formatTime(timeLeft)})`: ""}</Button>
|
||||
<Button className="xl:w-full mt-2" disabled={(!form.formState.isValid || isLoading)}>Linked Start !!!</Button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@ const mappingPublicRoutes = [
|
||||
'/auth/login',
|
||||
'/auth/forgot',
|
||||
'/auth/forgot/otp',
|
||||
'/auth/register',
|
||||
'/auth/register',
|
||||
'/auth/register/otp',
|
||||
'/auth/register/success',
|
||||
'/auth/new-password',
|
||||
|
||||
Reference in New Issue
Block a user