All files / src/features/Merchants/MerchantSidePanel/UnderwritingTasks utils.ts

81.81% Statements 18/22
60.86% Branches 14/23
50% Functions 3/6
81.81% Lines 18/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 151 152 153 154 155 156 157 158        29x             29x             29x                                                                                                         29x           29x         29x                     29x     1x               1x 1x                                 1x               1x 1x 1x       1x                 1x 1x           1x          
import NiceModal from "@ebay/nice-modal-react";
import { GIVE_CONFIRMATION_POP_UP } from "modals/modal_names";
import { ModalMerchantData } from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/types";
 
export const StatusDisplayName = {
  closed: "Completed",
  ready_for_verification: "Ready for Confirmation",
  open: "Open",
  rejected: "Rejected",
};
 
export const NewStatusDisplayName = {
  open: "Ready for KYB",
  in_progress: "In Progress",
  ready_for_underwriting: "Ready for Underwriting",
  completed: "Completed",
};
 
export const TaskNames = {
  MERCHANT_CATEGORY_VERIFICATION: "merchant_category_verification",
  MERCHANT_CATEGORY_CODE_MCC: "merchant_category_code_mcc",
  NEGATIVE_NEWS_SCREENING: "negative_news_screening",
  WEBSITE_VERIFICATION: "website_verification",
  WEBSITE: "website",
  VOLUME_ASSESSMENT: "volume_assessment",
  VERIFY_BILLING_DESCRIPTOR: "verify_billing_descriptor",
  BILLING_DESCRIPTOR: "billing_descriptor",
  MERCHANT_PURPOSE_OR_MISSION: "merchant_purpose_or_mission",
  LOCATED_IN_USA: "located_in_usa",
  COUNTRIES_SERVICED_ALLOWED: "countries_serviced_allowed",
  GOODS_AND_SERVICES: "goods_or_services",
  UNDERWRITING_MATCH_SCREENING_CHECK: "underwriting_match_screening_check",
  PRIMARY_ACCOUNT_HOLDER_OFAC_CHECK: "primary_account_holder_ofac_check",
  OFAC_PRIMARY_ACCOUNT_HOLDER_CHECK: "ofac_primary_account_holder_check",
  PRIMARY_ACCOUNT_HOLDER_OFAC: "primary_account_holder_ofac",
  BUSINESS_OWNER_PEP_CHECK: "business_owner_pep_check",
  BUSINESS_OWNER_PEP_CHECK_MATCH: "business_owner_pep_match",
  BUSINESS_OWNER_PEP_CHECK_MATCH_CONFIRMED:
    "business_owner_pep_match_confirmed",
  BUSINESS_OWNER_OFAC_CHECK: "ofac_business_owner_check",
  PRIMARY_ACCOUNT_HOLDER_ID_VERIFICATION:
    "primary_account_holder_id_verification",
  PRIMARY_ACCOUNT_HOLDER_IDENTITY: "primary_account_holder_identity",
  BUSINESS_OWNER_VERIFICATION: "business_owner_verification",
  BUSINESS_OWNER: "business_owner",
  ACCOUNT_MANAGEMENT_VERIFICATION: "account_management_verification",
  PRIMARY_ACCOUNT_HOLDER_OFAC_MATCH_CONFIRMED:
    "primary_account_holder_ofac_match_confirmed",
  PRIMARY_ACCOUNT_HOLDER_OFAC_POSSIBLE_MATCH:
    "primary_account_holder_ofac_match",
  BUSINESS_ADDRESS: "business_address",
  BUSINESS_PROFILE: "business_profile",
  BUSINESS_PROFILE_VERIFICATION_AND_APPROVAL:
    "business_profile_verification_and_approval",
  BUSINESS_TIN: "business_tin",
  BUSINESS_OWNER_OFAC_CHECK_MATCH_CONFIRMED:
    "business_owner_ofac_match_confirmed",
  BUSINESS_OWNER_OFAC_CHECK_MATCH: "business_owner_ofac_match",
  BUSINESS_PROFILE_OFAC_CHECK: "business_profile_ofac_check",
  OFAC_BUSINESS_PROFILE_CHECK: "ofac_business_profile_check",
  BUSINESS_PROFILE_OFAC_CHECK_MATCH: "business_profile_ofac_match",
  BUSINESS_PROFILE_OFAC_CHECK_MATCH_CONFIRMED:
    "business_profile_ofac_match_confirmed",
  BANK_ACCOUNT_VERIFICATION: "bank_account_verification",
  BANK_ACCOUNT: "bank_account",
  MATCH_SCREENING_CHECK: "match_screening_check",
  BANK_ACCOUNT_NAME_MATCHES_EVIDENCE: "bank_account_name_matches_evidence",
  AGREEMENT: "agreement",
  CLASSIFICATION: "classification",
};
 
export const BP_INFO = {
  title: "Incomplete information",
  message:
    "To continue, please make sure all details for the Business Profile and Business Owner are provided, and that an MCC is assigned to the merchant.",
};
 
export const tasksWithReject = [
  TaskNames.LOCATED_IN_USA,
  TaskNames.NEGATIVE_NEWS_SCREENING,
];
 
export const ofacTitles = {
  PEP: "PEP Check",
  BO: "OFAC Check",
  PAH: "OFAC Check",
  MATCH: "MATCH Check",
  BUSINESS_CHECK: "OFAC Check",
};
 
export const missingInfoRules: Record<
  string,
  (data: ModalMerchantData) => boolean
> = {
  primary_account_holder_identity: (data) => !data?.primaryAccountHolder?.email,
  business_profile: (data) =>
    !data?.businessProfile?.taxID &&
    !data?.businessProfile?.ssn &&
    !data?.businessProfile?.legalName,
  business_owner: (data) => data?.businessOwners?.length === 0,
  bank_account: (data) => data?.bankAccounts?.length === 0,
};
 
export function hasMissingInfo(key: string, data: ModalMerchantData): boolean {
  const rule = missingInfoRules[key];
  return rule?.(data) ?? false;
}
 
export function showMissingInfoModal({
  challengeKey,
  challengeName,
  merchantData,
  showNewMissingInfo = false,
  customMessage = "",
}: {
  challengeKey?: string;
  challengeName?: string;
  merchantData?: ModalMerchantData;
  showNewMissingInfo?: boolean;
  customMessage?: string;
}): boolean {
  const showMissingModal =
    (challengeKey &&
      merchantData &&
      hasMissingInfo(challengeKey, merchantData)) ||
    showNewMissingInfo;
 
  // if show New missing true, update title and description based on it
 
  // if BP missing info we show improved text
  const isBPChallenge = challengeName === "Business Profile";
  const usedTitle = isBPChallenge ? BP_INFO.title : challengeName;
  const usedDescription = isBPChallenge
    ? BP_INFO.message
    : "To complete the task, all fields must be filled in";
 
  const modalInfo = {
    title: showNewMissingInfo ? usedTitle : `Missing ${challengeName}`,
    description: showNewMissingInfo
      ? customMessage
        ? customMessage
        : usedDescription
      : `Please create a ${challengeName} before completing this task.`,
  };
 
  Eif (showMissingModal) {
    NiceModal.show(GIVE_CONFIRMATION_POP_UP, {
      modalType: "missing-info",
      ...modalInfo,
      customSubmitBtnText: "Close",
      hideCancel: true,
    });
    return true;
  }
 
  return false;
}