All files / src/components/common/Modal/ModalDrawer ModalDrawerBody.tsx

17.24% Statements 5/29
0% Branches 0/28
9.09% Functions 1/11
23.8% Lines 5/21

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                  4x                                                                                                                                                                                                     4x                 4x                           4x 4x                                    
import { useRef, useState, useMemo, useEffect } from "react";
import { styled, useTheme, useMediaQuery, Box, BoxProps } from "@mui/material";
import { palette } from "@palette";
import ModalDrawerHeader from "./ModalDrawerHeader";
import KotoStepper from "@common/SignUp/KotoStepper";
import { Text } from "@common/Text";
import ModalDrawerActions from "./ModalDrawerActions";
import { ModalDrawerProps } from "./types";
 
const ModalDrawerBody = ({
  HeaderProps,
  onModalClose,
  steps,
  children,
  currentStep,
  setCurrentStep,
  primaryAction,
  isPreBuildFormBuilder,
  isBody,
}: ModalDrawerProps) => {
  const [isLoaded, setIsLoaded] = useState<boolean>(false);
  const stepperRef = useRef<any>(null);
 
  const theme = useTheme();
  const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
 
  const stepIndex = useMemo(() => {
    return steps?.findIndex((step) => step.label === currentStep);
  }, [steps, currentStep]);
 
  useEffect(() => {
    if (!steps) setIsLoaded(true);
  }, []);
 
  const handleNext = () => (stepperRef.current as any).handleNext();
  const handleBack = () => (stepperRef.current as any).handleBack();
 
  const handleSubmitStep = () => {
    if (primaryAction.onClick) primaryAction.onClick();
    if (steps && stepIndex !== steps.length - 1) handleNext();
  };
 
  const actionProps = {
    steps: Boolean(steps),
    stepIndex: stepIndex,
    onModalClose: onModalClose,
    primaryAction: primaryAction,
    handleBack,
    handleSubmitStep,
    isPreBuildFormBuilder,
  };
 
  return (
    <BodyContainer height={isBody ? "96vh" : "100vh"}>
      {!isDesktop && (
        <ModalDrawerHeader {...HeaderProps} onModalClose={onModalClose} />
      )}
      {steps && (
        <KotoStepper
          sx={{
            ...(isDesktop && {
              borderBottom: `1px solid ${palette.liftedWhite[100]}`,
              background: "rgba(251, 251, 251, 0.50)",
              boxShadow: "0px 4px 8px 0px rgba(175, 175, 175, 0.05)",
              padding: "6px 8px",
            }),
          }}
          setStep={setCurrentStep}
          defaultStep={steps[0].label}
          customSteps={steps}
          ref={stepperRef}
          setIsLoaded={setIsLoaded}
          svgProps={{
            height: 8,
            width: 11,
          }}
          LinearProgressProps={{
            fontSize: "14px",
            lineHeight: "16.2px",
            mt: "12px",
          }}
        />
      )}
      {!steps && isDesktop && !isPreBuildFormBuilder && (
        <EditDesktopHeader>
          <Text
            color={palette.black[100]}
            variant="headline"
            lineHeight="21.6px"
          >
            {HeaderProps?.title}
          </Text>
          <ModalDrawerActions {...actionProps} />
        </EditDesktopHeader>
      )}
      {isLoaded && (
        <DrawerContent issteps={Boolean(steps)}>{children}</DrawerContent>
      )}
      {(steps || !isDesktop || isPreBuildFormBuilder) && (
        <>
          <Box flexGrow={1} />
          <ModalDrawerActions {...actionProps} />
        </>
      )}
    </BodyContainer>
  );
};
 
const BodyContainer = styled(Box)(() => ({
  width: "100%",
  overflowY: "auto",
  overflowX: 'hidden',
  display: "flex",
  flexDirection: "column",
  position: 'relative'
}));
 
const EditDesktopHeader = styled(Box)(() => ({
  borderBottom: `1px solid ${palette.neutral[10]}`,
  background: palette.background.dimmedWhite,
  boxShadow: "0px 4px 8px 0px rgba(175, 175, 175, 0.05)",
  padding: "12px 16px",
  backdropFilter: "blur(25px)",
  display: "flex",
  alignItems: "center",
  justifyContent: "space-between",
  position: "sticky",
  top: 0,
  zIndex: 99,
}));
 
const DrawerContent = styled(Box, {
  shouldForwardProp: (prop) => prop !== "issteps",
})<BoxProps & { issteps: boolean }>(
  ({ theme, issteps }) => ({
    paddingInline: "16px",
    flexGrow: 1,
    marginTop: "32px",
    ...(!issteps && {
      marginBottom: "16px",
    }),
 
    [theme.breakpoints.down("sm")]: {
      paddingInline: "20px",
      marginTop: "24px",
    },
  }),
);
 
export default ModalDrawerBody;