From e4755ded7396a230dbe23732038d71d384094223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=87=D8=B1=D8=B2=D8=A7=D8=AF=20=D9=82=D8=AF=D8=B1?= =?UTF-8?q?=D8=AA=DB=8C?= Date: Tue, 12 Aug 2025 11:52:09 +0330 Subject: [PATCH] chore: add phone number logic changed --- .../AuthenticationSteps.tsx | 14 ++++++- .../AuthenticationSteps/OtpVerifyForm.tsx | 42 +++++-------------- .../AuthenticationSteps/VerifyPhoneNumber.tsx | 13 +++--- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx b/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx index 8f08908..481f5a8 100644 --- a/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx +++ b/src/features/authorization/components/AuthenticationSteps/AuthenticationSteps.tsx @@ -69,6 +69,16 @@ export const AuthenticationSteps = (): JSX.Element => { location.href = authReturnUrl; }; + const handleConfrimPhoneNumber = (userId: GUID) => { + handleUserLoggedIn(userId); + + setCurrentStep('addPhoneNumber'); + }; + + const handlePhoneNumberVerified = () => { + location.href = authReturnUrl; + }; + return ( <> {currentStep === 'emailOrPhone' && ( @@ -87,7 +97,7 @@ export const AuthenticationSteps = (): JSX.Element => { {currentStep === 'verify' && ( setCurrentStep('addPhoneNumber')} + onVerifyPhoneNumber={handleConfrimPhoneNumber} authReturnUrl={authReturnUrl} countryCode={countryCode} onOTPVerified={handleOTPVerfied} @@ -129,7 +139,7 @@ export const AuthenticationSteps = (): JSX.Element => { onEditValue={() => setCurrentStep('addPhoneNumber')} value={addedPhoneNumberValue} email={loginRegisterValue} - onPhoneNumberVerified={handleUserLoggedIn} + onPhoneNumberVerified={handlePhoneNumberVerified} /> )} diff --git a/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx b/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx index c1f992a..bc5a4c0 100644 --- a/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx +++ b/src/features/authorization/components/AuthenticationSteps/OtpVerifyForm.tsx @@ -25,8 +25,8 @@ interface OtpVerifyFormProps { authType: AuthType; authMode: AuthMode; onEditValue: () => void; - onOTPVerified: (userID: GUID) => void; - onVerifyPhoneNumber: () => void; + onOTPVerified: (userId: GUID) => void; + onVerifyPhoneNumber: (userId: GUID) => void; authReturnUrl: string; } @@ -95,38 +95,11 @@ export function OtpVerifyForm({ if (!otpCode || otpCode.length < 4) { setOtpDigitInvalid(true); } else { - if (authMode === 'register' && authType === 'email') { - handleConfirmEmailAndAddPhone(); - } else { - handleLoginRequestWithOtp(); - } + handleLoginOrSignUp(); } }; - const handleConfirmEmailAndAddPhone = async () => { - setOtpDigitInvalid(false); - setVerifyStatusLoading(true); - - const confirmOtpRequest: ConfirmEmailOtpRequest = { - otpCode: otpCode, - email: value, - }; - const result = await confirmEmailOtp(confirmOtpRequest); - const jsonRes = await result.json(); - - if (jsonRes.success) { - setVerifyStatus('success'); - onVerifyPhoneNumber(); - } else { - setVerifyStatus('failed'); - setErrorMessage(jsonRes.message); - } - - setVerifyAlertOpen(true); - setVerifyStatusLoading(false); - }; - - const handleLoginRequestWithOtp = async () => { + const handleLoginOrSignUp = async () => { setOtpDigitInvalid(false); setVerifyStatusLoading(true); @@ -141,7 +114,12 @@ export function OtpVerifyForm({ if (jsonRes.success) { setVerifyStatus('success'); - onOTPVerified(jsonRes.userId); + + if (jsonRes.registeredWithOutPhoneNumber) { + onVerifyPhoneNumber(jsonRes.userId); + } else { + onOTPVerified(jsonRes.userId); + } } else { setVerifyStatus('failed'); setErrorMessage(jsonRes.message); diff --git a/src/features/authorization/components/AuthenticationSteps/VerifyPhoneNumber.tsx b/src/features/authorization/components/AuthenticationSteps/VerifyPhoneNumber.tsx index a7638a6..d35baba 100644 --- a/src/features/authorization/components/AuthenticationSteps/VerifyPhoneNumber.tsx +++ b/src/features/authorization/components/AuthenticationSteps/VerifyPhoneNumber.tsx @@ -6,9 +6,10 @@ import type { AuthMode, AuthType } from '../../types/authTypes'; import { useEffect, useState } from 'react'; import { Toast } from '@/components/Toast'; import { AuthenticationCard } from '../AuthenticationCard'; -import type { LoginRequest } from '../../types/userTypes'; +import type { ConfirmSmsOtpRequest, LoginRequest } from '../../types/userTypes'; import { useSearchParams } from 'react-router'; import { + confirmSmsOtp, loginOrSignUpWithOtp, sendEmailOtp, sendSmsOtp, @@ -21,7 +22,7 @@ interface VerifyPhoneNumberProps { email: string; countryCode: CountryCode; onEditValue: () => void; - onPhoneNumberVerified: (userId: GUID) => void; + onPhoneNumberVerified: () => void; } export function VerifyPhoneNumber({ @@ -86,18 +87,16 @@ export function VerifyPhoneNumber({ setOtpDigitInvalid(false); setVerifyStatusLoading(true); - const loginRequest: LoginRequest = { + const confirmSmsOtpRequest: ConfirmSmsOtpRequest = { otpCode: otpCode, phoneNumber: countryCode + value, - email: email, - returnUrl: authReturnUrl, }; - const result = await loginOrSignUpWithOtp(loginRequest); + const result = await confirmSmsOtp(confirmSmsOtpRequest); const jsonRes = await result.json(); if (jsonRes.success) { setVerifyStatus('success'); - onPhoneNumberVerified(jsonRes.userId); + onPhoneNumberVerified(); } else { setVerifyStatus('failed'); setErrorMessage(jsonRes.message);