All files / src/features/MerchantPortal/Customers/CustomersTable/Components CustomersTableColumns.atoms.tsx

18.18% Statements 4/22
0% Branches 0/8
0% Functions 0/7
18.18% Lines 4/22

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                                                                  1x                         1x                         1x                                                   1x                                                                                                                                
import { Stack } from "@mui/material";
import GiveText from "shared/Text/GiveText";
import { Customer } from "types/customer.types";
import GiveTruncateText from "shared/Text/GiveTruncateText";
import { parseAmount } from "utils";
import {
  InfinityIcon,
  PencilSimpleIcon,
  ReceiptIcon,
} from "@phosphor-icons/react";
import { useAppTheme } from "theme/v2/Provider";
import GiveIconButton from "shared/IconButton/GiveIconButton";
import { MERCHANT_ADD_EDIT_CUSTOMER_V2 } from "modals/modal_names";
import NiceModal, { useModal } from "@ebay/nice-modal-react";
import { GIVE_CONFIRMATION_POP_UP } from "modals/modal_names";
import {
  composePermission,
  useAccessControl,
} from "features/Permissions/AccessControl";
import RESOURCE_BASE, {
  EDIT_DENY_MESSAGE,
  OPERATIONS,
} from "constants/permissions";
import GiveTooltip from "shared/Tooltip/GiveTooltip";
import { Box } from "@mui/material";
import { useCustomThemeV2 } from "theme/hooks/useCustomThemeV2";
import { useNavigate } from "react-router-dom";
import { handleViewTransactions } from "features/MerchantPortal/Customers/utils";
import useTableSearch from "componentsV2/Table/hooks/useTableSearch";
import { QKEY_MANAGE_MONEY_TRANSACTIONS_LIST } from "@constants/queryKeys";
import { useFormatDateInTimezone } from "@utils/date.helpers";
import GiveDateTooltip from "@shared/Tooltip/GiveDateTooltip";
 
export const ProfileColumn = (row: Customer) => {
  return (
    <Stack>
      <GiveTruncateText lineClamp={1} variant="bodyS">
        {row.firstName} {row.lastName}
      </GiveTruncateText>
      <GiveTruncateText color="secondary" variant="bodyXS" lineClamp={1}>
        {row.email}
      </GiveTruncateText>
    </Stack>
  );
};
 
export const JoinedColumn = ({ row }: { row: Customer }) => {
  const { formatInTimezone } = useFormatDateInTimezone();
  return (
    <Stack>
      <GiveDateTooltip>
        <GiveText variant="bodyS">
          {formatInTimezone(row?.createdAt, "MMM dd, yyyy hh:mmaa")}
        </GiveText>
      </GiveDateTooltip>
    </Stack>
  );
};
 
export const AmountColumn = ({ row }: { row: Customer }) => {
  const { palette } = useAppTheme();
  const { isWideView } = useCustomThemeV2();
  return (
    <Stack maxHeight="34px" width="100%" alignItems="flex-end" gap="2px">
      <GiveTruncateText lineClamp={1} variant="bodyS">
        {parseAmount(row.totalPurchased / 100)} {!isWideView && " USD"}
      </GiveTruncateText>
      {row.recurringCustomer && (
        <Stack gap="4px" alignItems="center" direction="row">
          <InfinityIcon color={palette.primitive?.blue["100"]} size={16} />
          <GiveText
            variant="bodyXS"
            sx={{
              color: palette.primitive?.blue["100"],
            }}
            lineHeight="16px"
          >
            Recurring
          </GiveText>
        </Stack>
      )}
    </Stack>
  );
};
 
export const ActionsColumn = (row: Customer) => {
  const { remove } = useModal(GIVE_CONFIRMATION_POP_UP);
  const navigate = useNavigate();
  const { handleSearchChange } = useTableSearch({
    queryKey: QKEY_MANAGE_MONEY_TRANSACTIONS_LIST,
  });
 
  const handleNavigateToManageMoney = () => {
    handleSearchChange(row?.email || "");
    navigate("/merchant/manage-money");
  };
 
  const isEditCustomerAllowed = useAccessControl({
    resource: composePermission(RESOURCE_BASE.MERCHANT, RESOURCE_BASE.CUSTOMER),
    operation: OPERATIONS.UPDATE,
  });
 
  return (
    <Stack width="100%" justifyContent="right" direction="row" gap="12px">
      <Box>
        <GiveTooltip
          width="compact"
          placement="top"
          title={isEditCustomerAllowed ? "Edit" : EDIT_DENY_MESSAGE}
          color="default"
          disableHoverListener={false}
        >
          <GiveIconButton
            data-testid="edit-customer-button"
            onClick={(e) => {
              e.stopPropagation();
              NiceModal.show(MERCHANT_ADD_EDIT_CUSTOMER_V2, { id: row.id });
            }}
            variant="ghost"
            Icon={PencilSimpleIcon}
            disabled={!isEditCustomerAllowed}
          />
        </GiveTooltip>
      </Box>
      <Box>
        <GiveTooltip
          width="compact"
          placement="top"
          title="Transactions"
          color="default"
          disableHoverListener={false}
        >
          <GiveIconButton
            data-testid="view-transactions-button"
            onClick={(e) => {
              e.stopPropagation();
              handleViewTransactions({
                handleSuccess: handleNavigateToManageMoney,
                handleCancel: remove,
              });
            }}
            variant="ghost"
            Icon={ReceiptIcon}
          />
        </GiveTooltip>
      </Box>
    </Stack>
  );
};