All files / src/components/Merchants/MerchantPreview/helpers businessOwners.ts

87.5% Statements 7/8
88% Branches 22/25
100% Functions 1/1
87.5% Lines 7/8

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            13x 117x       117x   117x     117x   117x                                             13x                                                          
import { renderBODeps } from "@components/ProfilePage/BusinessProfileSetupNew/utils/principal.utils";
import { TBusinessOwner, TinType } from "../data.types";
import { isEmptyPhone } from "@utils/date.helpers";
import { getServicePhoneNumber } from "@utils/helpers";
import { normalizeAddress } from "@utils/address";
 
export const generateDefaultValues = (data?: TBusinessOwner) => {
  Iif (!data) {
    return {};
  }
  const { isUSCitizen, isUSResident, shouldUseSSN, shouldUseDocNumber } =
    renderBODeps(data);
 
  const tinType = data?.tinType === "ein" ? "ein" : ("ssn" as TinType);
 
  // Use normalizeAddress to handle all address variations consistently
  const normalizedAddress = normalizeAddress(data);
 
  return {
    ...data,
    ...normalizedAddress, // Spread flat address properties (line1, city, state, zip, country)
    street: normalizedAddress.line1, // street is an alias for line1
    address: normalizedAddress,
    businessAddress: normalizedAddress,
    isUSCitizen,
    isUSResident,
    citizenship: data.citizenship || "US",
    countryOfResidence: data.countryOfResidence || data.citizenship || "US",
    documentType: data.documentType || "passport_id",
    documentNumber: data.documentNumber || "",
    tinType,
    ssn: shouldUseSSN && tinType === "ssn" ? data?.ssn : "",
    ein: shouldUseSSN && tinType === "ein" ? data?.ein : "",
    dob: data?.dob ? data?.dob : null,
    phone: isEmptyPhone(data?.phone) ? "" : getServicePhoneNumber(data?.phone),
    files: {
      allFiles: [],
    },
  };
};
 
export const defaultBOFormValues = {
  firstName: "",
  lastName: "",
  email: "",
  ownership: "10",
  tinType: "ssn" as TinType,
  ssn: "",
  ein: "",
  dob: null,
  phone: "",
  isUSResident: true,
  isUSCitizen: true,
  citizenship: "US",
  isNotResidentInCitizenshipCountry: false,
  countryOfResidence: "US",
  documentType: "passport_id",
  documentNumber: "",
  useBusinessAddress: false,
  address: {
    country: "US",
    line1: "",
    city: "",
    state: "",
    zip: "",
  },
  files: {
    allFiles: [],
  },
};