All files / src/sections/PayBuilder/Checkout/wrappers/WithOrderColumn index.tsx

70% Statements 14/20
52.17% Branches 12/23
50% Functions 2/4
70% Lines 14/20

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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202                        12x                                                       12x                   291x 291x 291x         291x   291x 10x 10x             291x       291x               291x                 291x                                                                                                                                   291x                                                                                            
import { Grid } from "@mui/material";
import { BottomSheet } from "../BottomSheet";
import { cloneElement } from "react";
import { useAppTheme } from "@theme/v2/Provider";
import { Order } from "./Order";
import { usePayBuilderForm } from "@sections/PayBuilder/provider/PayBuilderFormProvider";
import { useIsPreviewMode } from "@sections/PayBuilder/provider/useIsPreviewMode";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { MobileOrderAcordion } from "./MobileOrderAcordion";
import SwipeableDrawerMobile from "@components/SwipeableDrawerMobile/SwipeableDrawerMobile";
import { usePayBuilderContext } from "@sections/PayBuilder/provider/PayBuilderContext";
 
const SwipeableContainer = ({
  isPreviewMode,
  children,
  open,
  onClose,
}: any) => {
  if (isPreviewMode) {
    return children;
  }
 
  return (
    <SwipeableDrawerMobile
      open={open}
      anchor={"bottom"}
      onClose={onClose}
      onOpen={() => undefined}
      disableRestoreFocus
      sx={{
        "& .MuiPaper-root": {
          top: "auto",
        },
      }}
    >
      {children}
    </SwipeableDrawerMobile>
  );
};
 
export const WithOrderColumn = ({
  children,
  isLoading,
  methods,
  onSubmit,
  paymentSuccessInfo,
  isDeclined,
  isFailed,
  declineReason,
}: any) => {
  const { isPreviewMode } = useIsPreviewMode();
  const builderContext = usePayBuilderContext();
  const { customs } = useAppTheme();
  const {
    checkoutBottomSheetVisible,
    setCheckoutBottomSheetVisible,
    parsedValues: { background },
  } = usePayBuilderForm();
 
  const onClose = () => {
    Eif (isPreviewMode) {
      return;
    }
    setCheckoutBottomSheetVisible(false);
  };
 
  // Check if form has validation errors
  const hasFormErrors =
    methods?.formState?.errors &&
    Object.keys(methods.formState.errors).length > 0;
 
  const { isMediumDesktop, isMediumView, isMobileView, isTabletView } =
    useCustomThemeV2();
 
  const {
    screenStates: {
      isMobileView: isMobileStateSelected,
      isTabletView: isTabletStateSelected,
    },
  } =
    Object.keys(builderContext)?.length > 0
      ? builderContext
      : {
          screenStates: {
            isMobileView: isMobileView,
            isTabletView: isTabletView,
          },
        };
 
  Iif (isMediumView || isMobileStateSelected || isTabletStateSelected) {
    return (
      <SwipeableContainer
        isPreviewMode={isPreviewMode}
        open={isPreviewMode ? true : checkoutBottomSheetVisible}
        onClose={onClose}
      >
        <BottomSheet
          open={isPreviewMode ? true : checkoutBottomSheetVisible}
          onClose={onClose}
          isMobile={isMediumView}
          isPreviewMode={isPreviewMode}
        >
          <Grid
            item
            xs={12}
            style={{
              height: "100%",
              background: background,
              paddingTop: "10px",
            }}
          >
            {cloneElement(children, {
              sx: {
                marginTop: 0,
                height: "100%",
                scrollbarWidth: "none !important",
                paddingTop: 0,
                overflowY: "auto",
                borderRadius: `${customs?.radius.medium}px ${customs?.radius.medium}px 0 0`,
              },
              children: (
                <MobileOrderAcordion
                  sx={{
                    background,
                    maxWidth: "900px",
                    width: "100%",
                    ".MuiAccordionDetails-root > div": {
                      padding: "0 16px",
                    },
                    ".MuiAccordionDetails-root > div, .MuiAccordionDetails-root > div > div":
                      {
                        width: "100%",
                      },
                  }}
                >
                  <Order
                    onSubmit={methods ? methods.handleSubmit(onSubmit) : null}
                    onClose={onClose}
                    isLoading={isLoading}
                    paymentSuccessInfo={paymentSuccessInfo}
                    isWrappedInAcordion
                    isDeclined={isDeclined}
                    isFailed={isFailed}
                    declineReason={declineReason}
                    hasFormErrors={hasFormErrors}
                  />
                </MobileOrderAcordion>
              ),
            })}
          </Grid>
        </BottomSheet>
      </SwipeableContainer>
    );
  }
 
  return (
    <BottomSheet
      open={isPreviewMode ? true : checkoutBottomSheetVisible}
      onClose={onClose}
      isPreviewMode={isPreviewMode}
    >
      <Grid container style={{ height: "100%", background: background }}>
        <Grid item xs={7} style={{ height: "100%" }}>
          {cloneElement(children, {
            sx: {
              marginTop: 0,
              height: "100%",
              scrollbarWidth: "none !important",
              paddingTop: 0,
              overflowY: "auto",
              borderRadius: `${customs?.radius.medium}px 0 0 0`,
            },
          })}
        </Grid>
        <Grid
          item
          xs={5}
          gap={2}
          sx={{
            background: "rgba(0, 0, 0, 0.05)",
            padding: "32px",
            display: "flex",
            flexDirection: "column",
            maxHeight: "100%",
          }}
        >
          <Order
            onSubmit={methods ? methods.handleSubmit(onSubmit) : null}
            onClose={onClose}
            isLoading={isLoading}
            paymentSuccessInfo={paymentSuccessInfo}
            isDeclined={isDeclined}
            isFailed={isFailed}
            declineReason={declineReason}
            hasFormErrors={hasFormErrors}
          />
        </Grid>
      </Grid>
    </BottomSheet>
  );
};