All files / src/features/Processing/hooks useTransactionsColumns.tsx

91.66% Statements 11/12
50% Branches 3/6
75% Functions 3/4
91.66% Lines 11/12

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                                                  2x 157x   157x 157x   157x 157x             157x             576x                                                                                                                                           576x   576x                                                     157x        
import { TableColumnType } from "@common/Table";
import { ColumnBaseType, TableOrder } from "componentsV2/Table/Table.types";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
  DateColumn,
  MobileDescriptionColumn,
  StatusColumn,
} from "features/MerchantPortal/ManageMoney/ManageMoneyTable.atoms";
import { ArrowDownIcon, ArrowUpIcon } from "@phosphor-icons/react";
import {
  DesktopDescriptionColumn,
  MerchantColumn,
} from "@features/MerchantPortal/ManageMoney/TransactionsTable.atoms";
import { useAppSelector } from "@redux/hooks";
import {
  selectProcessingTab,
  selectQueryFilters,
} from "@redux/slices/transactions";
import { TransactionTableRow } from "@components/ManageMoney/TransactionTable/transactions.types";
import { useFormatDateInTimezone } from "@utils/date.helpers";
import { parseAmount } from "@utils/index";
import GiveText from "@shared/Text/GiveText";
import { Box } from "@mui/material";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
 
export const useTransactionsColumns = () => {
  const { isWideView, isLargeView } = useCustomThemeV2();
 
  const queryFilters = useAppSelector(selectQueryFilters);
  const { formatInTimezone } = useFormatDateInTimezone();
 
  const tab = useAppSelector(selectProcessingTab);
  const dateColumnConfig = {
    queryFilters,
    isWideView,
    isLargeView,
    tab,
  };
 
  const columns = [
    {
      key: "createdAt",
      columnWidth: isLargeView ? 2.1 / 12 : 3.1 / 12,
      sortable: true,
      title: "Date",
      renderColumn: (row: TransactionTableRow) => (
        <DateColumn {...row} config={dateColumnConfig} />
      ),
      hideColumn: !isWideView,
      isComplexSort: true,
      sx: {
        paddingLeft: "26px",
      },
      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",
      columnWidth: 4 / 12,
      sortable: false, // @TODO TBF019 sorting is not implemented, needs backend
      title: "Description",
      renderColumn: DesktopDescriptionColumn,
      hideColumn: !isWideView,
    },
    {
      key: "description",
      columnWidth: 2.6 / 12,
      title: "Description",
      renderColumn: (row: TransactionTableRow) => (
        <MobileDescriptionColumn {...row} formatInTimezone={formatInTimezone} />
      ),
      hideColumn: isWideView,
      ...(!isWideView && {
        columnType: "transaction-first" as ColumnBaseType,
      }),
    },
    {
      key: "merchantName",
      sortable: true,
      title: "Merchant",
      columnWidth: 2 / 12,
      renderColumn: MerchantColumn,
      hideColumn: !isWideView,
    },
    {
      key: "charged",
      sortable: true,
      title: "Amount",
      columnWidth: isWideView ? 1.2 / 12 : 2 / 12,
      type: "balanceAdjustment" as ColumnBaseType,
      headerPosition: "right" as TableColumnType["headerPosition"],
      renderColumn: (row: TransactionTableRow) => {
        const charged = parseAmount(row?.charged);
 
        return (
          <Box display="flex" width="100%" justifyContent="flex-end">
            <GiveTooltip
              title={row?.charged?.toLocaleString()}
              placement="bottom"
              disableHoverListener={Math.abs(row?.charged) < 1_000_000}
              fluidWidth
            >
              <GiveText variant="bodyS">{charged}</GiveText>
            </GiveTooltip>
          </Box>
        );
      },
    },
    {
      key: "displayStatus",
      headerPosition: "left" as TableColumnType["headerPosition"],
      sortable: false,
      title: "Status",
      columnWidth: 2 / 12,
      type: "status" as ColumnBaseType,
      columnType: "status-round" as ColumnBaseType,
      renderColumn: StatusColumn,
      hideColumn: !isWideView,
    },
  ];
 
  return {
    columns,
  };
};