fix: ui bugs
This commit is contained in:
@@ -4,10 +4,14 @@ import { useRef, useState, type ChangeEvent, type Dispatch } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AuthenticationCard } from '../AuthenticationCard';
|
||||
import { CountryCodeSelector } from '../../../../components/CountryCodeSelector';
|
||||
import { sendSmsOtp } from '../../api/authorizationAPI';
|
||||
import {
|
||||
sendSmsCodeCompleteUserInforamation,
|
||||
sendSmsOtp,
|
||||
} from '../../api/authorizationAPI';
|
||||
import type { CountryCode } from '@/types/commonTypes';
|
||||
import { useApi } from '@/hooks/useApi';
|
||||
import { replacePersianWithRealNumbers } from '@/utils/replacePersianWithRealNumbers';
|
||||
import { useToast } from '@rkheftan/harmony-ui';
|
||||
|
||||
export interface CompleteSignUpProps {
|
||||
email: string;
|
||||
@@ -16,6 +20,7 @@ export interface CompleteSignUpProps {
|
||||
countryCode: CountryCode;
|
||||
setCountryCode: Dispatch<CountryCode>;
|
||||
onCompleteSignUp: (countryCode: string, value: string) => void;
|
||||
setTimerValue: Dispatch<number>;
|
||||
}
|
||||
|
||||
export const CompleteSignUp = ({
|
||||
@@ -25,6 +30,7 @@ export const CompleteSignUp = ({
|
||||
countryCode,
|
||||
setCountryCode,
|
||||
onCompleteSignUp,
|
||||
setTimerValue,
|
||||
}: CompleteSignUpProps) => {
|
||||
const { t, i18n } = useTranslation('authentication');
|
||||
const [error, setError] = useState<string>();
|
||||
@@ -32,7 +38,10 @@ export const CompleteSignUp = ({
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [touched, setTouched] = useState<boolean>(false);
|
||||
const inputError: boolean = touched && !!error;
|
||||
const { loading: sendSmsLoading, execute: sendSmsCall } = useApi(sendSmsOtp);
|
||||
const { loading: sendSmsLoading, execute: sendSmsCall } = useApi(
|
||||
sendSmsCodeCompleteUserInforamation,
|
||||
);
|
||||
const toast = useToast();
|
||||
|
||||
const isPhoneValid = (code: string, phone: string) => {
|
||||
const phoneNumber = parsePhoneNumberFromString(code + phone);
|
||||
@@ -74,8 +83,20 @@ export const CompleteSignUp = ({
|
||||
newValue = newValue.substring(1);
|
||||
setValue(newValue);
|
||||
}
|
||||
await sendSmsCall({ phoneNumber: countryCode + newValue });
|
||||
onCompleteSignUp(countryCode, newValue);
|
||||
const res = await sendSmsCall({ phoneNumber: countryCode + newValue });
|
||||
|
||||
if (!res) return;
|
||||
|
||||
if (res.success) {
|
||||
onCompleteSignUp(countryCode, newValue);
|
||||
setTimerValue(res.totalSecondForCodeToExpire);
|
||||
} else {
|
||||
toast({
|
||||
message: res.message,
|
||||
severity: 'error',
|
||||
});
|
||||
setError(res.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user