All files / src/components/Disputes/DisputeTable/Table GiveDisputesTable.tsx

100% Statements 17/17
50% Branches 1/2
100% Functions 4/4
100% Lines 17/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                                            1x 12x     12x     12x 12x 12x 12x                     12x 12x     12x                             12x   6x         12x   6x                 12x 3x     12x                                                                                              
import Table from "componentsV2/Table/Table";
import BackgroundAnimation from "@shared/Banner/BackgroundAnimation";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import DisputesBanner from "../Banner/DisputesBanner";
import { useEffect, useMemo } from "react";
import useTableSearch from "componentsV2/Table/hooks/useTableSearch";
import { useComponentHeight } from "@hooks/common/useComponentHeight";
import {
  DISPUTES_QUERY_KEY,
  useDisputesTable,
} from "@components/Disputes/DisputesList/hooks/useDisputesTable";
import { GIVE_DISPUTE_PANEL } from "modals/modal_names";
import { useHandleScroll } from "componentsV2/Table/hooks/useHandleScroll";
import { useTable } from "componentsV2/Table/hooks/useTable";
import { useDisputesTableColumns } from "../hooks/useDisputesTableColumns";
import { useFilterButton } from "@shared/GiveFilter/hooks/useFilterButton";
import { FilterPagesEnum } from "@shared/GiveFilter/constants";
import { useAppSelector } from "@redux/hooks";
import { selectDisputeTab } from "@redux/slices/transactions";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { STORED_MERCHANTS_ROWS_PER_PAGE } from "@constants/stringConstants";
 
const GiveDisputesTable = () => {
  const { search, searchQuery, handleSearchChange } = useTableSearch({
    queryKey: DISPUTES_QUERY_KEY,
  });
  const { handleResetFilters, filtersAmount } = useFilterButton({
    filterPage: FilterPagesEnum.ACQUIRER_DISPUTES,
  });
  const { height } = useComponentHeight();
  const { onScroll } = useHandleScroll();
  const tab = useAppSelector(selectDisputeTab);
  const { isWideView } = useCustomThemeV2();
 
  const {
    uiData,
    totalRows,
    setPaginatedPage,
    paginatedPage,
    loading: isLoading,
    onEndReached,
    nextCursor,
    rowsPerPage,
  } = useDisputesTable();
  const { columns } = useDisputesTableColumns();
 
  const { setSelectedRowIdx, loadMore, numberOfPages, selectedRowIdx } =
    useTable({
      allRows: uiData,
      isLoading,
      totalRows,
      page: paginatedPage,
      setPageDispatcher: setPaginatedPage,
      setPage: onEndReached,
      openModal: GIVE_DISPUTE_PANEL,
      enabledInfiniteScroll: !isWideView,
      paginationMethod: isWideView ? "offset" : "cursor",
      useIdForRows: true,
      nextCursor,
      storageKey: STORED_MERCHANTS_ROWS_PER_PAGE,
    });
 
  const Head = useMemo(
    () => (
      <DisputesBanner search={search} handleSearchChange={handleSearchChange} />
    ),
    [totalRows, handleSearchChange, search, isLoading],
  );
 
  const CompactHead = useMemo(
    () => (
      <DisputesBanner
        search={search}
        handleSearchChange={handleSearchChange}
        compact
      />
    ),
    [totalRows, handleSearchChange, search, isLoading],
  );
 
  useEffect(() => {
    handleResetFilters();
  }, [tab]);
 
  return (
    <>
      <BackgroundAnimation page="manageMoney" />
      <GiveMotionWrapper
        delay={30}
        containerProps={{ sx: { height: "100%", zIndex: 2 } }}
        customStyle={{
          height: "100%",
          display: "flex",
          justifyContent: "center",
        }}
      >
        <Table
          top={height}
          openModal={GIVE_DISPUTE_PANEL}
          columns={columns}
          allRows={uiData}
          page={paginatedPage}
          setPage={onEndReached}
          setPageDispatcher={setPaginatedPage}
          totalRows={totalRows}
          queryKey={DISPUTES_QUERY_KEY}
          onScroll={onScroll}
          searchQuery={searchQuery}
          handleSearchChange={handleSearchChange}
          selectedRowIdx={selectedRowIdx}
          setSelectedRowIdx={setSelectedRowIdx}
          numberOfPages={numberOfPages}
          Head={Head}
          CompactHead={CompactHead}
          compactAnimationPage="acquirerDisputes"
          loadMore={loadMore}
          sortReduxKey={DISPUTES_QUERY_KEY}
          defaultSortKey="createdAt"
          isLoading={isLoading}
          hasFilters={filtersAmount > 0}
          handleResetFilters={handleResetFilters}
          type="disputes"
          storageKey={STORED_MERCHANTS_ROWS_PER_PAGE}
          rowsPerPage={rowsPerPage}
        />
      </GiveMotionWrapper>
    </>
  );
};
 
export default GiveDisputesTable;