All files / src/sections DownloadReport.tsx

5.26% Statements 1/19
0% Branches 0/16
0% Functions 0/5
5.88% Lines 1/17

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                                                              2x                                                                                                                                                                                                                                                                                                        
import * as React from "react";
import { palette } from "@palette";
import NiceModal, { muiDialogV5, useModal } from "@ebay/nice-modal-react";
// mui
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
import { Link } from "@mui/material";
// components
import { Text } from "@common/Text";
import { Modal } from "@common/Modal";
import { Button } from "@common/Button";
// assets
import {
  FileDockIcon,
  ChromeIcon,
  SafariIcon,
  FirefoxIcon,
} from "@assets/icons";
// localization
import { useTranslation } from "react-i18next";
import { namespaces } from "localization/resources/i18n.constants";
import { showMessage } from "@common/Toast/ShowToast";
 
type IProps = {
  title: string;
  closeAction?: () => void;
  handleDownload  :() => void ;
};
 
const DownloadReport = NiceModal.create(({ title, closeAction ,handleDownload}: IProps) => {
  const theme = useTheme();
  const modal = useModal();
  const [choose, setChoose] = React.useState(false);
  const { t } = useTranslation(namespaces.pages.manageMoney);
  const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
 
  const handleClose = () => {
    modal.hide();
    if (closeAction) closeAction();
  };
 
  const mockSuccessGeneration = () => {
    showMessage("Success", "Merchants.csv downloaded successfully");
    modal.hide();
    if (closeAction) closeAction();
  }
 
  const downloadLinks = {
    safari: "https://www.idownloadblog.com/2020/01/22/always-allow-downloads-safari-mac/",
    chrome: "https://techwiser.com/stop-google-chrome-from-blocking-downloads/",
    firefox: "https://support.mozilla.org/en-US/kb/cant-download-or-save-files",
  }
 
  return (
    <Modal
      {...muiDialogV5(modal)}
      title={`${title} Report`}
      titleIcon={<FileDockIcon />}
      onClose={handleClose}
      actions={
        <>
          <Button variant="text" onClick={() => handleClose()}>
            {t("buttons.cancel", { ns: namespaces.common })}
          </Button>
          <Button variant="primary" onClick={handleDownload || mockSuccessGeneration}>
            {t("buttons.DownloadReport", { ns: namespaces.common })}
          </Button>
        </>
      }
    >
      {choose ? (
        <>
          {/** --------------------- CHOOSE BROWSWER ------------------ */}
          <Stack gap={2}>
            <Text
              variant="h5"
              textAlign="center"
              fontWeight="semibold"
              color={palette.neutral[800]}
            >
              {t("blockingDownload_msg")}
            </Text>
            {/* ------------ Button Icons ------------ */}
            <Stack
              gap={1.5}
              justifyContent="center"
              direction={isDesktop ? "row" : "column"}
            >
              <Link
                href={downloadLinks.safari}
                underline="none"
                target="_blank"
              >
                <Button
                  variant="primary"
                  fullWidth={!isDesktop}
                  endIcon={<SafariIcon />}
                  size={isDesktop ? "small" : "medium"}
                >
                  Safari
                </Button>
              </Link>
              <Link 
                href={downloadLinks.chrome}
                underline="none"
                target="_blank"
              >
                <Button
                  variant="primary"
                  fullWidth={!isDesktop}
                  endIcon={<ChromeIcon />}
                  size={isDesktop ? "small" : "medium"}
                >
                  Chrome
                </Button>
              </Link>
              <Link
                href={downloadLinks.firefox}
                underline="none"
                target="_blank"
              >
                <Button
                  variant="primary"
                  fullWidth={!isDesktop}
                  endIcon={<FirefoxIcon />}
                  size={isDesktop ? "small" : "medium"}
                >
                  Firefox
                </Button>
              </Link>
            </Stack>
 
            <Text
              variant="body"
              textAlign="center"
              color={palette.neutral[600]}
            >
              {t("try_different_browser_msg")}
            </Text>
          </Stack>
        </>
      ) : (
        <>
          <Text
            variant="h5"
            fontWeight="semibold"
            color={palette.neutral[800]}
            gutterBottom
          >
            {t("download_Transactions_report_msg")}
          </Text>
 
          <Text
            variant="body"
            mt={1}
            fontWeight="medium"
            color={palette.neutral[600]}
          >
            {t("download_Transactions_report_msg2")}
            <Box
              component="span"
              fontWeight="semibold"
              sx={{ cursor: "pointer" }}
              color={palette.primary.main}
              onClick={() => setChoose(true)}
            >
              {" "}
              {t("clickHere")}{" "}
            </Box>
          </Text>
        </>
      )}
    </Modal>
  );
});
 
export default DownloadReport;