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 166 | 8x 12x 12x 8x 12x 12x 9x 9x 9x 9x 9x 9x 4x 4x 4x 9x 9x 12x 9x 1x 9x 9x 9x 9x | import { MouseEvent, useMemo } from "react";
import { FieldConfig } from "../types";
import { getCountryNameFromCode } from "@utils/country_dial_codes";
import { formatInUTCMoment, isEmptyPhone } from "@utils/date.helpers";
import {
TBusinessOwner,
TBusinessProfileInfo,
TMerchantHeader,
TMerchantInfo,
} from "@components/Merchants/MerchantPreview/data.types";
import GivePepStatusChip from "@features/Merchants/MerchantSidePanel/GiveMerchantFile/businessOwners/GivePepStatusChip";
import useBusinessOwner from "@components/Settings/ManageTeam/BusinessOwners/useBusinessOwner";
import AccordionSection from "./AccordionSection";
import { TaskEmptyState, TaskLoading } from "./Sections.atoms";
import { useIsFetching } from "react-query";
import { MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS } from "@features/Merchants/MerchantSidePanel/constants";
import { betterPhoneNumber } from "../../GiveMerchantFile/hooks/helpers";
import { useAdjustAddressType } from "../hooks/useAdjustAddressType";
interface BusinessOwnerSectionProps {
data: {
businessOwners?: TBusinessOwner[];
businessProfile?: TBusinessProfileInfo;
header?: TMerchantHeader;
merchantInfo?: TMerchantInfo;
documents?: any;
[key: string]: any;
};
}
const getDOB = (dob?: any) => {
Iif (!dob) return "-";
return formatInUTCMoment(dob);
};
const getBusinessOwnerFields = (owner: TBusinessOwner): FieldConfig[] => {
const citizenshipCountry = owner.citizenship
? getCountryNameFromCode(owner.citizenship)
: "United States";
return [
{
label: "Full Name",
value: `${owner.firstName} ${owner.lastName}`,
},
{
label: "Email",
value: owner.email || "-",
},
{
label: "Ownership Percentage",
value: owner.ownership ? `${owner.ownership}%` : "-",
},
{
label: "SSN",
value: owner.ssn || "-",
},
{
label: "Date of Birth",
value: getDOB(owner.dob),
},
{
label: "Phone Number",
value:
owner.phone && !isEmptyPhone(owner.phone)
? betterPhoneNumber(owner.phone)
: "-",
isPhoneNumber: true,
},
{
label: "Country of Citizenship",
value: citizenshipCountry,
},
{
label: "Country of Residence",
value: owner.countryOfResidence
? getCountryNameFromCode(owner.countryOfResidence)
: citizenshipCountry,
},
];
};
function BusinessOwnerSection({ data }: BusinessOwnerSectionProps) {
const fetchNumber = useIsFetching({
queryKey: [
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_LEGAL_ENTITY,
data?.merchantData?.merchantID,
],
});
const { adjustAddressType } = useAdjustAddressType();
const isFetching = fetchNumber > 0;
const isIndividualSoleProprietorship =
data.businessProfile?.businessType === "individual_sole_proprietorship";
const businessOwners = data?.businessOwners || [];
const stakeSum = useMemo(() => {
return (
businessOwners?.reduce((acc, owner) => {
const _ownership = owner.ownership ? +owner.ownership : 0;
return acc + _ownership;
}, 0) || 0
);
}, [businessOwners]);
const { editOwnerHandler } = useBusinessOwner({
stakeSum,
isApprovedLE:
data?.header?.businessProfileStatus?.status?.toLowerCase() === "approved",
hasMaxOwners:
(isIndividualSoleProprietorship &&
data?.businessOwners &&
data.businessOwners.length >= 1) ||
false,
legalEntityID: Number(data?.businessProfile?.id),
showTag: true,
merchantId: data?.merchantInfo?.merchantID,
isSoleProprietorship: isIndividualSoleProprietorship,
isBPLinked: data?.businessProfile?.isBPLinked,
businessType: data?.businessProfile?.businessType,
documents: data?.documents,
isMerchant: true,
businessOwnersLength: businessOwners.length,
});
const renderStatusChip = (owner: TBusinessOwner) => (
<GivePepStatusChip
ownerPepStatus={owner.pepStatusName}
manualPepStatus={owner.manualPepStatus}
pepStatusSetByUnderwriter={owner.pepStatusSetByUnderwriter}
/>
);
const handleEdit = (
event: MouseEvent<HTMLElement>,
owner: TBusinessOwner,
) => {
editOwnerHandler(event, adjustAddressType(owner) as any);
};
const getBusinessOwnerDisplayData = (owner: TBusinessOwner) => ({
...owner,
title: `${owner.firstName} ${owner.lastName}`,
subtitle: `${owner.ownership}% Ownership`,
});
Iif (isFetching) {
return <TaskLoading />;
}
Iif (!businessOwners.length) {
return <TaskEmptyState section="business-owner" />;
}
return (
<AccordionSection
items={businessOwners.map(getBusinessOwnerDisplayData)}
getFieldsList={getBusinessOwnerFields}
statusComponent={renderStatusChip}
onEdit={handleEdit}
/>
);
}
export default BusinessOwnerSection;
|