All files / src/components/VirtualList MainActionsHeader.tsx

0% Statements 0/20
0% Branches 0/30
0% Functions 0/5
0% Lines 0/19

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                                                                                                                                                                                                                                                                                                                 
import ExportFilterButtons from "@shared/GiveExportModal/components/ExportFilterButtons";
import { SearchBar } from "@common/SearchBar_V2";
import {
  DownloadReportButton,
  PendingSwitch,
  TableFilters,
} from "@components/ManageMoney/TransactionTable/TransactionTable.atoms";
import { useDownloadReport } from "@components/ManageMoney/TransactionTable/hooks";
import { Grid, Stack } from "@mui/material";
import FilterAtomButton from "@common/Button/FilterAtomButton";
import NiceModal from "@ebay/nice-modal-react";
import { MANAGE_MONEY_FILTER_MODAL } from "modals/modal_names";
import { QKEY_MANAGE_MONEY_TRANSACTIONS_LIST } from "@constants/queryKeys";
import { useAppDispatch, useAppSelector } from "@redux/hooks";
import {
  resetFilterByKey,
  selectFiltersObject,
} from "@redux/slices/dynamicFilterSlice";
import { isEmpty } from "lodash";
import { countTopLevelDifferences } from "@utils/helpers";
import { defaultValuesManageMoney } from "@pages/ManageMoney/constants";
import { FilterPagesEnum } from "@shared/GiveFilter/constants";
 
export function MainActionsHeader({
  queryKey,
  filters,
  tableType = "",
  isDisabled,
  filterParams,
  handleOpenFilterModal,
  handleResetFilters,
  filtersAmount,
}: {
  queryKey: string;
  filters: any;
  tableType?: "manageMoney" | "providerProcessing" | string;
  handleOpenFilterModal: () => void;
  handleResetFilters: (event: React.MouseEvent<HTMLElement>) => void;
  filtersAmount: number;
  //TODO check the disabled logic, to adapd the logic for all table filter button
  isDisabled?: boolean;
  filterParams?: string;
}) {
  const tableTitle = "Transactions";
  const { disableDownload, downloadReport, denyDownload } = useDownloadReport({
    filterParams,
    exportType: tableType || "virtual-list",
  });
  const isFilter = filtersAmount > 0;
  if (!Array.isArray(filters) && filters?.type === "REACT_COMPONENT") {
    return (
      <Grid container alignItems="center">
        {filters.jsx}
        <Stack
          direction="row"
          alignItems="center"
          gap="8px"
          sx={{
            marginLeft: "auto",
          }}
        >
          <SearchBar queryKey={queryKey} />
        </Stack>
      </Grid>
    );
  }
  if (tableType === FilterPagesEnum.MANAGE_MONEY) {
    return (
      <Stack direction="row" alignItems="center" justifyContent="space-between">
        <SearchBar queryKey={queryKey} />
        <Stack
          direction="row"
          alignItems="center"
          justifyContent="space-between"
        >
          <FilterAtomButton
            disabled={isDisabled && !isFilter}
            handleResetFilters={handleResetFilters}
            handleOpenModal={handleOpenFilterModal}
            filtersAmount={filtersAmount}
          />
          <DownloadReportButton
            disabled={disableDownload || Boolean(isDisabled)}
            denyDownload={denyDownload}
            onClick={downloadReport}
          />
        </Stack>
      </Stack>
    );
  }
  return (
    <Grid container alignItems="center">
      {filters ? <TableFilters filters={filters} /> : <PendingSwitch />}
      <Stack
        direction="row"
        alignItems="center"
        gap="16px"
        sx={{
          marginLeft: "auto",
        }}
      >
        <SearchBar queryKey={queryKey} />
        {tableTitle && ["Merchants", "Merchants list"].includes(tableTitle) && (
          <ExportFilterButtons totalRows={0} />
        )}
        {tableType === FilterPagesEnum.PROVIDER_PROCESSING && (
          <FilterAtomButton
            disabled={isDisabled && !isFilter}
            handleResetFilters={handleResetFilters}
            handleOpenModal={handleOpenFilterModal}
            filtersAmount={filtersAmount}
          />
        )}
        <DownloadReportButton
          disabled={disableDownload || Boolean(isDisabled)}
          denyDownload={denyDownload}
          onClick={downloadReport}
        />
      </Stack>
    </Grid>
  );
}
 
//TODO remove this component from mobile view
export const FilterButton = ({ isDisabled }: { isDisabled?: boolean }) => {
  const dispatch = useAppDispatch();
  const filterObject = useAppSelector((state) =>
    selectFiltersObject(state, QKEY_MANAGE_MONEY_TRANSACTIONS_LIST),
  );
 
  const handleResetFilters = (event: React.MouseEvent<HTMLElement>) => {
    event?.stopPropagation();
    dispatch(
      resetFilterByKey({
        filterKey: QKEY_MANAGE_MONEY_TRANSACTIONS_LIST,
      }),
    );
  };
  const handleOpenModal = () => NiceModal.show(MANAGE_MONEY_FILTER_MODAL);
  const filtersAmount = isEmpty(filterObject)
    ? null
    : countTopLevelDifferences(filterObject, defaultValuesManageMoney);
  const isFilter = (filtersAmount ?? 0) > 0;
  return (
    <FilterAtomButton
      disabled={isDisabled && !isFilter}
      handleResetFilters={handleResetFilters}
      handleOpenModal={handleOpenModal}
      filtersAmount={filtersAmount}
    />
  );
};