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

41.93% Statements 13/31
31.25% Branches 15/48
25% Functions 1/4
41.93% Lines 13/31

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 159 160 161 162 163 164 165    76x       226x 226x   226x 226x   226x     226x   226x                           76x                                       76x                 76x                                                                       76x                                                   76x                                                                                    
import { showMessage } from "@common/Toast";
 
export const renderBODeps = (
  data: any,
  isMerchantOnboardingModalEnabled?: any,
) => {
  data = data || {};
  const isUSCitizen = data?.citizenship === "US" || data?.citizenship === "";
  const isUSResident =
    data?.countryOfResidence === "US" || data?.countryOfResidence === "";
  const shouldUseSSN = isUSCitizen || isUSResident;
  const shouldUseDocNumber =
    !isUSCitizen &&
    ["passport_id", "national_id"].includes(data?.documentType || "");
 
  const newIsUSCitizen = data?.citizenship === "US";
 
  return {
    shouldUseSSN: isMerchantOnboardingModalEnabled
      ? newIsUSCitizen
      : shouldUseSSN,
    shouldUseDocNumber: isMerchantOnboardingModalEnabled
      ? !newIsUSCitizen
      : shouldUseDocNumber,
    isUSCitizen: isMerchantOnboardingModalEnabled
      ? newIsUSCitizen
      : isUSCitizen,
    isUSResident,
  };
};
 
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" && errorInputs && errorInputs.length > 0) {
    for (const err of errorInputs) {
      showMessage(
        "Error",
        `${err.message ? err.message : err.param}`,
        true,
        "",
        6000,
      );
    }
  } else {
    showMessage("Error", `${errorMessage}`);
  }
};
 
const removeObjUndefinedValues = (obj: any) => {
  for (const key in obj) {
    if (obj[key] === undefined) {
      delete obj[key];
    }
  }
  return obj;
};
 
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,
    };
  }
 
  const addressPayload = removeObjUndefinedValues({
    street: values?.address?.street ?? values?.street,
    line1: values?.address?.street ?? values?.street,
    city: values?.address?.city ?? values?.city,
    state: values?.address?.state ?? values?.state,
    zip: values?.address?.zip ?? values?.zip,
    country: values?.address?.country ?? values?.country,
  });
 
  const ownershipPercentage = values?.ownershipPercentage || values?.ownership;
  return {
    ...values,
    // ...(!isNOTaxNumber && {
    //   taxIDNumber: values?.ssn,
    // }),
    ...(!values?.useBusinessAddress &&
      Object.values(addressPayload).length && {
        address: { ...addressPayload },
      }),
    ownershipPercentage: +ownershipPercentage,
    dateOfBirth: values.dateOfBirth,
    useEntityGeoAddress: values?.useBusinessAddress,
  };
};
 
export const businessOwnerDescriptions = {
  individual_sole_proprietorship: "",
  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 type IgnoredValueTypes = {
  [key: string]: {
    key: string;
    value: boolean | "both";
  };
};
 
//logic of usage check 'useCalculatePercentage.tsx'
export const businessOwnerIgnoredValues: IgnoredValueTypes = {
  isUSResident: {
    key: "isUSResident",
    value: false,
  },
  citizenship: {
    key: "isUSResident",
    value: false,
  },
  countryOfResidence: {
    key: "isNotResidentInCitizenshipCountry",
    value: false,
  },
  isNotResidentInCitizenshipCountry: {
    key: "isNotResidentInCitizenshipCountry",
    value: false,
  },
  useBusinessAddress: {
    key: "useBusinessAddress",
    value: "both",
  },
  country: {
    key: "useBusinessAddress",
    value: true,
  },
  state: {
    key: "useBusinessAddress",
    value: true,
  },
  city: {
    key: "useBusinessAddress",
    value: true,
  },
  street: {
    key: "useBusinessAddress",
    value: true,
  },
  zip: {
    key: "useBusinessAddress",
    value: true,
  },
};