All files / src/features/GiveTransfers GiveTransfersTable.tsx

93.33% Statements 14/15
70% Branches 7/10
100% Functions 3/3
93.33% Lines 14/15

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                                          1x         25x 25x                       25x   25x 25x   25x     25x                             25x       25x 25x                   25x   16x                     25x                                                                            
import { useLocation } from "react-router-dom";
import NiceModal from "@ebay/nice-modal-react";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import BackgroundAnimation from "@shared/Banner/BackgroundAnimation";
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 { TRANSACTION_INFO_MODAL } from "modals/modal_names";
import { useEffect, useMemo } from "react";
import { useGetTransfersTableColumns } from "@features/GiveTransfers/hooks/useGetTransfersTableColumns";
import TransfersTableBanner from "@features/GiveTransfers/TransfersTableBanner";
import { useComponentHeight } from "@hooks/common/useComponentHeight";
 
type GiveTransfersTableProps = Omit<TableProps, "columns" | "openModal"> & {
  totalExportRecords?: number;
  allRows?: any;
  totalRows?: number;
};
 
const GiveTransfersTable = ({
  nextCursor,
  paginationMethod,
  ...props
}: GiveTransfersTableProps) => {
  const { columns } = useGetTransfersTableColumns();
  const { height } = useComponentHeight();
  const {
    totalExportRecords,
    allRows,
    totalRows,
    type,
    queryKey,
    isFetching,
    page,
    setPageDispatcher,
    setPage,
    isLoading,
  } = props;
 
  const location = useLocation();
  const isLoadingTransactions = isLoading || isFetching;
 
  const { onScroll } = useHandleScroll();
 
  const { setSelectedRowIdx, loadMore, numberOfPages, selectedRowIdx } =
    useTable({
      useIdForRows: true,
      allRows,
      isLoading: isLoading,
      totalRows,
      page,
      setPageDispatcher,
      isFetching,
      setPage,
      openModal: TRANSACTION_INFO_MODAL,
      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]);
 
  const Head = useMemo(
    () => (
      <TransfersTableBanner
        search={search}
        handleSearchChange={handleSearchChange}
        actualTotalRows={totalRows}
        sortReduxKey={queryKey}
        isEmpty={!props.hasFilters && totalRows === 0}
      />
    ),
    [type, handleSearchChange, search, totalRows, isLoadingTransactions],
  );
 
  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={TRANSACTION_INFO_MODAL}
          columns={columns}
          totalRows={totalRows}
          queryKey={queryKey}
          onScroll={onScroll}
          searchQuery={searchQuery}
          handleSearchChange={handleSearchChange}
          selectedRowIdx={selectedRowIdx}
          loadMore={loadMore}
          numberOfPages={numberOfPages}
          Head={Head}
          setSelectedRowIdx={setSelectedRowIdx}
          sortReduxKey={queryKey}
          defaultSortKey="createdAt"
          isLoading={isLoading}
        />
      </GiveMotionWrapper>
    </>
  );
};
 
export default GiveTransfersTable;