diff --git a/src/components/DigitsInput.tsx b/src/components/DigitsInput.tsx index c133ace..bb90c61 100644 --- a/src/components/DigitsInput.tsx +++ b/src/components/DigitsInput.tsx @@ -8,6 +8,7 @@ import React, { } from 'react'; import { TextField, Stack } from '@mui/material'; import { useTranslation } from 'react-i18next'; +import { replacePersianWithRealNumbers } from '@/utils/replacePersianWithRealNumbers'; interface DigitInputProps { error: boolean; @@ -34,6 +35,8 @@ const DigitInput: React.FC = ({ }; const handleChange = (value: string, index: number) => { + value = replacePersianWithRealNumbers(value); + if (!/^\d$/.test(value) && value !== '') return; const newCode = [...code]; @@ -91,6 +94,7 @@ const DigitInput: React.FC = ({ color={success ? 'success' : 'primary'} key={index} inputRef={(el) => (inputRefs.current[index] = el)} + autoFocus={index === 0} value={digit} onChange={(e) => handleChange(e.target.value, index)} onKeyDown={(e) => e.key === 'Backspace' && handleBackspace(e, index)} diff --git a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx index eba878f..5a7e42b 100644 --- a/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx +++ b/src/features/authentication/components/AuthenticationSteps/LoginRegiserForm.tsx @@ -67,9 +67,6 @@ export function LoginRegisterForm({ const handleInputChange = (event: React.ChangeEvent) => { let newValue = event.target.value; newValue = replacePersianWithRealNumbers(newValue); - if (newValue.startsWith('09')) { - newValue = newValue.substring(1); - } setLoginRegisterValue(newValue); @@ -112,10 +109,20 @@ export function LoginRegisterForm({ const handleSubmit = async () => { if (validateInput(loginRegisterValue, authType, false)) { + let newValue = loginRegisterValue; + + if ( + authType === 'phone' && + countryCode === '+98' && + newValue.startsWith('09') + ) { + newValue = newValue.substring(1); + setLoginRegisterValue(newValue); + } + const res = await execUserStatus({ - phoneNumber: - authType === 'phone' ? countryCode + loginRegisterValue : undefined, - email: authType === 'email' ? loginRegisterValue : undefined, + phoneNumber: authType === 'phone' ? countryCode + newValue : undefined, + email: authType === 'email' ? newValue : undefined, }); if (!res) { @@ -123,7 +130,7 @@ export function LoginRegisterForm({ } if (res.success) { - onLoginRegisterSubmit(loginRegisterValue, res.userStatus); + onLoginRegisterSubmit(newValue, res.userStatus); } else { toast({ message: res.message, severity: 'error' }); }