All files / src/features/Merchants/MerchantSidePanel/GiveMerchantFile GiveSectionItem.tsx

77.77% Statements 7/9
83.33% Branches 25/30
66.66% Functions 2/3
85.71% Lines 6/7

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                        94x             3081x       3081x 3037x                                                                                                                                                                           94x             6074x                        
import { ReactNode } from "react";
import { Box, Grid, Stack, SxProps } from "@mui/material";
import { CountryFlag } from "@common/CountryFlag";
import GiveText from "@shared/Text/GiveText";
import CopyButton from "./components/CopyButton";
import { parseAmount } from "@utils/index";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import { followLink } from "@hooks/common/documents/utils";
import { omitLeadingZeros } from "@utils/helpers";
import { ISectionItem } from "@features/TransactionPanel/types";
import { maxHeight } from "@material-ui/system";
 
export const GiveSectionItem = ({
  item,
  sx,
}: {
  item: ISectionItem;
  sx?: SxProps;
}) => {
  const linkHandler = () => {
    if (item.isLink) followLink(item.value as string, { target: "__blank" });
  };
 
  if (item.hidden) return <></>;
  return (
    <Grid container item xs={12} spacing={2} justifyContent="center" sx={sx}>
      <CustomGridItem>
        <GiveText variant="bodyS" color="secondary">
          {item.title}
        </GiveText>
      </CustomGridItem>
      <CustomGridItem>
        <Stack
          direction="row"
          alignItems="center"
          justifyContent="space-between"
          position="relative"
        >
          <Stack
            direction="row"
            alignItems="center"
            gap={1}
            justifyContent="flex-start"
            maxWidth={item.canBeCopied ? "85%" : "100%"}
          >
            {item.isPhoneNumber && typeof item.value === "string" && (
              <CountryFlag phoneNumber={omitLeadingZeros(item.value)} />
            )}
            {Boolean(item.icon) && (
              <Box display="flex" alignItems="center" justifyContent="center">
                {item.icon}
              </Box>
            )}
            <Box
              component="span"
              display="flex"
              alignItems="center"
              onClick={linkHandler}
              width="100%"
              sx={{
                cursor: item.isLink ? "pointer" : "default",
              }}
            >
              <GiveTruncateText
                variant="bodyS"
                color="primary"
                lineClamp={item.hideOverflow ? 1 : 10}
              >
                {item.value ? (
                  <>
                    {item.isAmount
                      ? parseAmount(+item.value)
                      : item.isPhoneNumber
                      ? omitLeadingZeros(item.value as string)
                      : item.value}{" "}
                    {item?.showCurrency && (
                      <span style={{ marginLeft: "3px" }}>USD</span>
                    )}
                    {item.suf && (
                      <span style={{ marginLeft: "3px" }}>{item.suf}</span>
                    )}
                  </>
                ) : (
                  "-"
                )}
              </GiveTruncateText>
            </Box>
          </Stack>
          {item.canBeCopied && item.isLink && (
            <CopyButton text={item.value as string} fluidWidth />
          )}
        </Stack>
      </CustomGridItem>
      {item.notes && (
        <Box display="flex" justifyContent="flex-end">
          <CustomGridItem
            sx={{
              paddingTop: 0,
            }}
          >
            <GiveText variant="bodyS" color="secondary">
              {item.notes}
            </GiveText>
          </CustomGridItem>
        </Box>
      )}
    </Grid>
  );
};
 
const CustomGridItem = ({
  children,
  sx,
}: {
  children: ReactNode;
  sx?: any;
}) => (
  <Grid
    xs={6}
    item
    sx={{
      padding: "12px 16px !important",
      alignContent: "center",
      ...sx,
    }}
  >
    {children}
  </Grid>
);