fix: complete signup form normalization
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"loginForm": {
|
"loginForm": {
|
||||||
"title": "Login/Register",
|
"title": "Login/Register",
|
||||||
"description": "Please enter your email/password to start",
|
"description": "Please enter your email/password to start",
|
||||||
"emailOrPhoneLabel": "Email/Password",
|
"emailOrPhoneLabel": "Email/Phone number",
|
||||||
"submitButton": "Login/Register",
|
"submitButton": "Login/Register",
|
||||||
"loginWithGoogle": "Login with google",
|
"loginWithGoogle": "Login with google",
|
||||||
"emailIsInvalid": "Email is invalid",
|
"emailIsInvalid": "Email is invalid",
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
"moreMinute": "minute",
|
"moreMinute": "minute",
|
||||||
"resendCode": "Resend code",
|
"resendCode": "Resend code",
|
||||||
"confirmAndLogin": "Confirm & login",
|
"confirmAndLogin": "Confirm & login",
|
||||||
|
"confirmAndContinue": "Confirm & continue",
|
||||||
"loginWithPassword": "Login with password"
|
"loginWithPassword": "Login with password"
|
||||||
},
|
},
|
||||||
"completeSignUp": {
|
"completeSignUp": {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Box, Button, TextField, Typography } from '@mui/material';
|
import { Box, Button, TextField, Typography } from '@mui/material';
|
||||||
import parsePhoneNumberFromString from 'libphonenumber-js';
|
import parsePhoneNumberFromString from 'libphonenumber-js';
|
||||||
import { useRef, useState, type Dispatch } from 'react';
|
import { useRef, useState, type ChangeEvent, type Dispatch } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { AuthenticationCard } from '../AuthenticationCard';
|
import { AuthenticationCard } from '../AuthenticationCard';
|
||||||
import { CountryCodeSelector } from '../../../../components/CountryCodeSelector';
|
import { CountryCodeSelector } from '../../../../components/CountryCodeSelector';
|
||||||
import { sendSmsOtp } from '../../api/authorizationAPI';
|
import { sendSmsOtp } from '../../api/authorizationAPI';
|
||||||
import type { CountryCode } from '@/types/commonTypes';
|
import type { CountryCode } from '@/types/commonTypes';
|
||||||
import { useApi } from '@/hooks/useApi';
|
import { useApi } from '@/hooks/useApi';
|
||||||
|
import { replacePersianWithRealNumbers } from '@/utils/replacePersianWithRealNumbers';
|
||||||
|
|
||||||
export interface CompleteSignUpProps {
|
export interface CompleteSignUpProps {
|
||||||
email: string;
|
email: string;
|
||||||
@@ -25,7 +26,7 @@ export const CompleteSignUp = ({
|
|||||||
setCountryCode,
|
setCountryCode,
|
||||||
onCompleteSignUp,
|
onCompleteSignUp,
|
||||||
}: CompleteSignUpProps) => {
|
}: CompleteSignUpProps) => {
|
||||||
const { t } = useTranslation('authentication');
|
const { t, i18n } = useTranslation('authentication');
|
||||||
const [error, setError] = useState<string>();
|
const [error, setError] = useState<string>();
|
||||||
const textFieldRef = useRef<HTMLDivElement>(null);
|
const textFieldRef = useRef<HTMLDivElement>(null);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -45,6 +46,12 @@ export const CompleteSignUp = ({
|
|||||||
handleValueError();
|
handleValueError();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = replacePersianWithRealNumbers(event.target.value);
|
||||||
|
|
||||||
|
setValue(value);
|
||||||
|
};
|
||||||
|
|
||||||
const handleValueError = () => {
|
const handleValueError = () => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
setError(t('loginForm.thisFieldIsRequired'));
|
setError(t('loginForm.thisFieldIsRequired'));
|
||||||
@@ -62,8 +69,13 @@ export const CompleteSignUp = ({
|
|||||||
if (!value || !isPhoneValid(countryCode, value)) {
|
if (!value || !isPhoneValid(countryCode, value)) {
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
} else {
|
} else {
|
||||||
await sendSmsCall({ phoneNumber: countryCode + value });
|
let newValue = value;
|
||||||
onCompleteSignUp(countryCode, value);
|
if (countryCode === '+98' && newValue.startsWith('09')) {
|
||||||
|
newValue = newValue.substring(1);
|
||||||
|
setValue(newValue);
|
||||||
|
}
|
||||||
|
await sendSmsCall({ phoneNumber: countryCode + newValue });
|
||||||
|
onCompleteSignUp(countryCode, newValue);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +105,7 @@ export const CompleteSignUp = ({
|
|||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
label={t('completeSignUp.phoneNumber')}
|
label={t('completeSignUp.phoneNumber')}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => setValue(e.target.value)}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
error={inputError}
|
error={inputError}
|
||||||
helperText={inputError ? error : ''}
|
helperText={inputError ? error : ''}
|
||||||
@@ -101,7 +113,16 @@ export const CompleteSignUp = ({
|
|||||||
slotProps={{
|
slotProps={{
|
||||||
htmlInput: { dir: 'auto', sx: { lineHeight: 1.5 } },
|
htmlInput: { dir: 'auto', sx: { lineHeight: 1.5 } },
|
||||||
input: {
|
input: {
|
||||||
endAdornment: (
|
endAdornment: i18n.dir() === 'rtl' && (
|
||||||
|
<CountryCodeSelector
|
||||||
|
value={countryCode}
|
||||||
|
onChange={setCountryCode}
|
||||||
|
show={true}
|
||||||
|
menuAnchor={textFieldRef.current}
|
||||||
|
onCloseFocusRef={inputRef}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
startAdornment: i18n.dir() === 'ltr' && (
|
||||||
<CountryCodeSelector
|
<CountryCodeSelector
|
||||||
value={countryCode}
|
value={countryCode}
|
||||||
onChange={setCountryCode}
|
onChange={setCountryCode}
|
||||||
|
|||||||
Reference in New Issue
Block a user