fix: API calls
This commit is contained in:
@@ -58,6 +58,10 @@ export function UserCompletionForm() {
|
|||||||
useState(false);
|
useState(false);
|
||||||
const [sentVerificationCode, setSentVerificationCode] = useState('');
|
const [sentVerificationCode, setSentVerificationCode] = useState('');
|
||||||
|
|
||||||
|
const [showVerifiedSuccess, setShowVerifiedSuccess] = useState(false);
|
||||||
|
const [showVerifiedError, setShowVerifiedError] = useState(false);
|
||||||
|
const [emailVerifiedMessage, setEmailVerifiedMessage] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (password) {
|
if (password) {
|
||||||
if (!validPassword) {
|
if (!validPassword) {
|
||||||
@@ -107,28 +111,28 @@ export function UserCompletionForm() {
|
|||||||
try {
|
try {
|
||||||
const response = await apiClient.post('/User/SendEmailOtp', { email });
|
const response = await apiClient.post('/User/SendEmailOtp', { email });
|
||||||
if (response.data?.success) {
|
if (response.data?.success) {
|
||||||
setSentVerificationCode(response.data.message);
|
|
||||||
setShowVerifyCodeSectionSuccess(true);
|
setShowVerifyCodeSectionSuccess(true);
|
||||||
setCodeSent(true);
|
|
||||||
setButtonState('counting');
|
|
||||||
setCountdown(120);
|
|
||||||
setSuccess(true);
|
|
||||||
setSentVerificationCode(
|
setSentVerificationCode(
|
||||||
response.data.message || 'کد با موفقیت ارسال شد',
|
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 {
|
} else {
|
||||||
setShowVerifyCodeSectionError(true);
|
setShowVerifyCodeSectionError(true);
|
||||||
setSentVerificationCode(response.data.message || 'مشکلی پیش آمده');
|
setSentVerificationCode(response.data.message || 'مشکلی پیش آمده');
|
||||||
// setError(
|
|
||||||
// response.data?.message || t('completion.verificationCodeError'),
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setShowVerifyCodeSectionError(true);
|
setShowVerifyCodeSectionError(true);
|
||||||
setSentVerificationCode(err.response?.data?.message || 'مشکلی پیش آمده');
|
setSentVerificationCode(err.response?.data?.message || 'مشکلی پیش آمده');
|
||||||
// setError(
|
|
||||||
// err.response?.data?.message || t('completion.verificationCodeError'),
|
|
||||||
// );
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -146,25 +150,25 @@ export function UserCompletionForm() {
|
|||||||
try {
|
try {
|
||||||
const res = await apiClient.post('/User/ConfirmEmailOtp', {
|
const res = await apiClient.post('/User/ConfirmEmailOtp', {
|
||||||
email,
|
email,
|
||||||
otp: verificationCode,
|
otpCode: verificationCode,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.data?.success) {
|
if (res.data?.success) {
|
||||||
setEmailVerified(true);
|
setEmailVerified(true);
|
||||||
setSuccess(true);
|
setSuccess(true);
|
||||||
if (res.data.access_token) {
|
setShowVerifiedSuccess(true);
|
||||||
localStorage.setItem('authToken', res.data.access_token);
|
setEmailVerifiedMessage(res.data.message || 'کد با موفقیت تایید شد');
|
||||||
apiClient.defaults.headers.common['Authorization'] =
|
|
||||||
`Bearer ${res.data.access_token}`;
|
|
||||||
}
|
|
||||||
} else {
|
} 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) {
|
} catch (err: any) {
|
||||||
setError(
|
setError(err.response?.data?.message || 'خطای ناشناخته');
|
||||||
err.response?.data?.message ||
|
setShowVerifiedError(true);
|
||||||
'Something went wrong while verifying the code',
|
setEmailVerifiedMessage(err.response?.data?.message || 'خطای ناشناخته');
|
||||||
);
|
setEmailVerified(false);
|
||||||
} finally {
|
} finally {
|
||||||
setIsVerifyingCode(false);
|
setIsVerifyingCode(false);
|
||||||
}
|
}
|
||||||
@@ -188,7 +192,7 @@ export function UserCompletionForm() {
|
|||||||
message: string;
|
message: string;
|
||||||
validations: { property: string; message: string }[];
|
validations: { property: string; message: string }[];
|
||||||
}>('/User/CompleteUserInformation', {
|
}>('/User/CompleteUserInformation', {
|
||||||
userId: '9cb8ae51-95f9-4f66-99b4-1c7c4d48251b',
|
userId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
gender: sex === 'female' ? 2 : 1,
|
gender: sex === 'female' ? 2 : 1,
|
||||||
@@ -300,6 +304,22 @@ export function UserCompletionForm() {
|
|||||||
>
|
>
|
||||||
{sentVerificationCode}
|
{sentVerificationCode}
|
||||||
</Toast>
|
</Toast>
|
||||||
|
|
||||||
|
<Toast
|
||||||
|
color="success"
|
||||||
|
open={showVerifiedSuccess}
|
||||||
|
onClose={() => setShowVerifiedSuccess(false)}
|
||||||
|
>
|
||||||
|
{emailVerifiedMessage}
|
||||||
|
</Toast>
|
||||||
|
|
||||||
|
<Toast
|
||||||
|
color="error"
|
||||||
|
open={showVerifiedError}
|
||||||
|
onClose={() => setShowVerifiedError(false)}
|
||||||
|
>
|
||||||
|
{emailVerifiedMessage}
|
||||||
|
</Toast>
|
||||||
<EmailSection
|
<EmailSection
|
||||||
showEmail={showEmail}
|
showEmail={showEmail}
|
||||||
setShowEmail={setShowEmail}
|
setShowEmail={setShowEmail}
|
||||||
|
|||||||
Reference in New Issue
Block a user