diff --git a/src/pages/auth/components/LoginStep1.tsx b/src/pages/auth/components/LoginStep1.tsx index 04a6661..1904586 100644 --- a/src/pages/auth/components/LoginStep1.tsx +++ b/src/pages/auth/components/LoginStep1.tsx @@ -39,7 +39,7 @@ const LoginStep1: FC = () => { }) return ( -
+

خوش آمدید @@ -56,6 +56,7 @@ const LoginStep1: FC = () => { type='tel' autoComplete='tel' inputMode='tel' + autoFocus className='dltr text-left' name='phone_email' onChange={formik.handleChange} @@ -75,10 +76,10 @@ const LoginStep1: FC = () => {

+
) } diff --git a/src/pages/auth/components/LoginStep2.tsx b/src/pages/auth/components/LoginStep2.tsx index 57f3005..2719679 100644 --- a/src/pages/auth/components/LoginStep2.tsx +++ b/src/pages/auth/components/LoginStep2.tsx @@ -1,4 +1,4 @@ -import { type FC, useEffect } from 'react' +import { type FC, useEffect, useRef } from 'react' import { type OtpVerifyType } from '../types/AuthTypes' import { useFormik } from 'formik' import * as Yup from 'yup' @@ -20,6 +20,7 @@ const LoginStep2: FC = () => { const { value, reset } = useCountDown(2, true) const otpVerify = useOtpVerify() const loginWithOtp = useLoginWithOtp() + const firstOtpInputRef = useRef(null) const formik = useFormik({ initialValues: { @@ -51,6 +52,14 @@ const LoginStep2: FC = () => { }, }) + useEffect(() => { + const frameId = requestAnimationFrame(() => { + firstOtpInputRef.current?.focus() + }) + + return () => cancelAnimationFrame(frameId) + }, []) + useEffect(() => { // بررسی پشتیبانی از Web OTP API if (!("OTPCredential" in window)) return; @@ -96,7 +105,7 @@ const LoginStep2: FC = () => { return ( -
+

کد تایید را وارد کنید @@ -126,14 +135,24 @@ const LoginStep2: FC = () => { numInputs={5} inputType='tel' onChange={(otp: string) => formik.setFieldValue('otp', otp)} - renderInput={(props) => - - } + renderInput={(props, index) => { + const { ref, ...inputProps } = props + + return ( + { + ref(element) + if (index === 0) { + firstOtpInputRef.current = element + } + }} + type='tel' + autoComplete="one-time-otp" + inputMode="numeric" + className='w-full h-[50px] min-w-[50px] flex-1 mx-2 bg-white border border-border rounded-[10px]' /> + ) + }} />

@@ -166,7 +185,7 @@ const LoginStep2: FC = () => {
*/} -
+ ) }