All files / src/sections/PayBuilder/components/InvoicePreview ItemsSection.tsx

20% Statements 2/10
0% Branches 0/15
0% Functions 0/2
20% Lines 2/10

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                      12x                                                                                                                                                                                                                             12x                                                          
import { Box, Divider, Grid, Stack } from "@mui/material";
import { CheckCircleIcon } from "@phosphor-icons/react";
import { ICartItem, useCart } from "@sections/PayBuilder/provider/CartContext";
import GiveText from "@shared/Text/GiveText";
import { useAppTheme } from "@theme/v2/Provider";
import { CartItemsList } from "./CartItemsList";
import { CARD_FEES_LABEL, CURRENCY } from "@constants/constants";
import { useIsPreviewMode } from "@sections/PayBuilder/provider/useIsPreviewMode";
import { useModal } from "@ebay/nice-modal-react";
import { NEW_PEEK_MODE_MODAL } from "modals/modal_names";
 
const ItemsSection = ({
  formattedAmount,
  cartItems,
  renewalDate,
}: {
  formattedAmount?: string;
  cartItems: ICartItem[];
  renewalDate?: string;
}) => {
  const theme = useAppTheme();
  const { fees, displayFees } = useCart();
  const { isPreviewMode } = useIsPreviewMode();
  const { visible: isPeekModalOpened } = useModal(NEW_PEEK_MODE_MODAL);
 
  const isPreview = isPreviewMode || isPeekModalOpened;
 
  return (
    <>
      <Box id="items-section">
        <Stack
          sx={{
            backgroundColor: "#f2f2f2",
            width: "100%",
            padding: "20px",
            borderRadius: "12px",
            gap: "12px",
          }}
        >
          <GiveText>Items</GiveText>
          {Boolean(cartItems.length) && <ItemsList cartItems={cartItems} />}
          <Stack
            sx={{
              backgroundColor: theme.palette.primitive?.transparent["darken-5"],
              width: "100%",
              padding: "20px",
              borderRadius: "12px",
              gap: 1,
            }}
          >
            <Stack spacing={1}>
              <Stack direction="row" justifyContent="space-between">
                <GiveText fontSize="14px">
                  {" "}
                  Subtotal ({cartItems.length} Item
                  {cartItems.length !== 1 && "s"})
                </GiveText>
                <GiveText fontSize="14px" textAlign={"right"}>
                  {formattedAmount} {CURRENCY}
                </GiveText>
              </Stack>
 
              {Boolean(fees || isPreview) && displayFees && (
                <Stack direction="row" justifyContent="space-between">
                  <GiveText variant="bodyS">{CARD_FEES_LABEL}</GiveText>
                  <GiveText variant="bodyS">
                    {isPreview ? "0.00" : fees} {CURRENCY}
                  </GiveText>
                </Stack>
              )}
 
              <Divider />
 
              <Stack direction="row" justifyContent="space-between">
                <GiveText fontSize="16px" fontWeight={700}>
                  Total
                </GiveText>
                <GiveText fontSize="16px" textAlign="right" fontWeight={700}>
                  {formattedAmount} {CURRENCY}
                </GiveText>
              </Stack>
            </Stack>
 
            {renewalDate && (
              <Stack gap={1}>
                <Stack direction="row" alignItems="center" gap={1}>
                  <CheckCircleIcon
                    width="14.63px"
                    height="14.63px"
                    color={theme.palette.primitive?.neutral[60]}
                  />
                  <GiveText
                    fontSize="12px"
                    fontWeight={400}
                    color={theme.palette.primitive?.neutral[60]}
                  >
                    Subscription renews automatically on {renewalDate}
                  </GiveText>
                </Stack>
                <Stack direction="row" alignItems="center" gap={1}>
                  <CheckCircleIcon
                    width="14.63px"
                    height="14.63px"
                    color={theme.palette.primitive?.neutral[60]}
                  />
                  <GiveText
                    fontSize="12px"
                    fontWeight={400}
                    color={theme.palette.primitive?.neutral[60]}
                  >
                    Cancel your renewal anytime
                  </GiveText>
                </Stack>
              </Stack>
            )}
          </Stack>
        </Stack>
      </Box>
    </>
  );
};
 
const ItemsList = ({ cartItems }: { cartItems: ICartItem[] }) => {
  const { palette } = useAppTheme();
  return (
    <>
      <Grid
        container
        width="100%"
        rowSpacing={1}
        id="items-list"
        paddingY={1.5}
        borderBottom={`.5px solid ${palette.primitive?.neutral[20]}`}
      >
        <Grid item md={6}>
          <GiveText color="secondary" fontSize="14px">
            Name/Description
          </GiveText>
        </Grid>
        <Grid item md={6}>
          <GiveText color="secondary" textAlign="right">
            Amount
          </GiveText>
        </Grid>
      </Grid>
      <CartItemsList cartItems={cartItems} />
    </>
  );
};
 
export default ItemsSection;