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 | import { Box, Stack } from "@mui/material";
import NiceModal, { useModal } from "@ebay/nice-modal-react";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import { GiveNameInput } from "@common/BusinessProfileInputs";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import HFGiveSelect from "@shared/HFInputs/HFGiveSelect/HFGiveSelect";
import GiveText from "@shared/Text/GiveText";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import GiveButton from "@shared/Button/GiveButton";
import * as Yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { useAppSelector } from "@redux/hooks";
import { selectUser } from "@redux/slices/auth/auth";
import { EMAIL_REGEX } from "@validation/regex";
import { OFAC_MATCH_MESSAGE } from "@constants/permissions";
import { MemberData } from "@customTypes/team.member";
import { TMemberInfo } from "features/Permissions/ModalV2/types";
import { FormProvider, useForm } from "react-hook-form";
import { useEditTeamMember } from "../hooks/useEditTeamMember";
import { useRoles } from "@services/api/accounts";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useAppTheme } from "@theme/v2/Provider";
const schema = Yup.object().shape({
firstName: Yup.string(),
lastName: Yup.string(),
email: Yup.string().matches(EMAIL_REGEX, "Invalid email address"),
occupation: Yup.string().nullable(),
employer: Yup.string().nullable(),
});
interface EditModalPops {
rowData: MemberData;
memberInfo: TMemberInfo;
setMemberInfo: (data: any) => void;
}
const EditTeamMemberModal = NiceModal.create(
({ rowData, memberInfo, setMemberInfo }: EditModalPops) => {
const modal = useModal();
const { palette } = useAppTheme();
const { isMobileView } = useCustomThemeV2();
const { data: rolesData } = useRoles();
const { accID } = rowData?.user || {};
const { firstName, lastName, email, occupation, employer, roleName } =
memberInfo || {};
const { user } = rowData;
const { email: currentUserEmail } = useAppSelector(selectUser);
const isCurrentUser = currentUserEmail === email;
const isOwner = rowData.roleName === "owner";
const isOFACMatch = rowData?.lastOFACCheckStatusName === "confirmed_match";
const { handleEdit, isLoading } = useEditTeamMember({
accID,
roleOnly: isOFACMatch,
handleClose: (data) => {
modal.remove();
setMemberInfo(data);
},
});
const rolesOptions =
rolesData?.data
?.filter((role) => isOwner || role?.value !== "owner")
?.sort((a, b) => a?.label.localeCompare(b?.label)) || [];
const methods = useForm<TMemberInfo>({
resolver: yupResolver(schema),
defaultValues: {
firstName: firstName || user.firstName,
lastName: lastName || user.lastName,
roleName: roleName || rowData.roleName || null,
email: email || user.email,
occupation: occupation || user.occupation,
employer: employer || user.employer,
},
});
const {
formState: { isDirty },
} = methods;
const onSubmit = (data: TMemberInfo) => {
handleEdit(data);
};
const handleCancel = () => {
modal.remove();
};
return (
<GiveBaseModal
open={modal.visible}
title={`Edit Team Member`}
width="648px"
height="fit-content"
onClose={modal.remove}
buttons={
<Stack direction="row" gap="12px">
<GiveButton
variant="ghost"
size="large"
label="Cancel"
onClick={handleCancel}
/>
<GiveButton
size="large"
variant="filled"
label="Save"
color="primary"
onClick={methods.handleSubmit(onSubmit)}
disabled={isLoading || !isDirty}
/>
</Stack>
}
>
{isOFACMatch && (
<GiveText
color={"error1"}
variant="bodyS"
sx={{
padding: "2px 16px",
mb: "20px",
borderRadius: "16px",
background: palette.gradient["citrus-peel"]?.highlight,
width: "fit-content",
}}
>
OFAC Confirmed match
</GiveText>
)}
<FormProvider {...methods}>
<Stack gap={3}>
<GiveMotionWrapper delay={250}>
<Box
display="flex"
flexDirection={isMobileView ? "column" : "row"}
gap={3}
>
<GiveTooltip
width="compact"
alignment="bottom"
title={OFAC_MATCH_MESSAGE}
color="default"
disableHoverListener={!isOFACMatch}
>
<GiveNameInput
name="firstName"
label="First Name"
disabled={isOFACMatch}
/>
</GiveTooltip>
<GiveTooltip
width="compact"
alignment="bottom"
title={OFAC_MATCH_MESSAGE}
color="default"
disableHoverListener={!isOFACMatch}
>
<GiveNameInput
name="lastName"
label="Last Name"
disabled={isOFACMatch}
/>
</GiveTooltip>
</Box>
</GiveMotionWrapper>
<GiveMotionWrapper delay={300}>
<Box
display="flex"
flexDirection={isMobileView ? "column" : "row"}
gap={3}
>
<HFGiveSelect
name="roleName"
label="Role"
placeholder="Role"
options={rolesOptions}
disabled={isOwner || isCurrentUser}
/>
<HFGiveInput name="email" label="Email" fullWidth disabled />
</Box>
</GiveMotionWrapper>
<GiveMotionWrapper delay={350}>
<Box
display="flex"
flexDirection={isMobileView ? "column" : "row"}
gap={3}
>
<GiveTooltip
width="compact"
alignment="bottom"
title={OFAC_MATCH_MESSAGE}
color="default"
disableHoverListener={!isOFACMatch}
>
<HFGiveInput
name="occupation"
label="Job Title"
fullWidth
disabled={isOFACMatch}
/>
</GiveTooltip>
<GiveTooltip
width="compact"
alignment="bottom"
title={OFAC_MATCH_MESSAGE}
color="default"
disableHoverListener={!isOFACMatch}
>
<HFGiveInput
name="employer"
label="Employer"
fullWidth
disabled={isOFACMatch}
/>
</GiveTooltip>
</Box>
</GiveMotionWrapper>
</Stack>
</FormProvider>
</GiveBaseModal>
);
},
);
export default EditTeamMemberModal;
|