All files / src/features/GiveSignup/components GiveSignup.tsx

84.09% Statements 37/44
87.5% Branches 28/32
91.66% Functions 11/12
87.8% Lines 36/41

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184                                              1x 49x 48x 48x   48x 48x       48x 48x 48x 48x     48x   48x 6x                   48x     48x   48x 33x 19x 19x 42x   19x 19x           19x           48x 1x     48x 3x     48x       48x   48x     48x   48x                                                               3x                     1x                                           1x 1x                                            
import React, { useEffect, useRef, useState } from "react";
import { Box } from "@mui/material";
import { MainLogo } from "@hooks/common/useEnterpriseLogo";
import Logo from "@assets/icons/RebrandedIcons/LogoBlueAccent";
import { isEnterpriseWebsite } from "@hooks/onboarding/utils";
import { useSearchParams } from "react-router-dom";
import { useGetMerchantsPublic } from "@hooks/useGetMerchantsPublic";
import LoadingSpinner from "@components/Snipper/LoadingSpinner";
import NotFoundPageState from "@common/EmptyState/NotFoundPageState";
import SignupFormProvider from "@components/Signup/Forms/SignupFormProvider";
import { SignupEnum, SignupStepType } from "../types";
import { initialBarsValue } from "../constants";
import { Container, SignupContainer, containerStyle } from "../styles";
import SignupKotoStepper from "./SignupKotoStepper";
import { BACKGROUND_VIDEO_PRIMARY } from "@constants/constants";
import GiveBusinessType from "./GiveBusinessType";
import GivePageFooter from "@pages/Login/components/GivePageFooter";
import GiveBusinessClassifications from "./GiveBusinessClassification";
import SignupPersonalDetails from "./PersonalDetails";
import OrganizationDetails from "./OrganizationDetails";
import GiveSentAnimation from "@features/GiveSignup/components/GiveSentAnimation";
import { personalDetailsStepIndex } from "../helpers";
 
const GiveSignup = () => {
  const [searchParams] = useSearchParams();
  const classificationParam = searchParams.get("classification");
  const isParams = Boolean(classificationParam);
 
  const isEnterprise = isEnterpriseWebsite();
  const { isLoading, isError } = useGetMerchantsPublic({
    enabled: isEnterprise,
  });
 
  const [isStart, setIsStart] = React.useState(true);
  const [isLoaded, setIsLoaded] = useState<boolean>(false);
  const stepperRef = useRef(null);
  const [step, setStep] = React.useState<SignupStepType>(
    SignupEnum.BUSINESS_CLASSIFICATION,
  );
  const [defaultKotoStep, setDefaultKotoStep] = useState(-1);
 
  useEffect(() => {
    Iif (isParams) {
      setIsStart(false);
      setStep(SignupEnum.PERSONAL_DETAILS);
      handleUpdateStatusValue(SignupEnum.BUSINESS_CLASSIFICATION)(100);
      // for personal details step the page is reloaded with step 0 but now we have previous steps loaded as well,
      // so we need to set it to the correct step id instead of 0
      (stepperRef.current as any)?.setActiveStep(personalDetailsStepIndex);
    }
  }, [isParams]);
 
  const isStartAndNotEnterprise = isStart && !isEnterprise;
 
  const [signupStatusBar, setSignupStatusBar] =
    React.useState(initialBarsValue);
 
  const handleUpdateStatusValue = React.useCallback(
    (label: string) => (value: number) => {
      setSignupStatusBar((prev) => {
        let oldArr = prev;
        const index = oldArr.findIndex((obj) => obj.label === label);
 
        Eif (index !== -1) {
          oldArr = [
            ...oldArr.slice(0, index),
            { ...oldArr[index], barValue: value },
            ...oldArr.slice(index + 1),
          ];
        }
        return oldArr;
      });
    },
    [],
  );
 
  const handleResetStatusBars = () => {
    setSignupStatusBar(initialBarsValue);
  };
 
  const handleNextStep = React.useCallback(() => {
    (stepperRef.current as any).handleNext();
  }, []);
 
  const handleBackStep = React.useCallback(() => {
    (stepperRef.current as any).handleBack();
  }, []);
 
  Iif (isLoading) return <LoadingSpinner />;
  // If provider has been deleted,the permalink should show 404 page
  Iif (isError) return <NotFoundPageState />;
 
  const showWelcomeView =
    !isStartAndNotEnterprise && isLoaded && step === "Welcome";
 
  return (
    <Box sx={containerStyle} data-testid="give-signup">
      <video autoPlay muted loop>
        <source src={BACKGROUND_VIDEO_PRIMARY} type="video/mp4" />
      </video>
      <SignupFormProvider>
        <Container alignItems="center" justifyContent="space-between">
          <MainLogo defaultLogo={<Logo />} isAuthPage position="center" />
          {!showWelcomeView && (
            <SignupContainer>
              <SignupKotoStepper
                disableWithoutStyle
                disableLastClick
                automateLast
                setStep={setStep}
                defaultStep={SignupEnum.PERSONAL_DETAILS}
                customSteps={signupStatusBar}
                ref={stepperRef}
                setIsLoaded={setIsLoaded}
                overriderActiveStep={defaultKotoStep}
                sx={{
                  "& .MuiStep-root": {
                    paddingLeft: "6px",
                    paddingRight: "6px",
                    "&:first-child": {
                      paddingLeft: "0 !important",
                    },
                  },
                }}
              />
 
              {isStartAndNotEnterprise && !isParams && (
                <GiveBusinessType setIsStart={() => setIsStart(false)} />
              )}
              <>
                {!isStartAndNotEnterprise &&
                  isLoaded &&
                  step === SignupEnum.BUSINESS_CLASSIFICATION && (
                    <GiveBusinessClassifications
                      handleUpdateStatusValue={handleUpdateStatusValue(
                        SignupEnum.BUSINESS_CLASSIFICATION,
                      )}
                      handleNext={handleNextStep}
                      setIsStart={() => setIsStart(true)}
                      handleResetStatusbars={handleResetStatusBars}
                      isFirstPage={isEnterprise}
                    />
                  )}
                {!isStartAndNotEnterprise &&
                  isLoaded &&
                  step === SignupEnum.PERSONAL_DETAILS && (
                    <SignupPersonalDetails
                      handleUpdateStatusValue={handleUpdateStatusValue(
                        SignupEnum.PERSONAL_DETAILS,
                      )}
                      personalDetailsStatusBar={signupStatusBar[1].barValue}
                      handleNext={handleNextStep}
                      handleBack={handleBackStep}
                    />
                  )}
                {!isStartAndNotEnterprise &&
                  isLoaded &&
                  step === SignupEnum.ORGANIZATION_DETAILS && (
                    <OrganizationDetails
                      handleNext={() => {
                        handleNextStep();
                        setStep(SignupEnum.WELCOME);
                      }}
                      handleBack={handleBackStep}
                      handleUpdateStatusValue={handleUpdateStatusValue(
                        SignupEnum.ORGANIZATION_DETAILS,
                      )}
                      organizationDetailsStatusBar={signupStatusBar[2].barValue}
                    />
                  )}
              </>
            </SignupContainer>
          )}
 
          {showWelcomeView && <GiveSentAnimation />}
          <GivePageFooter />
        </Container>
      </SignupFormProvider>
    </Box>
  );
};
 
export default GiveSignup;