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 | 3x 66x 66x 66x 66x 66x 66x 66x 198x 66x 66x 198x 66x 66x 66x 66x 2x 3x 6x 6x | import { Dispatch, SetStateAction, useState } from "react";
import { Stack } from "@mui/material";
import GiveTabs from "@shared/Tabs/GiveTabs";
import { GiveTabItem } from "@shared/Tabs/GiveTab.types";
import { useAppTheme } from "@theme/v2/Provider";
import GiveBusinessOwnersNavigation from "./GiveBusinessOwnersNavigation";
import {
MATCHES,
OFACTabType,
TabStatuses,
TabConfig,
} from "@components/Merchants/MerchantPreview/OFAC/hooks/types";
import { DotComponent } from "@shared/atoms";
import { Theme, useMediaQuery } from "@mui/material";
interface GiveOFACTabsProps {
activeTab: OFACTabType;
setActiveTab: (tab: OFACTabType) => void;
hasBusinessProfile?: boolean;
hasPAH?: boolean;
hasPAHData?: boolean;
hasBusinessOwner?: boolean;
tabStatuses?: TabStatuses;
businessOwnersCount?: number;
// Optional external state management for business owner navigation
currentBusinessOwnerIndex?: number;
setCurrentBusinessOwnerIndex?: Dispatch<SetStateAction<number>>;
totalBusinessOwners?: number;
}
const GiveOFACTabs = ({
activeTab,
setActiveTab,
hasBusinessProfile,
hasPAH,
hasPAHData,
hasBusinessOwner,
tabStatuses,
businessOwnersCount,
currentBusinessOwnerIndex: externalIndex,
setCurrentBusinessOwnerIndex: externalSetIndex,
totalBusinessOwners,
}: GiveOFACTabsProps) => {
const isSmallView = useMediaQuery((theme: Theme) =>
theme.breakpoints.up("sm"),
);
const [internalIndex, setInternalIndex] = useState(0);
// Use external state if provided, otherwise use internal state
const currentBusinessOwnerIndex = externalIndex ?? internalIndex;
const setCurrentBusinessOwnerIndex = externalSetIndex ?? setInternalIndex;
const totalCount = totalBusinessOwners ?? businessOwnersCount ?? 0;
const hasMatch = (tab: OFACTabType) =>
MATCHES.includes(tabStatuses?.[tab] ?? "clear");
const tabConfigs: TabConfig[] = [
{
key: OFACTabType.BUSINESS_PROFILE,
isEnabled: !!hasBusinessProfile,
info: "Please add Business Profile to enable the OFAC check",
},
{
key: OFACTabType.PRIMARY_ACCOUNT_HOLDER,
isEnabled: !!hasPAH && !!hasPAHData,
info: hasPAH
? "Please fill the First and Last name of Primary Account Holder"
: "Please add Primary Account Holder to enable the OFAC check",
},
{
key: OFACTabType.BUSINESS_OWNER,
label: "Business Owners",
isEnabled: !!hasBusinessOwner,
info: "Please add Business Owner to enable the OFAC check",
},
];
const tabs: GiveTabItem[] = tabConfigs.map(
({ key, label, isEnabled, info }) => ({
label: label || key,
value: key,
disabled: !isEnabled,
endItem: hasMatch(key) ? <MatchDot /> : undefined,
displayInfoOnHover: !isEnabled,
allowHoverWhenDisabled: !isEnabled,
info: !isEnabled ? info : undefined,
}),
);
const handlePrevBusinessOwner = () => {
setCurrentBusinessOwnerIndex((prev) => Math.max(0, prev - 1));
};
const handleNextBusinessOwner = () => {
setCurrentBusinessOwnerIndex((prev) => Math.min(totalCount - 1, prev + 1));
};
const showNavigation =
activeTab === OFACTabType.BUSINESS_OWNER && totalCount > 1;
return (
<Stack spacing={2}>
<GiveTabs
type="line"
variant="underline"
items={tabs}
selected={activeTab}
onClick={(value) => setActiveTab(value as OFACTabType)}
containerSx={
!isSmallView
? {
overflowX: "auto",
whiteSpace: "nowrap",
/* Hide scrollbar */
"&::-webkit-scrollbar": {
display: "none",
},
msOverflowStyle: "none",
scrollbarWidth: "none",
}
: undefined
}
/>
{showNavigation && (
<GiveBusinessOwnersNavigation
currentIndex={currentBusinessOwnerIndex}
totalCount={totalCount}
onPrevious={handlePrevBusinessOwner}
onNext={handleNextBusinessOwner}
testIdPrefix="ofac-bo-nav"
/>
)}
</Stack>
);
};
export default GiveOFACTabs;
const MatchDot = () => {
const { palette } = useAppTheme();
return <DotComponent bgColor={palette.primitive?.warning[50]} size={8} />;
};
|