All files / src/shared/GiveExportModal/components GiveExportContent.tsx

100% Statements 8/8
66.66% Branches 4/6
100% Functions 2/2
100% Lines 8/8

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                                                        86x                 86x                 86x 1x 1x     86x                                                                                                                                                   25x             25x              
import PanelLoadingSkeleton from "@features/Merchants/MerchantSidePanel/components/PanelLoadingSkeleton";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import {
  SidePanelFooterContainer,
  SidePanelHeaderBase,
} from "@shared/SidePanel/components/SidePanelHeader/SidePanelHeader";
import { SidePanelContainerWrapper } from "@shared/SidePanel/SidePanelAtoms";
import GiveText from "@shared/Text/GiveText";
import { FormProvider } from "react-hook-form";
import ExportModalContent from "./ExportModalContent";
import GiveButton from "@shared/Button/GiveButton";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import ProgressBar from "@shared/SidePanel/components/SidePanelHeader/ProgressBar";
import { XIcon } from "@phosphor-icons/react";
import useGenerateFieldData from "../hooks/useGenerateFieldData";
import { styled } from "@theme/v2/Provider";
import { EXPORT_PANEL_WIDTH, TableType } from "../const";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { ContentProps } from "../giveExportTypes";
 
export default function GiveExportContent({
  handleClose,
  fieldTypes,
  merchantID,
  counts,
  tab,
  hasFilters,
}: ContentProps) {
  const { isMobileView } = useCustomThemeV2();
  const {
    methods,
    fieldRawData,
    handleSubmit,
    isLoading,
    isLoadingSubmission,
    isFormValid,
    message,
  } = useGenerateFieldData({
    fieldTypes,
    merchantID,
    counts,
    tab,
    onClose: handleClose,
    hasFilters,
  });
 
  const onClose = () => {
    methods.reset();
    handleClose?.();
  };
 
  return (
    <SidePanelContainerWrapper
      sx={{
        display: "flex",
        flexDirection: "column",
        height: "100%",
        width: isMobileView ? "100%" : EXPORT_PANEL_WIDTH,
      }}
    >
      <SidePanelHeaderBase
        leftItems={<GiveText variant="bodyM">Export Table</GiveText>}
        noBorderBottom={isLoading}
        rightItems={
          <GiveIconButton
            data-testid="panel-x-icon"
            Icon={XIcon}
            variant="ghost"
            onClick={onClose}
            size="small"
          />
        }
      />
 
      {isLoading ? (
        <>
          <ProgressBar isLoading />
          <PanelLoadingSkeleton variant="export" />
        </>
      ) : (
        <FormProvider {...methods}>
          <FormContainer onSubmit={methods.handleSubmit(handleSubmit)}>
            <ContentWrapper>
              <ExportModalContent fieldRawData={fieldRawData} />
            </ContentWrapper>
 
            <SidePanelFooterContainer>
              <>
                <GiveButton
                  label="Cancel"
                  variant="ghost"
                  size="large"
                  onClick={onClose}
                  disabled={isLoadingSubmission}
                />
 
                <GiveTooltip
                  placement="top"
                  sx={{
                    width: "unset",
                  }}
                  disableHoverListener={isFormValid}
                  title={message}
                >
                  <GiveButton
                    disabled={!isFormValid || isLoadingSubmission}
                    label="Export CSV"
                    variant="filled"
                    size="large"
                    type="submit"
                    sx={{
                      width: "unset",
                    }}
                    loading={isLoadingSubmission}
                  />
                </GiveTooltip>
              </>
            </SidePanelFooterContainer>
          </FormContainer>
        </FormProvider>
      )}
    </SidePanelContainerWrapper>
  );
}
 
const FormContainer = styled("form")({
  display: "flex",
  flexDirection: "column",
  flexGrow: 1,
  minHeight: 0,
});
 
const ContentWrapper = styled("div")({
  flexGrow: 1,
  overflowY: "auto",
  overflowX: "hidden",
  minHeight: 0,
  width: "100%",
});