All files / src/components/ManageMoney/TransactionTable TransactionTable.atoms.tsx

96.42% Statements 27/28
70% Branches 14/20
100% Functions 15/15
96.42% Lines 27/28

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                                        27x                 2x     4x                                                   27x         2x     3x   1x                     27x 1787x 1787x             27x 39x 3x                                                       3x 3x 6x     3x 1x 1x     1x     1x 1x 1x 4x           3x                         27x 1x                                                                      
import { DownloadIcon } from "@assets/icons";
import { Button } from "@common/Button";
import { Switch_V2 } from "@common/Switch";
import { Text } from "@common/Text";
import { TypedFunction } from "@customTypes/utils.types";
import { Box, BoxProps, Skeleton, Stack, styled } from "@mui/material";
import { palette } from "@palette";
import { useAppDispatch, useAppSelector } from "@redux/hooks";
import {
  addStatusFilter,
  clearFilters,
  resetStatusFilter,
  selectTableFilter,
} from "@redux/slices/transactions";
import { getRandomNumber } from "@utils/helpers";
import { FEATURE_DENY_MESSAGE } from "constants/permissions";
import { CustomToolTip } from "@common/BusinessOwners/CustomToolTip";
import { batch } from "react-redux";
import { pendingTransactionMap } from "@shared/GiveFilter/constants";
 
export const DownloadReportButton = ({
  disabled,
  denyDownload,
  onClick,
}: {
  disabled: boolean;
  onClick: () => void;
  denyDownload?: boolean;
}) => {
  return (
    <CustomToolTip showToolTip={!!denyDownload} message={FEATURE_DENY_MESSAGE}>
      <Button
        sx={({ palette }) => ({
          paddingX: 0,
          "&:hover, &:hover path  ": {
            color: palette.neutral["100"],
            stroke: palette.neutral["100"],
          },
        })}
        endIcon={<DownloadIcon />}
        disabled={disabled || denyDownload}
        background="tertiary"
        onClick={onClick}
        data-testid="download-report-button"
      >
        Download report
      </Button>
    </CustomToolTip>
  );
};
 
export type TransactionTableFilter = {
  label: string;
  onClick: (index: number) => void;
  showAlert?: boolean;
  selected: number;
};
 
export const TableFilters = ({
  filters,
}: {
  filters: TransactionTableFilter[];
}) => {
  return (
    <Stack direction="row" alignItems="center">
      {filters.map(({ label, onClick, showAlert, selected }, idx) => (
        <TransactionFilterBase
          key={label}
          onClick={() => onClick(idx)}
          selected={selected === idx}
          data-testid={`test-id-${label.toLowerCase().replaceAll(" ", "-")}`}
        >
          {label} {showAlert && <AlertDot data-testid="alert-dot" />}
        </TransactionFilterBase>
      ))}
    </Stack>
  );
};
 
export const AlertDot = styled((props: BoxProps) => (
  <Box component="span" {...props} />
))(() => ({
  width: "8px",
  height: "8px",
  borderRadius: "100px",
  background: "#6D9CF8",
}));
 
export const TransactionFilterBase = styled(Text, {
  shouldForwardProp: (prop) => prop !== "selected" && prop !== "color",
})<{ selected: boolean; color?: string }>(({ selected, color }) => ({
  color: selected ? (color ? color : palette.black[100]) : palette.gray[300],
  lineHeight: "16.8px",
  padding: "8px 16px",
  borderRadius: "100px",
  userSelect: "none",
  display: "flex",
  alignItems: "center",
  whiteSpace: "nowrap",
  gap: "4px",
  ...(selected && {
    background: palette.liftedWhite[100],
  }),
  ...(!selected && {
    cursor: "pointer",
  }),
  ...(color && {
    "&:hover": {
      color,
    },
  }),
}));
 
interface PendingSwitchProps {
  setPage?: TypedFunction<[number]>;
}
 
export function PendingSwitch({ setPage }: PendingSwitchProps) {
  const dispatch = useAppDispatch();
  const filters = useAppSelector(selectTableFilter).filter(
    ({ value }) => value !== "!declined",
  );
 
  const handleFilterChange = (_: any, checked: boolean) => {
    Eif (setPage) {
      setPage(0);
    }
 
    Iif (!checked) {
      dispatch(resetStatusFilter());
    } else {
      batch(() => {
        dispatch(clearFilters());
        pendingTransactionMap.forEach((el) => {
          dispatch(addStatusFilter(el));
        });
      });
    }
  };
 
  return (
    <Switch_V2
      onChange={handleFilterChange}
      checked={filters.length > 0}
      size="small"
      label="Pending only"
      sxText={{
        pt: "4px",
      }}
    />
  );
}
 
export const LoadingSkeleton = () => (
  <Box
    mb="16px"
    display="flex"
    alignItems="center"
    justifyContent="space-between"
  >
    <Box>
      <Skeleton
        sx={{
          borderRadius: "22.5px",
          marginBottom: "8px",
        }}
        height="12.75px"
        width="78px"
        variant="rounded"
      />
      <Skeleton
        sx={{
          borderRadius: "22.5px",
        }}
        height="12.75px"
        width="128px"
        variant="rounded"
      />
    </Box>
    <Skeleton
      sx={{
        borderRadius: "22.5px",
      }}
      height="10.75px"
      width={`${getRandomNumber(50, 128)}px`}
      variant="rounded"
    />
  </Box>
);