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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | 3x 3x 17x 15x 15x 15x 15x 15x 15x 15x 15x 45x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 105x 93x | import NiceModal, { useModal } from "@ebay/nice-modal-react";
import { FormProvider } from "react-hook-form";
import { Box, Grid, Stack } from "@mui/material";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import GiveButton from "@shared/Button/GiveButton";
import GiveText from "@shared/Text/GiveText";
import { IParsedData, TPrimaryAccountHolder } from "../data.types";
import { NonResidentInputs } from "@common/NonResidentInput/NonResidentInputs";
import { GiveNameInput } from "@common/BusinessProfileInputs";
import {
MAXIMUM_REQUIRED_AGE,
MINIMUM_REQUIRED_AGE,
OFAC_STATUS,
} from "@constants/constants";
import { useAccessControl } from "features/Permissions/AccessControl";
import RESOURCE_BASE, {
Edit_DENY_BY_OFAC_V2,
EDIT_DENY_MESSAGE,
OPERATIONS,
} from "@constants/permissions";
import { checkPortals } from "@utils/routing";
import { HFGiveTelephone } from "@shared/HFInputs/HFGiveTelephone/HFGiveTelephone";
import { ControlledDatePicker } from "@sections/PayBuilder/Forms/DateAndLocation/components/ControlledDatePicker";
import moment from "moment";
import { PLATFORM_TIMEZONE } from "@utils/timezones";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { CustomToolTip } from "componentsV2/Table/CustomTooltip";
import GivePepStatusChip from "@features/Merchants/MerchantSidePanel/GiveMerchantFile/businessOwners/GivePepStatusChip";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveDivider from "@shared/GiveDivider/GiveDivider";
import IdentityVerification from "features/Merchants/MerchantSidePanel/components/PrimaryAccountHolderSection/IdentityVerification";
import { useEnterprisePermissions } from "@components/AcquirerEnterprises/CreateEnterprise/hooks/useEnterprisePermissions";
import { useEditPAH } from "../hooks/useEditPAH";
// AC7.2: the PAH email is read-only on the merchant record; email changes happen
// only through the secure "Change Primary Account Holder" reassignment flow.
export const PAH_EMAIL_CHANGE_NOTE =
'To change the primary account holder’s email, use “Change Primary Account Holder”.';
type Props = {
id: number;
data: TPrimaryAccountHolder;
ownerAccId: number;
merchantData: IParsedData;
// Providers (enterprise) stay on the old owner-change flow during the
// merchants-first rollout (GB-21482); merchants (submerchants) get the new
// approval-gated flow. All three openers pass this through.
isEnterprise?: boolean;
};
const GiveEditPAHModal = NiceModal.create((props: Props) => {
const { id, data, merchantData, isEnterprise } = props;
const { isMerchantOnboardingModalEnabled } = useGetFeatureFlagValues();
const modal = useModal();
const open = modal.visible;
const { isAcquirerEnterprises, isEnterprisePortal } = checkPortals();
const { merchant_underwriting } = useEnterprisePermissions();
const { isMobileView } = useCustomThemeV2();
const { methods, handleCancel, onSubmit, handleLocalDoc, isLoading } =
useEditPAH(props);
const getUTCDates = () => {
return {
maxDate: moment().subtract(MINIMUM_REQUIRED_AGE, "years").utc().toDate(),
minDate: moment().subtract(MAXIMUM_REQUIRED_AGE, "years").utc().toDate(),
};
};
const isOFACConfirmedMatch =
data?.ofac?.lastCheckStatusName === OFAC_STATUS.CONFIRMED_MATCH;
const isOFACMatch =
isOFACConfirmedMatch ||
data?.ofac?.lastCheckStatusName === OFAC_STATUS.POSSIBLE_MATCH;
const isEditAllowed = useAccessControl({
resource: isAcquirerEnterprises
? RESOURCE_BASE.ENTERPRISE
: RESOURCE_BASE.MERCHANT,
operation: OPERATIONS.UPDATE,
});
const disabledField = isOFACMatch || !isEditAllowed;
const tooltipMessage = !isEditAllowed
? EDIT_DENY_MESSAGE
: Edit_DENY_BY_OFAC_V2;
const isHiddenIdentityVerification =
!merchant_underwriting && isEnterprisePortal;
const {
formState: { isDirty, isValid },
watch,
} = methods;
const values = watch();
const isResidentInUs = watch("isUSResident");
const isUSCitizen = watch("isUSCitizen");
const inputList = [
{
input: (
<Stack spacing={0.5} width="100%" mb={1}>
<Stack
direction={isMobileView ? "column" : "row"}
spacing={isMobileView ? 0.5 : 1.5}
sx={{ "& div": { width: "fit-content" } }}
>
<GiveText variant="bodyS">
Office of Foreign Assets Control Check:
</GiveText>
<GivePepStatusChip ownerPepStatus="confirmed_match" />
</Stack>
<GiveText variant="bodyXS" color="secondary">
{data?.ofac?.lastCheckAt
? moment
.unix(data?.ofac?.lastCheckAt)
.tz(PLATFORM_TIMEZONE)
.format("MMMM D, YYYY, hh:mm:ss A z")
: ""}
</GiveText>
</Stack>
),
hidden: !isOFACConfirmedMatch,
},
{
input: (
<GiveNameInput
name="firstName"
label="First Name"
disabled={disabledField}
/>
),
hasTooltip: true,
},
{
input: (
<GiveNameInput
name="lastName"
label="Last Name"
disabled={disabledField}
/>
),
hasTooltip: true,
},
{
// AC001/AC007: for MERCHANTS the PAH email is read-only here — email
// changes are routed through the new "Change Primary Account Holder" flow.
// Providers (enterprise) stay on the OLD flow (GB-21482): no Change-PAH
// option exists for them, so the email stays editable (subject to the same
// OFAC/permission gating as the other fields) and the note is hidden.
input: (
<Stack spacing={0.5} width="100%">
<HFGiveInput
name="email"
label="Email"
fullWidth
disabled={isEnterprise ? disabledField : true}
/>
{!isEnterprise && (
<GiveText variant="bodyXS" color="secondary">
{PAH_EMAIL_CHANGE_NOTE}
</GiveText>
)}
</Stack>
),
hasTooltip: true,
},
{
input: (
<HFGiveTelephone
name="phoneNumber"
label="Mobile Phone"
fullWidth
disabled={disabledField}
/>
),
hasTooltip: true,
},
{
input: (
<ControlledDatePicker
name="dob"
label="Date of Birth"
disableFuture
minDate={getUTCDates().minDate}
maxDate={getUTCDates().maxDate}
defaultPickerValue={getUTCDates().maxDate}
disabled={disabledField}
useUTCMoment
/>
),
hasTooltip: true,
},
{
input: (
<Box width="100%">
<NonResidentInputs
isBusinessOwner
isRebranded
labels={{
USResidencyLabel: "I am a resident of the United States",
residenceDifferentLabel: "I am a United States citizen",
hideCitizenshipSelector: !isResidentInUs ? isUSCitizen : true,
hideResidencySelector: isResidentInUs,
isResidentInUsFieldName: "isUSResident",
isUSCitizenFieldName: "isUSCitizen",
}}
isMerchantOnboardingModalEnabled={isMerchantOnboardingModalEnabled}
hasTooltip
show={disabledField}
inputsDisabled={disabledField}
tooltipMessage={tooltipMessage}
excludeCountries={[]}
/>
</Box>
),
},
];
return (
<GiveBaseModal
open={open}
title="Edit Primary Account Holder"
width="720px"
onClose={handleCancel}
buttons={
<Stack gap="12px" flexDirection="row">
<GiveButton
onClick={handleCancel}
label="Cancel"
variant="ghost"
size="large"
/>
<GiveButton
label="Save"
variant="filled"
size="large"
disabled={!isDirty || isLoading || !isValid}
type="submit"
form="edit-primary-account-holder"
sx={{ border: "none" }}
/>
</Stack>
}
closeIconProps={{
bgColor: "solidWhite",
}}
>
<FormProvider {...methods}>
<Box
component="form"
id="edit-primary-account-holder"
onSubmit={methods.handleSubmit(onSubmit)}
marginTop="8px"
>
<Grid container spacing={3}>
{inputList
.filter(({ hidden }) => !hidden)
.map(
(
{
input,
tooltipMessage: customTooltipMessage,
hasTooltip,
showTooltip,
},
index,
) => (
<Grid key={index} item xs={12}>
<CustomToolTip
showToolTip={
!!hasTooltip &&
(isOFACMatch || !isEditAllowed || !!showTooltip)
}
message={
showTooltip ? customTooltipMessage : tooltipMessage
}
placement="bottom"
>
{input}
</CustomToolTip>
</Grid>
),
)}
</Grid>
{!isHiddenIdentityVerification && (
<>
<GiveDivider sx={{ mt: 4 }} />
<GiveText color="secondary" paddingBottom="8px" variant="bodyS">
Identity Verification
</GiveText>
<IdentityVerification
data={merchantData}
documents={merchantData?.documents}
merchantId={id}
isEnterprise={isAcquirerEnterprises}
localDocs={{ id: values.ID, selfie: values.selfie }}
localRemoved={{
id: values.removedIDFileId,
selfie: values.removedSelfieFileId,
}}
setLocalDocs={handleLocalDoc}
/>
</>
)}
</Box>
</FormProvider>
</GiveBaseModal>
);
});
export default GiveEditPAHModal;
|