All files / src/shared GiveStatementPreview.tsx

93.33% Statements 14/15
88.23% Branches 15/17
100% Functions 4/4
93.33% Lines 14/15

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                9x 9x                             3x   3x   3x                                                                                                                                                                                           9x 12x   6x 6x   6x   6x                                 9x             3x                         3x                
import { Stack } from "@mui/material";
import { styled, useAppTheme } from "@theme/v2/Provider";
import GiveText from "./Text/GiveText";
import { Box } from "@mui/material";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveThumbnail from "./Thumbnail/GiveThumbnail";
import { ThumbnailType } from "./Thumbnail/getIconType";
 
const title = `Customer's Credit Card Statement Preview`;
const GiveStatementPreview = ({
  cardSrc,
  merchantName,
  date,
  amount,
  imageUrl,
  type = "merchant",
}: {
  merchantName?: string;
  cardSrc?: string;
  date?: string;
  amount?: string;
  imageUrl?: string;
  type?: ThumbnailType;
}) => {
  const theme = useAppTheme();
 
  const { isMobileView } = useCustomThemeV2();
 
  return (
    <Stack width="100%" gap="12px" marginBottom="24px ">
      <GiveText fontSize="14px">{title}</GiveText>
      <Stack sx={{ position: "relative" }}>
        <Box
          data-testid="statement-preview"
          sx={{
            display: "flex",
            flexDirection: "row",
            alignItems: "center",
            justifyContent: "space-between",
            backgroundColor: theme.palette.surface?.secondary,
            borderRadius: "20px",
            height: "72px",
            p: "16px 20px",
            lineHeight: "21.6px",
            fontWeight: "350",
            boxShadow: "0px 3px 8px 0px rgba(161, 175, 180, 0.10)",
            zIndex: 15,
          }}
        >
          <Stack
            direction="row"
            alignItems="center"
            gap="12px"
            sx={{
              minWidth: 0,
              flexShrink: 1,
              flexGrow: 1,
            }}
          >
            <GiveThumbnail type={type} size="small" imageUrl={imageUrl} />
            <GiveText
              sx={{
                whiteSpace: "nowrap",
                overflow: "hidden",
                textOverflow: "ellipsis",
                minWidth: 0,
                maxWidth: "160px",
              }}
              fontSize="14px"
              color="primary"
              component="p"
            >
              <GiveText color="secondary" component="span" variant="bodyS">
                GIV*
              </GiveText>
              {merchantName?.toUpperCase()}
            </GiveText>
          </Stack>
 
          {!isMobileView && (
            <Box
              component="img"
              sx={{
                width: "28px",
                height: "18px",
                mx: "12px",
              }}
              src={cardSrc}
            />
          )}
 
          <Wrapper isMobileView={isMobileView}>
            <GiveText
              sx={{
                whiteSpace: "nowrap",
                overflow: "hidden",
                textOverflow: "ellipsis",
              }}
              fontSize="14px"
              color={isMobileView ? "secondary" : "primary"}
            >
              {date}
            </GiveText>
            <GiveText
              sx={{
                whiteSpace: "nowrap",
                overflow: "hidden",
                textOverflow: "ellipsis",
              }}
              fontSize="14px"
            >
              {amount}
            </GiveText>
          </Wrapper>
        </Box>
        <StackLayer isFirst />
        <StackLayer />
      </Stack>
    </Stack>
  );
};
 
const StackLayer = styled(Box, {
  shouldForwardProp: (prop) => prop !== "isFirst",
})<{ isFirst?: boolean }>(({ isFirst, theme }) => {
  const surfacePrimary = theme.palette.surface?.primary;
  const surfaceInvert = "rgba(0,0,0,0.05)";
  const darken =
    theme.palette.primitive?.transparent?.[isFirst ? "darken-5" : "darken-10"];
 
  return {
    width: isFirst ? "92%" : "84%",
    height: "100%",
    position: "absolute",
    left: isFirst ? "4%" : "8%",
    zIndex: isFirst ? 10 : 5,
    top: isFirst ? 10 : 20,
    borderRadius: "20px",
    background: `
      linear-gradient(180deg, ${surfaceInvert} 0%, transparent 100%),
      linear-gradient(0deg, ${darken} 0%, ${darken} 100%),
      ${surfacePrimary}
    `, // Gradient copied from Figma — renders wrong in the original file, but correct pasted in a new draft.
    boxShadow: "0px 3px 15px 0px rgba(161, 175, 180, 0.10)",
  };
});
 
const Wrapper = ({
  isMobileView,
  children,
}: {
  isMobileView: boolean;
  children: React.ReactElement[];
}) => {
  Iif (isMobileView)
    return (
      <Stack
        sx={{
          display: "flex",
          flexDirection: "column-reverse",
          alignItems: "flex-end",
          justifyContent: "center",
        }}
      >
        {children}
      </Stack>
    );
  return (
    <Stack direction="row" gap="12px">
      {children}
    </Stack>
  );
};
 
export default GiveStatementPreview;