All files / src/components/common/BottomMobileDrawer BottomConfirmationMobile.tsx

81.25% Statements 13/16
83.33% Branches 5/6
66.66% Functions 4/6
81.25% Lines 13/16

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                                                      3x 3x 3x 1x     3x         3x 1x 1x       3x       3x                         3x                 2x                                       1x  
import SwipeableDrawerMobile from "@components/SwipeableDrawerMobile/SwipeableDrawerMobile";
import { Stack, SwipeableDrawerProps } from "@mui/material";
import { Text } from "@common/Text";
import { Button } from "@common/Button";
import { BaseLink, BaseLinkProps } from "@common/Campaigns/BaseLink";
import NiceModal, { useModal } from "@ebay/nice-modal-react";
 
export interface BottomConfirmationMobileProps
  extends Omit<SwipeableDrawerProps, "onOpen"> {
  title?: string;
  cancelTitle?: string;
  confirmTitle?: string;
  confirmActionLink?: BaseLinkProps;
  customBottomActions?: JSX.Element;
  handleCancel?: VoidFunction;
  handleConfirm?: VoidFunction;
}
 
function BottomConfirmationMobile({
  title,
  cancelTitle,
  confirmTitle,
  customBottomActions,
  confirmActionLink,
  handleCancel,
  handleConfirm,
}: BottomConfirmationMobileProps) {
  const modal = useModal();
  const isModalVisible = modal.visible;
  const handleClose = () => {
    modal.hide();
  }
 
  const onCancel = () => {
    handleCancel?.();
    handleClose();
  };
 
  const onConfirm = () => {
    !confirmActionLink && handleConfirm?.();
    handleClose();
  };
 
  const confirmButton = (
    <Button onClick={onConfirm} sx={{ flex: 1 }} fullWidth size="medium">
      {confirmTitle}
    </Button>
  );
  const linkWrapper = confirmActionLink ? (
    <BaseLink
      onClick={handleClose}
      flex={1}
      sx={{ borderBottom: "none" }}
      {...confirmActionLink}
    >
      {confirmButton}
    </BaseLink>
  ) : (
    confirmButton
  );
 
  return (
    <SwipeableDrawerMobile
      open={isModalVisible}
      anchor="bottom"
      onOpen={() => ""}
      onClose={handleClose}
    >
      <Stack mt={2} padding="10px 10px" gap={5}>
        <Text
          color={({ palette }) => palette.neutral["80"]}
          textAlign="center"
          fontSize={24}
          lineHeight="24px"
        >
          {title}
        </Text>
        {customBottomActions || (
          <Stack direction="row" alignItems="baseline">
            <Button background="tertiary" onClick={onCancel}>
              {cancelTitle}
            </Button>
            {linkWrapper}
          </Stack>
        )}
      </Stack>
    </SwipeableDrawerMobile>
  );
}
 
export const DownloadReportActionModalMobile = NiceModal.create(BottomConfirmationMobile);