All files / src/features/MerchantPortal/ManageMoney ManageMoneyTable.tsx

96.42% Statements 27/28
80% Branches 12/15
100% Functions 5/5
96.42% Lines 27/28

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 181 182 183 184 185 186 187 188 189 190 191 192                                                              4x         51x 51x                       51x   51x 51x 51x 51x   51x   51x       51x   51x         51x                           51x       51x 48x                   51x 12x 11x 11x   1x 1x     51x   27x                             51x   28x                                               51x                                                                                  
import NiceModal from "@ebay/nice-modal-react";
import BackgroundAnimation from "@shared/Banner/BackgroundAnimation";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import { useHandleScroll } from "componentsV2/Table/hooks/useHandleScroll";
import { useTable } from "componentsV2/Table/hooks/useTable";
import useTableSearch from "componentsV2/Table/hooks/useTableSearch";
import Table from "componentsV2/Table/Table";
import { TableProps } from "componentsV2/Table/Table.types";
import {
  MANAGE_MONEY_INFO_MODAL,
  TRANSACTION_INFO_MODAL,
} from "modals/modal_names";
import { useEffect, useMemo, useState } from "react";
import { useLocation } from "react-router-dom";
import { useGetManageMoneyTableColumns } from "./hooks/useGetManageMoneyTableColumns";
import ManageMoneyBanner from "./ManageMoneyBanner";
import { useAppDispatch } from "@redux/hooks";
import { useTransactionsFilters } from "@features/Processing/hooks/useTransactionsFilters";
import { checkPortals } from "@utils/routing";
import {
  addBlockedAndQuarantinedFilter,
  resetStatusFilter,
} from "@redux/slices/transactions";
import { useComponentHeight } from "@hooks/common/useComponentHeight";
 
type ManageMoneyTableProps = Omit<TableProps, "columns" | "openModal"> & {
  totalExportRecords?: number;
  allRows?: any;
  totalRows?: number;
};
 
const ManageMoneyTable = ({
  nextCursor,
  paginationMethod,
  ...props
}: ManageMoneyTableProps) => {
  const { columns } = useGetManageMoneyTableColumns();
  const { height } = useComponentHeight();
  const {
    totalExportRecords,
    allRows,
    totalRows,
    type,
    queryKey,
    isFetching,
    page,
    setPageDispatcher,
    setPage,
    isLoading,
  } = props;
 
  const location = useLocation();
  const dispatch = useAppDispatch();
  const { isMerchantPortal, isAcquirerOrProviderManageMoney } = checkPortals();
  const [localIsLoading, setLocalIsLoading] = useState<boolean>(false);
 
  const isLoadingTransactions = localIsLoading || isLoading || isFetching;
 
  const { tableFilters, selectedFilter } = useTransactionsFilters({
    isLoading: isLoadingTransactions,
  });
 
  const { onScroll } = useHandleScroll();
 
  const usedModalId = !isMerchantPortal
    ? MANAGE_MONEY_INFO_MODAL
    : TRANSACTION_INFO_MODAL;
 
  const { setSelectedRowIdx, loadMore, numberOfPages, selectedRowIdx } =
    useTable({
      allRows,
      isLoading: isLoading,
      totalRows,
      page,
      setPageDispatcher,
      isFetching,
      setPage,
      openModal: usedModalId,
      paginationMethod,
      nextCursor,
      enabledInfiniteScroll: props.enabledInfiniteScroll,
    });
 
  const { search, searchQuery, handleSearchChange } = useTableSearch({
    queryKey: queryKey || "",
  });
 
  useEffect(() => {
    Iif (location.state && location.state.transactionData) {
      NiceModal.show(TRANSACTION_INFO_MODAL, {
        undefined,
        data: location.state.transactionData,
        isFirst: true,
        isLast: true,
      });
    }
  }, [location]);
 
  useEffect(() => {
    if (isAcquirerOrProviderManageMoney) {
      dispatch(resetStatusFilter([]));
      return;
    }
    dispatch(addBlockedAndQuarantinedFilter());
    dispatch(resetStatusFilter());
  }, []);
 
  const Head = useMemo(
    () => (
      <ManageMoneyBanner
        search={search}
        handleSearchChange={handleSearchChange}
        actualTotalRows={totalRows}
        sortReduxKey={queryKey}
        type={type}
        filters={tableFilters}
        selectedTabFilter={String(selectedFilter)}
        setLocalIsLoading={setLocalIsLoading}
        localIsLoading={localIsLoading}
      />
    ),
    [type, handleSearchChange, search, totalRows, isLoadingTransactions],
  );
 
  const CompactHead = useMemo(
    () => (
      <ManageMoneyBanner
        search={search}
        handleSearchChange={handleSearchChange}
        actualTotalRows={totalRows}
        sortReduxKey={queryKey}
        type={type}
        filters={tableFilters}
        selectedTabFilter={String(selectedFilter)}
        setLocalIsLoading={setLocalIsLoading}
        localIsLoading={localIsLoading}
        compact
      />
    ),
    [
      type,
      handleSearchChange,
      search,
      totalRows,
      isLoadingTransactions,
      selectedFilter,
      localIsLoading,
    ],
  );
 
  return (
    <>
      <BackgroundAnimation page="manageMoney" />
      <GiveMotionWrapper
        delay={30}
        containerProps={{ sx: { height: "100%", zIndex: 2 } }}
        customStyle={{
          height: "100%",
          display: "flex",
          justifyContent: "center",
        }}
      >
        <Table
          {...props}
          top={height}
          totalExportRecords={totalExportRecords}
          openModal={usedModalId}
          columns={columns}
          totalRows={totalRows}
          queryKey={queryKey}
          onScroll={onScroll}
          searchQuery={searchQuery}
          handleSearchChange={handleSearchChange}
          selectedRowIdx={selectedRowIdx}
          loadMore={loadMore}
          numberOfPages={numberOfPages}
          Head={Head}
          CompactHead={CompactHead}
          compactAnimationPage="manageMoney"
          setSelectedRowIdx={setSelectedRowIdx}
          sortReduxKey={queryKey}
          defaultSortKey="createdAt"
          isLoading={isLoading || localIsLoading}
          showLoadedRowCount
        />
      </GiveMotionWrapper>
    </>
  );
};
 
export default ManageMoneyTable;