diff --git a/public/locales/en/authentication.json b/public/locales/en/authentication.json index 18287d4..ef0caca 100644 --- a/public/locales/en/authentication.json +++ b/public/locales/en/authentication.json @@ -17,7 +17,11 @@ "theVerificationCodeIsIncorrect": "The verification code is incorrect.", "youHaveSuccessfullyLoggedIn": "You have successfully logged in", "youHaveSuccessfullySignedIn": "You have successfully signed in" + }, + "completeSignUp": { + "completeSignUp": "Complete Sign Up", + "emailHasBeenSuccessfullyVerifiedPleaseEnterYourContactNumberToContinue": "Email {{ email }} has been successfully verified. Please enter your contact number to continue.", + "phoneNumber": "Phone number" } } } - \ No newline at end of file diff --git a/public/locales/fa/authentication.json b/public/locales/fa/authentication.json index 72a9536..ad86fc7 100644 --- a/public/locales/fa/authentication.json +++ b/public/locales/fa/authentication.json @@ -20,5 +20,10 @@ "theVerificationCodeIsIncorrect": "کد تایید اشتباه می باشد", "youHaveSuccessfullyLoggedIn": "با موفقیت وارد شدید", "youHaveSuccessfullySignedIn": "ثبت نام با موفقیت انجام شد" + }, + "completeSignUp": { + "completeSignUp": "تکمیل ثبت نام", + "emailHasBeenSuccessfullyVerifiedPleaseEnterYourContactNumberToContinue": "ایمیل {{ email }} با موفقیت تایید شد. برای ادامه لطفا شماره تماس خود را وارد کنید", + "phoneNumber": "شماره تماس" } } diff --git a/src/features/authentication/components/AuthenticationContainer.tsx b/src/features/authentication/components/AuthenticationContainer.tsx index 5148e47..ed1f8c8 100644 --- a/src/features/authentication/components/AuthenticationContainer.tsx +++ b/src/features/authentication/components/AuthenticationContainer.tsx @@ -3,14 +3,21 @@ import { LoginRegisterForm } from './LoginRegiserForm'; import type { AuthMode, AuthType } from '../types/auth-types'; import { OtpVerifyForm } from './OtpVerifyForm'; import { isNumeric } from '@/utils/regexes/isNumeric'; +import { CompleteSignUp } from './CompleteSignUp'; export const AuthenticationContainer = (): JSX.Element => { - const [authMode, setAuthMode] = useState('login'); + const [authMode, setAuthMode] = useState('register'); const [authType, setAuthType] = useState('phone'); const [currentStep, setCurrentStep] = useState< - 'emailOrPassword' | 'verify' | 'enterPassword' | 'addPhoneNumber' + | 'emailOrPassword' + | 'verify' + | 'enterPassword' + | 'addPhoneNumber' + | 'addedPhoneNumberVerify' >('emailOrPassword'); const [loginRegisterValue, setLoginRegisterValue] = useState(''); + const [addedPhoneNumberValue, setAddedPhoneNumberValue] = + useState(''); const handleLoginRegister = (value: string) => { setLoginRegisterValue(value); @@ -19,8 +26,6 @@ export const AuthenticationContainer = (): JSX.Element => { }; const handleOTPVerfied = (otpCode: string) => { - console.log(otpCode); - if (authMode === 'register' && authType === 'email') { setAuthType('phone'); setCurrentStep('addPhoneNumber'); @@ -31,6 +36,18 @@ export const AuthenticationContainer = (): JSX.Element => { setCurrentStep('emailOrPassword'); }; + const handleCompleteSignUp = (countryCode: string, value: string) => { + setCurrentStep('addedPhoneNumberVerify'); + }; + + const handleCompleteSignUpOTPVerified = (otpCode: string) => { + console.log(otpCode); + }; + + const handleCompleteSignUpEditValue = () => { + setCurrentStep('addPhoneNumber'); + }; + return ( <> {currentStep === 'emailOrPassword' && ( @@ -52,6 +69,25 @@ export const AuthenticationContainer = (): JSX.Element => { value={loginRegisterValue} /> )} + + {currentStep === 'addPhoneNumber' && ( + + )} + + {currentStep === 'addedPhoneNumberVerify' && ( + + )} ); }; diff --git a/src/features/authentication/components/CompleteSignUp.tsx b/src/features/authentication/components/CompleteSignUp.tsx new file mode 100644 index 0000000..ccf8eb6 --- /dev/null +++ b/src/features/authentication/components/CompleteSignUp.tsx @@ -0,0 +1,106 @@ +import { Box, Button, TextField, Typography } from '@mui/material'; +import parsePhoneNumberFromString from 'libphonenumber-js'; +import React, { useRef, useState, type Dispatch } from 'react'; +import { useTranslation } from 'react-i18next'; +import { CountryCodeSelector } from './CountryCodeSelector'; + +export interface CompleteSignUpProps { + email: string; + value: string; + setValue: Dispatch; + onCompleteSignUp: (countryCode: string, value: string) => void; +} + +export const CompleteSignUp = ({ + email, + value, + setValue, + onCompleteSignUp, +}: CompleteSignUpProps) => { + const { t } = useTranslation('authentication'); + const [countryCode, setCountryCode] = useState('+98'); + const [error, setError] = useState(); + const textFieldRef = useRef(null); + const inputRef = useRef(null); + const [touched, setTouched] = useState(false); + const inputError: boolean = touched && !!error; + + const isPhoneValid = (code: string, phone: string) => { + const phoneNumber = parsePhoneNumberFromString(code + phone); + + return phoneNumber && phoneNumber.isValid(); + }; + + const handleBlur = () => { + setTouched(true); + + if (!value) { + setError(t('loginForm.thisFieldIsRequired')); + } + if (!isPhoneValid(countryCode, value)) { + setError(t('loginForm.phoneNumberIsInvalid')); + } else { + setError(undefined); + } + }; + + const handleCompleteSignUp = () => { + if (!value) { + setError(t('loginForm.thisFieldIsRequired')); + inputRef.current?.focus(); + } + if (!isPhoneValid(countryCode, value)) { + setError(t('loginForm.phoneNumberIsInvalid')); + inputRef.current?.focus(); + } else { + setError(undefined); + onCompleteSignUp(countryCode, value); + } + }; + + return ( + + + {t('completeSignUp.completeSignUp')} + + + + {t( + 'completeSignUp.emailHasBeenSuccessfullyVerifiedPleaseEnterYourContactNumberToContinue', + { email }, + )} + + + setValue(e.target.value)} + onBlur={handleBlur} + error={inputError} + helperText={inputError ? error : ''} + autoFocus + slotProps={{ + htmlInput: { dir: 'auto', sx: { lineHeight: 1.5, paddingX: 0 } }, + input: { + endAdornment: ( + + ), + }, + }} + sx={{ my: 4 }} + /> + + + + ); +}; diff --git a/src/providers/CustomThemeProvider.tsx b/src/providers/CustomThemeProvider.tsx index ee1201e..374cea1 100644 --- a/src/providers/CustomThemeProvider.tsx +++ b/src/providers/CustomThemeProvider.tsx @@ -46,7 +46,7 @@ export const CustomThemeProvider: React.FC<{ children: React.ReactNode }> = ({ }, [i18n]); return ( - + {children} );