From e62f9faef88fea2c529166a56716a177ce567dd6 Mon Sep 17 00:00:00 2001 From: Sajad Mirjalili Date: Sat, 29 Nov 2025 11:31:19 +0330 Subject: [PATCH] fix: forget password bugs --- .../ForgetPassword/ChangePassword.tsx | 7 +- .../ForgetPassword/ForgetPasswordInfo.tsx | 104 ++++++++++-------- .../ForgetPassword/ForgetPasswordOtp.tsx | 9 +- 3 files changed, 70 insertions(+), 50 deletions(-) diff --git a/src/features/authentication/components/ForgetPassword/ChangePassword.tsx b/src/features/authentication/components/ForgetPassword/ChangePassword.tsx index 65df75a..e73dc8d 100644 --- a/src/features/authentication/components/ForgetPassword/ChangePassword.tsx +++ b/src/features/authentication/components/ForgetPassword/ChangePassword.tsx @@ -20,6 +20,7 @@ import type { CountryCode } from '@/types/commonTypes'; import { resetPassword } from '../../api/authorizationAPI'; import { Icon, useToast } from '@rkheftan/harmony-ui'; import { useApi } from '@/hooks/useApi'; +import { LTRTypography } from '@/components/common/LTRTypography'; export interface ChangePasswordProps { onEditInfo: () => void; @@ -136,7 +137,11 @@ export const ChangePassword = ({ endIcon={} onClick={onEditInfo} > - {forgetPasswordInfo} + + {infoType === 'email' + ? forgetPasswordInfo + : countryCode + forgetPasswordInfo} + diff --git a/src/features/authentication/components/ForgetPassword/ForgetPasswordInfo.tsx b/src/features/authentication/components/ForgetPassword/ForgetPasswordInfo.tsx index 033078e..23a8434 100644 --- a/src/features/authentication/components/ForgetPassword/ForgetPasswordInfo.tsx +++ b/src/features/authentication/components/ForgetPassword/ForgetPasswordInfo.tsx @@ -1,5 +1,5 @@ -import { Button, Stack, TextField, Typography } from '@mui/material'; -import { useRef, useState, type Dispatch } from 'react'; +import { Box, Button, Stack, TextField, Typography } from '@mui/material'; +import { useRef, useState, type Dispatch, type FormEvent } from 'react'; import { useTranslation } from 'react-i18next'; import { isNumeric } from '@/utils/regexes/isNumeric'; import type { AuthType } from '../../types/authTypes'; @@ -48,9 +48,7 @@ export function ForgetPasswordInfo({ const handleInputChange = (event: React.ChangeEvent) => { let newValue = event.target.value; newValue = replacePersianWithRealNumbers(newValue); - if (newValue.startsWith('09')) { - newValue = newValue.substring(1); - } + setForgetPasswordInfo(newValue); // If the new value contains only digits (or is empty), it's a phone number @@ -86,13 +84,26 @@ export function ForgetPasswordInfo({ } }; - const handleSubmit = async () => { + const handleSubmit = async (e: FormEvent) => { + e.preventDefault(); + if (validateInput(forgetPasswordInfo, infoType, false)) { + let newValue = forgetPasswordInfo; + + if ( + infoType === 'phone' && + countryCode === '+98' && + newValue.startsWith('09') + ) { + newValue = forgetPasswordInfo.substring(1); + setForgetPasswordInfo(newValue); + } + const sendCodeRequest: SendForgetPassCodeRequest = { email: infoType === 'email' ? forgetPasswordInfo : undefined, - phoneNumber: - infoType === 'phone' ? countryCode + forgetPasswordInfo : undefined, + phoneNumber: infoType === 'phone' ? countryCode + newValue : undefined, }; + const res = await sendForgetPassCodeCall(sendCodeRequest); if (!res) return; @@ -102,6 +113,7 @@ export function ForgetPasswordInfo({ message: res.message, severity: 'error', }); + return; } onVerifyOtp(forgetPasswordInfo); @@ -115,49 +127,49 @@ export function ForgetPasswordInfo({ return ( - - - {t('forgetPassword.forgetPassword')} - - - {t( - 'forgetPassword.pleaseEnterYourMobileNumberEmailToRecoverYourPassword', - )} - - + + + + {t('forgetPassword.forgetPassword')} + + + {t( + 'forgetPassword.pleaseEnterYourMobileNumberEmailToRecoverYourPassword', + )} + + - - ), - }, - }} - sx={{ my: 4, mb: 8 }} - /> + + ), + }, + }} + sx={{ my: 4, mb: 8 }} + /> - - + ); } diff --git a/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx b/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx index 705e718..5ad2b19 100644 --- a/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx +++ b/src/features/authentication/components/ForgetPassword/ForgetPasswordOtp.tsx @@ -16,6 +16,7 @@ import { } from '../../api/authorizationAPI'; import { Icon, useToast } from '@rkheftan/harmony-ui'; import { useApi } from '@/hooks/useApi'; +import { LTRTypography } from '@/components/common/LTRTypography'; interface ForgetPasswordOtpProps { forgetPasswordInfo: string; @@ -150,9 +151,11 @@ export function ForgetPasswordOtp({ endIcon={} onClick={onEditInfo} > - {infoType === 'phone' - ? countryCode + forgetPasswordInfo - : forgetPasswordInfo} + + {infoType === 'phone' + ? countryCode + forgetPasswordInfo + : forgetPasswordInfo} +