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 | 3x 227x 227x 227x 227x 227x 227x 227x 227x 227x 227x 128x 99x 99x 891x 792x 99x | import NiceModal from "@ebay/nice-modal-react";
import { CREATE_BUSINESS_PROFILE_MODAL } from "modals/modal_names";
import { useFormContext } from "react-hook-form";
import {
IParsedData,
TBusinessOwner,
} from "@components/Merchants/MerchantPreview/data.types";
import { computeAgeOfBusiness } from "@components/Merchants/MerchantPreview/helpers/parsers";
import { businessProfileDefaultValues } from "@validation/merchant";
import { TCreateBusinessProfile } from "components/Merchants/CreateMerchantPanel/types";
import { FormType } from "components/Merchants/CreateMerchantPanel/modals/CreateBusinessProfileModal";
import { BusinessProfileSectionContent } from "features/Merchants/MerchantSidePanel/GiveMerchantFile/businessProfile/BusinessProfileSectionContent";
import useGetSectionItems from "features/Merchants/MerchantSidePanel/GiveMerchantFile/hooks/useGetSectionItems";
import { Box } from "@mui/material";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
type Props = {
isProvider?: boolean;
};
const LocalBP = ({ isProvider }: Props) => {
const { isOnboardingLinkBPEnabled } = useGetFeatureFlagValues();
const { watch, setValue } = useFormContext();
const values = watch();
const { businessProfile } = values || {};
const showLinkingProgress =
isOnboardingLinkBPEnabled &&
businessProfile?.isLinkBusinessProfile &&
businessProfile?.isOutOfMerchantTree;
const { age } = computeAgeOfBusiness(businessProfile?.businessOpenedAt);
const handleCloseBusinessProfile = (data: {
businessProfile: TCreateBusinessProfile;
businessOwners?: TBusinessOwner[];
}) => {
setValue("businessProfile", {
...data.businessProfile,
linkedOwnerId: data.businessOwners?.[0]?.id,
});
if (data.businessProfile.linkedBusinessProfile) {
setValue("businessOwners", data.businessOwners || []);
}
};
const editHandler = () => {
let customData = businessProfile;
if (customData.isLinkBusinessProfile && customData.linkedBusinessProfile) {
customData = {
...businessProfileDefaultValues,
isLinkBusinessProfile: true,
linkedBusinessProfile: customData.linkedBusinessProfile,
isOutOfMerchantTree: customData?.isOutOfMerchantTree,
};
} else {
customData = {
...customData,
isLinkBusinessProfile: false,
linkedBusinessProfile: undefined,
};
}
NiceModal.show(CREATE_BUSINESS_PROFILE_MODAL, {
onClose: handleCloseBusinessProfile,
data: customData,
isEdit: true,
isLegalEntityApproved: false,
formType: isProvider
? FormType.CREATE_ENTERPRISE
: FormType.CREATE_MERCHANT,
});
};
const { businessProfileItems, formattedTaxID } = useGetSectionItems({
...values,
businessProfile: {
...values.businessProfile,
ageOfBusiness: age,
dba: businessProfile.DBA,
},
businessAddress: businessProfile?.address,
} as IParsedData);
if (!values.businessProfile?.taxID && !values.businessProfile?.ssn)
return null;
const items = showLinkingProgress ? [] : businessProfileItems;
const hasEmptyValue = items
.filter((item) => !item.title.includes("Optional"))
.some((item) => item.value === undefined || item.value === "");
return (
<Box data-testid="local-bp-container" marginX="20px">
<BusinessProfileSectionContent
actions={{ handleEdit: editHandler }}
items={items}
linkedBPTaxId={showLinkingProgress ? formattedTaxID : ""}
status={hasEmptyValue ? "pending" : undefined}
showLinkedApprovalButtons={false}
email={businessProfile?.pendingLegalEntityEmail}
/>
</Box>
);
};
export default LocalBP;
|