All files / src/pages/Login GiveLogin.tsx

72.22% Statements 13/18
50% Branches 8/16
100% Functions 2/2
76.47% Lines 13/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93                      1x 29x                                       28x 28x       28x   28x   28x 7x     28x       28x                 28x                               28x       28x                            
import { useLogin } from "@hooks/auth-api";
import { useAppSelector } from "@redux/hooks";
import { selectAuth } from "@redux/slices/auth/auth";
import Cookies from "js-cookie";
import { useEffect } from "react";
import DifferentAccount from "./DifferentAccount";
import GiveLoginOTP from "./GiveLoginOTP";
import GiveLoginContent from "./components/GiveLoginContent";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveCheckYourEmailContent from "./components/GiveCheckYourEmailContent";
 
const GiveLogin = () => {
  const isAuthenticated = useAppSelector(selectAuth);
 
  const {
    isLoading,
    showAlert,
    location,
    methods,
    isPasswordVisible,
    handleVerify,
    tmpStep2,
    error2FA,
    is2FALoading,
    onSubmit,
    togglePasswordVisible,
    isDifferentAccount,
    onSwitchAccount,
    onContinueAnyway,
    setTmpStep2,
    onGoBack,
    isEmailSent,
  } = useLogin();
  const { isMobileView } = useCustomThemeV2();
 
  const {
    watch,
  } = methods;
 
  const email = watch("email") || ""
 
  useEffect(() => {
    Iif (isAuthenticated && !Cookies.get("user")) window.location.reload();
  }, [isAuthenticated]);
 
  Iif (isAuthenticated) {
    return <></>;
  }
 
  Iif (isDifferentAccount) {
    return (
      <DifferentAccount
        onContinueAnyway={onContinueAnyway}
        onSwitchAccount={onSwitchAccount}
      />
    );
  }
 
  Iif (tmpStep2.email) {
    return (
      <GiveLoginOTP
        withLoginMainContainer={false}
        onSubmit={onSubmit}
        setTmpStep2={setTmpStep2}
        handleVerify={handleVerify}
        onGoBack={onGoBack}
        error={error2FA}
        isLoading={!!is2FALoading || !!isLoading}
        email={tmpStep2.email}
        isMobileView={isMobileView}
      />
    );
  }
 
  Iif (isEmailSent) {
    return <GiveCheckYourEmailContent email={email} />;
  }
 
  return (
    <GiveLoginContent
      isLoading={isLoading}
      showAlert={showAlert}
      location={location}
      methods={methods}
      isPasswordVisible={isPasswordVisible}
      onSubmit={onSubmit}
      togglePasswordVisible={togglePasswordVisible}
    />
  );
};
 
export default GiveLogin;