All files / src/features/MerchantPortal/ManageMoney/hooks useGetManageMoneyTableColumns.tsx

89.47% Statements 17/19
78.57% Branches 11/14
77.77% Functions 7/9
89.47% Lines 17/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 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 193 194 195 196                                                    4x                   4x 51x 51x   51x 51x   51x 51x   51x             51x 13x             52x                                                                             52x                                                                   52x                       52x                                                                       52x                     51x    
import { ColumnBaseType, TableColumnType } from "@common/Table/helpers";
import { useMemo } from "react";
import {
  selectProcessingTab,
  selectQueryFilters,
} from "@redux/slices/transactions";
import { useAppSelector } from "@redux/hooks";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
  BalanceColumn,
  CreditColumn,
  DateColumn,
  DebitColumn,
  DesktopDescriptionColumn,
  MobileAmountColumn,
  MobileDescriptionColumn,
  StatusColumn,
  TypeColumn,
} from "../ManageMoneyTable.atoms";
import { ArrowDownIcon, ArrowUpIcon } from "@phosphor-icons/react";
import { TableOrder } from "componentsV2/Table/Table.types";
import { TransactionTableRow } from "@components/ManageMoney/TransactionTable/transactions.types";
import { checkPortals } from "@utils/routing";
import { Stack } from "@mui/material";
import { useFormatDateInTimezone } from "@utils/date.helpers";
 
export const columnTestIDs = {
  firstCheckedAt: "sorting-column-firstCheckedAt",
  createdAt: "sorting-column-createdAt",
  description: "sorting-column-description",
  merchantName: "sorting-column-merchantName",
  displayType: "sorting-column-displayType",
  balanceAdjustment: "sorting-column-balanceAdjustment",
  displayStatus: "sorting-column-displayStatus",
} as const;
 
export const useGetManageMoneyTableColumns = () => {
  const queryFilters = useAppSelector(selectQueryFilters);
  const { isMerchantPortal } = checkPortals();
  const { isMobileView, isLargeTabletView, isWideView, isLargeView } =
    useCustomThemeV2();
  const { formatInTimezone } = useFormatDateInTimezone();
 
  const tab = useAppSelector(selectProcessingTab);
  const showMobileView = isLargeTabletView || isMobileView;
 
  const dateColumnConfig = {
    queryFilters,
    isWideView,
    isLargeView,
    tab,
  };
 
  const columns = useMemo(
    () => [
      {
        key: "createdAt",
        testid: columnTestIDs["createdAt"],
        columnWidth: 2.2 / 12,
        title: "Date",
        renderColumn: (row: TransactionTableRow) => (
          <DateColumn {...row} config={dateColumnConfig} />
        ),
        hideColumn: showMobileView,
        sortable: true,
        isComplexSort: true,
        complexSortOptions: [
          {
            key: "createdAt",
            label: "Created - Oldest",
            order: "asc" as TableOrder,
            IconLeft: ArrowUpIcon,
          },
          {
            key: "createdAt",
            label: "Created - Newest",
            order: "desc" as TableOrder,
            IconLeft: ArrowDownIcon,
          },
          {
            key: "updatedAt",
            label: "Updated - Oldest",
            order: "asc" as TableOrder,
            IconLeft: ArrowUpIcon,
          },
          {
            key: "updatedAt",
            label: "Updated - Newest",
            order: "desc" as TableOrder,
            IconLeft: ArrowDownIcon,
          },
        ],
      },
      {
        key: "cardHolderName,merchantName,-id",
        testid: columnTestIDs["description"],
        sortable: false, // @TODO TBF019 sorting is not implemented, needs backend
        columnWidth: 5.5 / 12,
        title: "Description",
        renderColumn: (row: TransactionTableRow) => (
          <DesktopDescriptionColumn {...row} />
        ),
        hideColumn: showMobileView,
        columnType: "double-row" as ColumnBaseType,
      },
      {
        key: "description",
        testid: columnTestIDs["description"],
        columnWidth: 8 / 12,
        title: "Description",
        renderColumn: (row: TransactionTableRow) => (
          <MobileDescriptionColumn
            {...row}
            formatInTimezone={formatInTimezone}
          />
        ),
        hideColumn: !showMobileView,
      },
      {
        key: "displayType",
        testid: columnTestIDs["displayType"],
        title: "Type",
        columnWidth: 2 / 12,
        renderColumn: TypeColumn,
        hideColumn: showMobileView || !isMerchantPortal,
      },
      {
        key: "balanceAdjustment",
        testid: columnTestIDs["displayStatus"],
        sortable: true,
        title: "Credit",
        columnWidth: !showMobileView ? 1.5 / 12 : 4 / 12,
        type: "credit" as ColumnBaseType,
        headerPosition: "right" as TableColumnType["headerPosition"],
        renderColumn: (row: TransactionTableRow) => <CreditColumn {...row} />,
        hideColumn: showMobileView,
        columnType: "half-text" as ColumnBaseType,
      },
      {
        key: "-balanceAdjustment",
        testid: columnTestIDs["displayStatus"],
        sortable: true,
        title: "Debit",
        columnWidth: !showMobileView ? 1.5 / 12 : 4 / 12,
        type: "debit" as ColumnBaseType,
        headerPosition: "right" as TableColumnType["headerPosition"],
        renderColumn: (row: TransactionTableRow) => <DebitColumn {...row} />,
        hideColumn: showMobileView,
        columnType: "half-text" as ColumnBaseType,
      },
      {
        key: "balanceAdjustment",
        title: "In/Out (USD)",
        columnWidth: !showMobileView ? 1.2 / 12 : 4 / 12,
        type: "in-out" as ColumnBaseType,
        headerPosition: "left" as TableColumnType["headerPosition"],
        renderColumn: (row: TransactionTableRow) => (
          <MobileAmountColumn {...row} />
        ),
        hideColumn: !showMobileView,
        columnType: "in-out" as ColumnBaseType,
      },
      {
        key: "displayStatus",
        testid: columnTestIDs["displayStatus"],
        headerPosition: "left" as TableColumnType["headerPosition"],
        sortable: false,
        title: "Status",
        columnWidth: 2 / 12,
        type: "status" as ColumnBaseType,
        renderColumn: StatusColumn,
        hideColumn: showMobileView || !isMerchantPortal,
        columnType: "status-round" as ColumnBaseType,
      },
      {
        key: "balance",
        headerPosition: "right" as TableColumnType["headerPosition"],
        sortable: false,
        title: "Balance",
        columnWidth: 1.5 / 12,
        type: "text" as ColumnBaseType,
        renderColumn: (row: TransactionTableRow) => (
          <Stack flexGrow={1}>
            <BalanceColumn {...row} />{" "}
          </Stack>
        ),
        hideColumn: showMobileView || isMerchantPortal,
        columnType: "text" as ColumnBaseType,
      },
    ],
    [queryFilters.blocked, showMobileView, isMerchantPortal],
  );
 
  return { columns };
};