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

100% Statements 4/4
80% Branches 4/5
100% Functions 2/2
100% Lines 4/4

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                                        9x         9x 1x               9x                                                        
import { NewMobileDownloadIcon } from "@assets/icons";
import { StyledIconButton } from "@common/IconButton";
import { Stack } from "@mui/material";
import React from "react";
import { useDownloadReport } from "./hooks";
import { palette } from "@palette";
import NiceModal from "@ebay/nice-modal-react";
import { DOWNLOAD_REPORT_MODAL_MOBILE } from "modals/modal_names";
import { CustomToolTip } from "@common/BusinessOwners/CustomToolTip";
import { FEATURE_DENY_MESSAGE } from "@constants/permissions";
 
function DownloadReportAction({
  filterParams,
  disabled,
  exportType = "default",
}: {
  filterParams?: string;
  disabled?: boolean;
  exportType?: string;
} = {}) {
  const { disableDownload, downloadReport, denyDownload } = useDownloadReport({
    filterParams,
    exportType,
  });
 
  const handleOpen = (event: React.MouseEvent<HTMLElement>) => {
    NiceModal.show(DOWNLOAD_REPORT_MODAL_MOBILE, {
      title: "Download transaction report?",
      confirmTitle: "Yes, download",
      cancelTitle: "Cancel",
      handleConfirm: downloadReport,
    });
  };
 
  return (
    <Stack direction="row" alignItems="center">
      <CustomToolTip showToolTip={denyDownload} message={FEATURE_DENY_MESSAGE}>
        <StyledIconButton
          onClick={handleOpen}
          disabled={disableDownload || denyDownload || disabled}
          sx={{
            maxHeight: "32px",
            maxWidth: "32px",
            padding: "0 !important",
            borderRadius: "4px",
            "&:active": {
              backgroundColor: palette.liftedWhite[200],
            },
            "&:hover path": {
              fill: "transparent",
            },
          }}
          data-testid="mobile-download-report-button"
        >
          <NewMobileDownloadIcon />
        </StyledIconButton>
      </CustomToolTip>
    </Stack>
  );
}
 
export default React.memo(DownloadReportAction);