fix: farsi digits and autofoucs in digits input

This commit is contained in:
Sajad Mirjalili
2025-09-29 15:51:28 +03:30
parent 4a420da452
commit 9a75e599e2
2 changed files with 18 additions and 7 deletions

View File

@@ -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<DigitInputProps> = ({
};
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<DigitInputProps> = ({
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)}

View File

@@ -67,9 +67,6 @@ export function LoginRegisterForm({
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
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' });
}