TP-28528 | Login Flow update
This commit is contained in:
@@ -28,6 +28,7 @@ import { GoogleSignin } from '@react-native-google-signin/google-signin';
|
||||
|
||||
export interface GenerateOTPPayload {
|
||||
phoneNumber: string;
|
||||
otpToken?: string;
|
||||
}
|
||||
|
||||
export interface VerifyOTPPayload {
|
||||
@@ -44,12 +45,16 @@ export interface ImpersonationPayload {
|
||||
}
|
||||
|
||||
export const generateOTP =
|
||||
({ phoneNumber }: GenerateOTPPayload, isResendOTP?: boolean) =>
|
||||
({ phoneNumber, otpToken }: GenerateOTPPayload, isResendOTP?: boolean) =>
|
||||
(dispatch: Dispatch) => {
|
||||
const url = getApiUrl(ApiKeys.GENERATE_OTP);
|
||||
dispatch(setFormLoading(true));
|
||||
axiosInstance
|
||||
.post(url, { phoneNumber: Number(phoneNumber) }, { headers: { donotHandleError: true } })
|
||||
.post(
|
||||
url,
|
||||
{ phoneNumber: Number(phoneNumber), otpToken },
|
||||
{ headers: { donotHandleError: true } }
|
||||
)
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
if (response?.data?.data?.otpToken) {
|
||||
|
||||
@@ -46,7 +46,7 @@ export enum ApiKeys {
|
||||
}
|
||||
|
||||
export const API_URLS: Record<ApiKeys, string> = {} as Record<ApiKeys, string>;
|
||||
API_URLS[ApiKeys.GENERATE_OTP] = '/auth/otp/generate';
|
||||
API_URLS[ApiKeys.GENERATE_OTP] = '/auth/request-otp';
|
||||
API_URLS[ApiKeys.VERIFY_OTP] = '/auth/otp/verify';
|
||||
API_URLS[ApiKeys.ALL_CASES] = '/cases/all-cases';
|
||||
API_URLS[ApiKeys.CASE_DETAIL] = '/cases/get-cases';
|
||||
|
||||
@@ -20,13 +20,15 @@ const OtpText: React.FC<IOtpText> = ({ resetOtp }) => {
|
||||
const [countDownTimeLeft, setCountDownTimeLeft] = useState<number>(RESEND_OTP_TIME);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { phoneNumber, verifyOTPError } = useSelector((state: RootState) => state.loginInfo);
|
||||
const { phoneNumber, verifyOTPError, otpToken } = useSelector(
|
||||
(state: RootState) => state.loginInfo
|
||||
);
|
||||
|
||||
const handleResendOTP = () => {
|
||||
setCountDownComplete(false);
|
||||
setCountDownTimeLeft(RESEND_OTP_TIME);
|
||||
dispatch(resetVerifyOTPError());
|
||||
dispatch(generateOTP({ phoneNumber }, true));
|
||||
dispatch(generateOTP({ phoneNumber, otpToken }, true));
|
||||
resetOtp();
|
||||
};
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ function Login() {
|
||||
formState: { isValid },
|
||||
} = useForm<ILoginForm>();
|
||||
const dispatch = useAppDispatch();
|
||||
const { phoneNumber, OTPError, isLoading, deviceId } = useSelector((state: RootState) => ({
|
||||
deviceId: state.user.deviceId,
|
||||
const { phoneNumber, OTPError, isLoading, otpToken } = useSelector((state: RootState) => ({
|
||||
phoneNumber: state.loginInfo.phoneNumber,
|
||||
otpToken: state.loginInfo.otpToken,
|
||||
OTPError: state.loginInfo.OTPError,
|
||||
isLoading: state.loginInfo.isLoading,
|
||||
}));
|
||||
@@ -68,8 +68,12 @@ function Login() {
|
||||
}, []);
|
||||
|
||||
const handleGenerateOTP = (data: GenerateOTPPayload) => {
|
||||
let payload = {
|
||||
...data,
|
||||
otpToken: data.phoneNumber === phoneNumber ? otpToken : undefined,
|
||||
};
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_LOGIN_SCREEN_SEND_OTP_CLICKED);
|
||||
dispatch(generateOTP(data));
|
||||
dispatch(generateOTP(payload));
|
||||
};
|
||||
|
||||
const onPressGoogle = async () => {
|
||||
|
||||
Reference in New Issue
Block a user