All files / src/components/ProfilePage/BusinessProfileSetup/utils principal.utils.ts

21.05% Statements 4/19
0% Branches 0/14
0% Functions 0/3
22.22% Lines 4/18

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          31x                                       31x                                                             31x                                     31x              
import { showMessage } from "@common/Toast";
import { TMerchantDocument } from "@components/Merchants/MerchantPreview/data.types";
import { BILLING_DESCRIPTOR_MAX_LENGTH } from "@constants/constants";
import { toISODateString } from "@utils/date.helpers";
 
export const onPrincipalError = (error: any) => {
  const errorMessage = error.response.data.message;
  const errorInputs = error.response.data.input;
  const errorCode = error.response.data.code;
 
  if (errorCode === "invalid_input") {
    for (const err of errorInputs) {
      showMessage(
        "Error",
        `${err.message ? err.message : err.param}`,
        true,
        "",
        6000,
      );
    }
  } else {
    showMessage("Error", `${errorMessage}`);
  }
};
 
export const generatePrincipalPayload = (values: any) => {
  const isNOTaxNumber = values?.ssn?.toLowerCase()?.startsWith("x");
  const isConfirmMatch = values?.pepStatusName === "confirmed_match";
 
  if (isConfirmMatch) {
    return {
      id: values?.id,
      ownershipPercentage: values.ownership ? +values.ownership : null,
    };
  }
 
  return {
    ...values,
    ...(!isNOTaxNumber && {
      taxIDNumber: values?.ssn,
    }),
    ...(!values?.useBusinessAddress && {
      address: {
        line1: values?.street,
        city: values?.city,
        state: values?.state,
        zip: values?.zip,
        country: values?.country,
      },
    }),
    ownershipPercentage: values?.ownership,
    dateOfBirth: toISODateString(values.DOB as Date | string | null),
    useEntityGeoAddress: values?.useBusinessAddress,
  };
};
 
export const businessOwnerDescriptions = {
  individual_sole_proprietorship:
    "Sole Proprietor businesses can only have one owner.",
  corporation:
    "A beneficial owner is any individual who directly or indirectly owns 10% or more of the company's shares.",
  limited_liability_company:
    "A beneficial owner is any individual who directly or indirectly owns 10% or more of the company's shares.",
  partnership:
    "A beneficial owner is any individual who directly or indirectly owns 10% or more of the company's shares.",
  general_partnership:
    "A beneficial owner is any individual who directly or indirectly owns 10% or more of the company's shares.",
  limited_partnership:
    "A beneficial owner is any individual who directly or indirectly owns 10% or more of the company's shares.",
  tax_exempt_organization:
    "As a non-profit entity, you are required to identify and provide information for one individual with significant responsibility for managing the non-profit, such as the executive director or a senior officer.",
  government_agency:
    "As a non-profit entity, you are required to identify and provide information for one individual with significant responsibility for managing the non-profit, such as the executive director or a senior officer.",
} as const;
 
export const formatBillingDescriptor = (value?: string) => {
  if (!value) return "";
  return value
    .replace(/[^a-zA-Z0-9]/g, "")
    ?.slice(0, BILLING_DESCRIPTOR_MAX_LENGTH)
    .toUpperCase();
};