All files / src/components/Disputes/utils index.ts

96% Statements 24/25
97.29% Branches 36/37
100% Functions 4/4
100% Lines 23/23

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                  2x                                                         2x 97x         97x           97x   4718x         97x 51x             46x 46x 16x     16x             46x           2x 41x 41x       41x     41x         214x   41x 41x 37x 4x    
import { SelectorOption } from "@common/TableFilters/SelectorOption";
import { Amount } from "components/Tranfers/utils";
import {
  caseStatusesMap,
  caseTypesMap,
  refundTypesMap,
} from "../DisputesList/constants";
import { capitalizeCardType } from "@utils/index";
 
export const disputesFilterDefaultValues = {
  underwriterEmail: [],
  merchantName: [],
  caseType: [],
  disputeStatus: [],
  amount: [],
  custom: "",
  createdAt: "",
};
 
export type DisputesFilterFormValuesType = {
  underwriterEmail: SelectorOption[];
  merchantName: SelectorOption[];
  caseType: SelectorOption[];
  disputeStatus: string[];
  amount: Array<Amount>;
  custom: string;
  createdAt: string;
};
 
export type DisputeFilterFormFields =
  | "underwriterEmail"
  | "disputeStatus"
  | "merchantName"
  | "caseType"
  | "amount"
  | "custom"
  | "createdAt";
 
export const getCaseTypeInfo = (row: any, source = "dispute") => {
  const isFromRDR = Boolean(
    row?.preChargebackRefundTransactionID ||
      row?.preChargebackRefundTransaction,
  );
 
  const conditionValue = isFromRDR
    ? row?.stage
    : source === "dispute"
    ? row?.mspCaseTypeName
    : row?.mspCaseType || row?.stage;
 
  const status = caseTypesMap.find(
    (el) =>
      el.value === conditionValue ||
      el.fallbackValue === conditionValue ||
      el.label === conditionValue,
  );
 
  if (!status) {
    return {
      label: row?.stage?.toUpperCase(),
      description: "No description available.",
    };
  }
 
  // Replace {REFUND_TYPE} placeholder with actual card brand for refunds
  let label = status.label;
  if (label?.includes("{REFUND_TYPE}") && row?.cardholder?.cardBrand) {
    const cardBrandName = row.cardholder
      .cardBrand as keyof typeof refundTypesMap;
 
    label = label.replace(
      "{REFUND_TYPE}",
      refundTypesMap[cardBrandName] ||
        `${capitalizeCardType(cardBrandName)} RDR`,
    );
  }
 
  return {
    label,
    description: status.description,
  };
};
 
export const getCaseStatus = (row: any) => {
  const isWordPay = row.processorName === "worldpay";
  const isFromRDR = Boolean(
    row?.preChargebackRefundTransaction ||
      row?.preChargebackRefundTransactionID,
  );
  const isClosed = [row?.mspCaseStatusName, row?.status].includes("closed");
 
  // if closed we use outcome to display the value (won, lost) in UI
  const conditionValue = isClosed
    ? row?.outcome
    : isFromRDR
    ? row?.status
    : row?.mspCaseStatusName;
  const status = caseStatusesMap.find((el) => el.value === conditionValue);
 
  Iif ((isFromRDR || isWordPay) && row?.status === "pending") return "Open";
  if (!status || (isFromRDR && !isClosed) || row?.status === "under_review")
    return row?.statusDisplayName;
  return status.label;
};