multiple messages for phone login and signup added
This commit is contained in:
@@ -9,17 +9,21 @@ import { isEmail } from '@/utils/regexes/isEmail';
|
||||
import parsePhoneNumberFromString from 'libphonenumber-js';
|
||||
|
||||
export interface LoginRegisterFormProps {
|
||||
loginRegisterValue: string;
|
||||
setLoginRegisterValue: Dispatch<string>;
|
||||
authType: AuthType;
|
||||
setAuthType: Dispatch<AuthType>;
|
||||
onLoginRegisterSubmit: (value: string) => void;
|
||||
}
|
||||
|
||||
export function LoginRegisterForm({
|
||||
loginRegisterValue,
|
||||
setLoginRegisterValue,
|
||||
authType,
|
||||
setAuthType,
|
||||
onLoginRegisterSubmit,
|
||||
}: LoginRegisterFormProps) {
|
||||
const { t, i18n } = useTranslation('authentication');
|
||||
const [value, setValue] = useState('');
|
||||
const [countryCode, setCountryCode] = useState('+98');
|
||||
const textFieldRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -30,7 +34,7 @@ export function LoginRegisterForm({
|
||||
|
||||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newValue = event.target.value;
|
||||
setValue(newValue);
|
||||
setLoginRegisterValue(newValue);
|
||||
|
||||
// If the new value contains only digits (or is empty), it's a phone number
|
||||
if (isNumeric(newValue)) {
|
||||
@@ -42,7 +46,7 @@ export function LoginRegisterForm({
|
||||
|
||||
const handleBlur = () => {
|
||||
setTouched(true);
|
||||
validateInput(value, authType);
|
||||
validateInput(loginRegisterValue, authType);
|
||||
};
|
||||
|
||||
const validateInput = (value: string, authType: AuthType) => {
|
||||
@@ -80,14 +84,15 @@ export function LoginRegisterForm({
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (isInputValid(value, authType)) {
|
||||
if (isInputValid(loginRegisterValue, authType)) {
|
||||
onLoginRegisterSubmit(loginRegisterValue);
|
||||
} else {
|
||||
inputRef.current?.focus();
|
||||
validateInput(value, authType);
|
||||
validateInput(loginRegisterValue, authType);
|
||||
}
|
||||
};
|
||||
|
||||
const showAdornment = authType === 'phone' && value.length > 0;
|
||||
const showAdornment = authType === 'phone' && loginRegisterValue.length > 0;
|
||||
|
||||
return (
|
||||
<Box sx={{ width: '100%' }}>
|
||||
@@ -102,7 +107,7 @@ export function LoginRegisterForm({
|
||||
ref={textFieldRef}
|
||||
inputRef={inputRef}
|
||||
label={t('loginForm.emailOrPhoneLabel')}
|
||||
value={value}
|
||||
value={loginRegisterValue}
|
||||
onChange={handleInputChange}
|
||||
onBlur={handleBlur}
|
||||
error={inputError}
|
||||
|
||||
Reference in New Issue
Block a user