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 | 1x 11x 11x 11x 11x 11x 1x 1x 1x 11x 11x 1x 1x 1x 11x 1x | import { useCallback, useMemo, useState } from "react";
import { CaretDownIcon, CaretUpIcon } from "@phosphor-icons/react";
import GiveButton from "@shared/Button/GiveButton";
import ContextualMenu from "@shared/ContextualMenu/ContextualMenu";
import { ContextualMenuOptionProps } from "@shared/ContextualMenu/ContextualMenu.types";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { OFACCheckType } from "@components/Merchants/MerchantPreview/OFAC/hooks/useOFAC";
import { TOFACEndpointBuilder } from "@components/Merchants/MerchantPreview/OFAC/hooks/useUpdateOFACCheck";
import { TOFACStatusImproved } from "./types";
import { OFACTabType } from "@components/Merchants/MerchantPreview/OFAC/hooks/types";
import useGiveOFACConfirmMatchPopup from "@hooks/useGiveOFACConfirmMatchPopup";
type GiveOFACChangeStatusProps = {
ofacStatus: TOFACStatusImproved;
merchantId: number;
legalEntityId: number;
currentCheck: OFACCheckType;
handleSubmit: (payload: TOFACEndpointBuilder) => void;
activeTab: OFACTabType;
isEnterprisePanel: boolean;
isPEP?: boolean;
};
type OFACApiStatus = "possible_match" | "manually_cleared" | "confirmed_match";
const GiveChangeOFACStatus = ({
ofacStatus,
merchantId,
legalEntityId,
currentCheck,
handleSubmit,
activeTab,
isEnterprisePanel,
isPEP,
}: GiveOFACChangeStatusProps) => {
const { showOFACConfirmMatchPopup } = useGiveOFACConfirmMatchPopup();
const { isMobileView } = useCustomThemeV2();
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const handleClose = () => setAnchorEl(null);
const submitStatus = useCallback(
(status: OFACApiStatus) => {
Iif (!currentCheck?.ID) {
// This should *never* happen — fail loudly
throw new Error("OFAC check ID is missing");
}
// for ofac checks we dont pass legal entityId, to call the correct endpoint
handleSubmit({
merchantId,
ofacId: currentCheck.ID,
data: { status },
});
handleClose();
},
[currentCheck?.ID, merchantId, legalEntityId, handleSubmit],
);
const options: ContextualMenuOptionProps[] = useMemo(
() => [
{
text: "Possible match",
hidden:
isPEP ||
[
"Possible match",
"Confirmed match",
"Manually cleared",
"Clear",
].includes(ofacStatus),
onClick: () => submitStatus("possible_match"),
},
{
text: "Change to Clear Match",
hidden: ["Manually cleared", "Clear"].includes(ofacStatus),
onClick: () => submitStatus("manually_cleared"),
},
{
text: "Change to Confirmed Match",
hidden: ofacStatus === "Confirmed match",
onClick: () => {
showOFACConfirmMatchPopup({
isEnterprisePanel,
activeTab,
onConfirm: () => submitStatus("confirmed_match"),
});
handleClose();
},
},
],
[
ofacStatus,
submitStatus,
showOFACConfirmMatchPopup,
isEnterprisePanel,
activeTab,
isPEP,
],
);
return (
<>
<GiveButton
variant="filled"
color="light"
size="large"
label="Change status"
onClick={(e) => setAnchorEl(e.currentTarget)}
endIcon={
anchorEl ? <CaretUpIcon size={16} /> : <CaretDownIcon size={16} />
}
data-testid="OFAC-Details-Menu"
/>
<ContextualMenu
anchorEl={anchorEl}
handleClose={handleClose}
color={isMobileView ? "secondary" : "tertiary"}
texture={isMobileView ? "solid" : "blurred"}
options={options}
anchorOrigin={{ vertical: -18, horizontal: "right" }}
transformOrigin={{ vertical: "bottom", horizontal: "right" }}
/>
</>
);
};
export default GiveChangeOFACStatus;
|