diff --git a/src/features/authentication/components/UserCompletionForm.tsx b/src/features/authentication/components/UserCompletionForm.tsx index fe498e9..89ae3a8 100644 --- a/src/features/authentication/components/UserCompletionForm.tsx +++ b/src/features/authentication/components/UserCompletionForm.tsx @@ -58,6 +58,10 @@ export function UserCompletionForm() { useState(false); const [sentVerificationCode, setSentVerificationCode] = useState(''); + const [showVerifiedSuccess, setShowVerifiedSuccess] = useState(false); + const [showVerifiedError, setShowVerifiedError] = useState(false); + const [emailVerifiedMessage, setEmailVerifiedMessage] = useState(''); + useEffect(() => { if (password) { if (!validPassword) { @@ -107,28 +111,28 @@ export function UserCompletionForm() { try { const response = await apiClient.post('/User/SendEmailOtp', { email }); if (response.data?.success) { - setSentVerificationCode(response.data.message); setShowVerifyCodeSectionSuccess(true); - setCodeSent(true); - setButtonState('counting'); - setCountdown(120); - setSuccess(true); setSentVerificationCode( response.data.message || 'کد با موفقیت ارسال شد', ); + setCodeSent(true); + setButtonState('counting'); + setCountdown(120); + } else if (response.data?.codeSentAnyway) { + setShowVerifyCodeSectionSuccess(true); + setSentVerificationCode( + 'کد ارسال شد، اما: ' + (response.data.message || ''), + ); + setCodeSent(true); + setButtonState('counting'); + setCountdown(120); } else { setShowVerifyCodeSectionError(true); setSentVerificationCode(response.data.message || 'مشکلی پیش آمده'); - // setError( - // response.data?.message || t('completion.verificationCodeError'), - // ); } } catch (err: any) { setShowVerifyCodeSectionError(true); setSentVerificationCode(err.response?.data?.message || 'مشکلی پیش آمده'); - // setError( - // err.response?.data?.message || t('completion.verificationCodeError'), - // ); } finally { setLoading(false); } @@ -146,25 +150,25 @@ export function UserCompletionForm() { try { const res = await apiClient.post('/User/ConfirmEmailOtp', { email, - otp: verificationCode, + otpCode: verificationCode, }); if (res.data?.success) { setEmailVerified(true); setSuccess(true); - if (res.data.access_token) { - localStorage.setItem('authToken', res.data.access_token); - apiClient.defaults.headers.common['Authorization'] = - `Bearer ${res.data.access_token}`; - } + setShowVerifiedSuccess(true); + setEmailVerifiedMessage(res.data.message || 'کد با موفقیت تایید شد'); } else { - setError(res.data?.message || 'Invalid verification code'); + // setError(res.data?.message || 'Invalid verification code'); + setShowVerifiedError(true); + setEmailVerifiedMessage(res.data?.message || 'کد تایید نامعتبر است'); + setEmailVerified(false); } } catch (err: any) { - setError( - err.response?.data?.message || - 'Something went wrong while verifying the code', - ); + setError(err.response?.data?.message || 'خطای ناشناخته'); + setShowVerifiedError(true); + setEmailVerifiedMessage(err.response?.data?.message || 'خطای ناشناخته'); + setEmailVerified(false); } finally { setIsVerifyingCode(false); } @@ -188,7 +192,7 @@ export function UserCompletionForm() { message: string; validations: { property: string; message: string }[]; }>('/User/CompleteUserInformation', { - userId: '9cb8ae51-95f9-4f66-99b4-1c7c4d48251b', + userId: '3fa85f64-5717-4562-b3fc-2c963f66afa6', firstName, lastName, gender: sex === 'female' ? 2 : 1, @@ -300,6 +304,22 @@ export function UserCompletionForm() { > {sentVerificationCode} + + setShowVerifiedSuccess(false)} + > + {emailVerifiedMessage} + + + setShowVerifiedError(false)} + > + {emailVerifiedMessage} +