All files / src/features/MerchantPortal/Customers/CustomersTable/hooks useGetCustomersTableColumns.tsx

20% Statements 2/10
0% Branches 0/4
0% Functions 0/5
20% Lines 2/10

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                        1x                   1x                                                                                                
import { useMemo } from "react";
import { selectQueryFilters } from "@redux/slices/transactions";
import { useAppSelector } from "@redux/hooks";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import {
  ActionsColumn,
  AmountColumn,
  JoinedColumn,
  ProfileColumn,
} from "../Components/CustomersTableColumns.atoms";
import { Customer } from "types/customer.types";
 
export const columnTestIDs = {
  profile: "sorting-column-name",
  joined: "sorting-column-createdAt",
  amount: "sorting-column-amount",
  actions: "actions",
  displayType: "sorting-column-displayType",
  balanceAdjustment: "sorting-column-balanceAdjustment",
  displayStatus: "sorting-column-displayStatus",
} as const;
 
export const useGetCustomersTableColumns = () => {
  const { isWideView } = useCustomThemeV2();
  const queryFilters = useAppSelector(selectQueryFilters);
  const columns = useMemo(
    () => [
      {
        key: "firstName,lastName",
        sortable: true,
        testid: columnTestIDs["profile"],
        columnWidth: isWideView ? 3 / 12 : 8 / 12,
        title: "Profile",
        renderColumn: ProfileColumn,
        columnType: "customer-profile",
      },
      {
        key: "createdAt,-accID",
        testid: columnTestIDs["joined"],
        columnWidth: 3.5 / 12,
        sortable: true,
        title: "Joined",
        renderColumn: (row: Customer) => <JoinedColumn row={row} />,
        hideColumn: !isWideView,
      },
      {
        key: "totalPurchased",
        testid: columnTestIDs["amount"],
        columnWidth: isWideView ? 2.5 / 12 : 3.5 / 12,
        title: "Amount (USD)",
        renderColumn: (row: Customer) => <AmountColumn row={row} />,
        sortable: true,
        columnType: "amount",
        headerPosition: "right",
      },
      {
        key: "actions",
        testid: columnTestIDs["actions"],
        title: "",
        columnWidth: 3 / 12,
        renderColumn: (row: Customer) => <ActionsColumn {...row} />,
        hideColumn: !isWideView,
        columnType: "customer-actions",
      },
    ],
    [isWideView, queryFilters.blocked],
  );
 
  return { columns };
};