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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | 3x 87x 87x 87x 87x 87x 87x 87x 87x 87x 87x 87x 4x 4x 4x 87x 87x 174x 424x 384x 384x 384x 424x 424x 384x 384x 384x 384x 96x 288x 4x 4x 288x 174x 87x 87x 87x 87x 87x 87x 87x | import GiveText from "@shared/Text/GiveText";
import { MemberData } from "@customTypes/team.member";
import {
ColumnBaseType,
TableColumnType,
} from "componentsV2/Table/Table.types";
import { GiveMemberNameCell } from "../components/GiveMemberNameCell";
import { Box } from "@mui/material";
import { useFormatDateInTimezone } from "@utils/date.helpers";
import GiveChip from "@shared/Chip/GiveChip";
import { CodeIcon } from "@assets/icons";
import {
CheckCircleIcon,
DotsThreeIcon,
PaperPlaneTiltIcon,
PencilSimpleIcon,
TrashIcon,
UserSwitchIcon,
XCircleIcon,
} from "@phosphor-icons/react";
import { selectUser } from "@redux/slices/auth/auth";
import { useAppSelector } from "@redux/hooks";
import { ActionsComponent } from "@common/Table/components/ActionsComponent";
import { useCallback, useState } from "react";
import { ContextualMenuOptionProps } from "@shared/ContextualMenu/ContextualMenu.types";
import NiceModal from "@ebay/nice-modal-react";
import {
GIVE_EDIT_TEAM_MEMBER_MODAL,
GIVE_DELETE_TEAM_MEMBER_MODAL,
TEAM_MEMBER_PANEL_MODAL,
CHANGE_PAH_MODAL,
} from "modals/modal_names";
import { useTeamPermissions } from "features/Permissions/AccessControl/hooks";
import { useSendInvitationAction } from "@hooks/merchant-api/manage-team/useResendInvite";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { shouldBeHidden } from "@constants/constants";
import { useNavigate } from "react-router-dom";
import { checkPortals } from "@utils/routing";
import {
MANAGE_PERMISSIONS_DENY_MESSAGE,
NEW_ACTION_DENY_MESSAGE,
} from "@constants/permissions";
import { isMemberJoined } from "../helpers/memberJoinState";
const useGetTeamMembersTable = () => {
const { formatInTimezone } = useFormatDateInTimezone();
const { email } = useAppSelector(selectUser);
const navigate = useNavigate();
const {
isDeleteAllowed,
isEditAllowed,
isInviteAllowed,
isListAccessPoliciesAllowed,
isReadAllowed,
} = useTeamPermissions();
const { handleResendInvitation, checkIsInvitationSent } =
useSendInvitationAction();
const { isMobileView } = useCustomThemeV2();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [selectedRow, setSelectedRow] = useState<MemberData>();
const { isPermissionsTableEnabled, isMerchantPermissionsRebrandingEnabled } =
useGetFeatureFlagValues();
const { isAcquirerPortal, isMerchantPortal, isEnterprisePortal } =
checkPortals();
const handleOpenMenu = useCallback(
(event: React.MouseEvent<HTMLButtonElement>, row: MemberData) => {
event.stopPropagation();
setAnchorEl(event.currentTarget);
setSelectedRow(row);
},
[],
);
const closeMenu = (event?: React.MouseEvent<HTMLElement>) => {
setAnchorEl(null);
event?.stopPropagation();
};
const getColumns = (isSortable: boolean) => {
const columns: TableColumnType[] = [
{
key: "user.firstName",
sortable: isSortable ? true : false,
title: "Member",
columnType: "member" as ColumnBaseType,
columnWidth: 3 / 12,
renderColumn: (row: MemberData) => (
<GiveMemberNameCell
firstName={row.user.firstName}
email={row.user.email}
imageURL={row.user.imageURL}
lastName={row.user.lastName}
/>
),
},
{
key: "joinedAt",
sortable: isSortable ? true : false,
title: "Joined",
columnWidth: 1.8 / 12,
renderColumn: (row: MemberData) => {
const isInvite =
row.memberStatus === "pending" || row.memberStatus === "invited";
return (
<Box>
{isInvite ? (
<GiveChip
label="Invitation sent"
color="success"
variant="light"
/>
) : (
<GiveText variant="bodyS">
{row.joinedAt
? formatInTimezone(row.joinedAt, "MM/dd/yyyy")
: ""}
</GiveText>
)}
</Box>
);
},
hideColumn: isMobileView,
},
{
key: "user.occupation",
sortable: false,
title: "Title",
columnWidth: 2 / 12,
renderColumn: (row: MemberData) => {
return (
<Box>
<GiveText variant="bodyS">
{row?.user?.occupation || "-"}
</GiveText>
</Box>
);
},
hideColumn: isMobileView,
},
{
key: "roleName",
sortable: false,
title: "Role",
columnWidth: 2.5 / 12,
renderColumn: (row: MemberData) => {
const isInvite = ["pending", "invited"].includes(row.memberStatus);
return isMobileView && isInvite ? (
<Box sx={{ display: "flex", alignItems: "center" }}>
<GiveChip
label="Invitation sent"
color="success"
variant="light"
/>
</Box>
) : (
<Box
sx={{
display: "flex",
alignItems: "center",
}}
>
<GiveChip label={row.roleDisplayName} />
<Box display="flex" alignItems="center">
{row.hasCustomPermissions &&
!shouldBeHidden.HIDE_CODE_ICON_FF && (
<CodeIcon width={18} height={18} />
)}
</Box>
</Box>
);
},
},
{
key: "actions",
columnType: "assignment" as ColumnBaseType,
columnWidth: 1 / 12,
renderColumn: (row: MemberData) => {
// PAH006 bug 5: the PAH (owner) may transfer ownership from the
// three-dots menu on their OWN row in the merchant portal, so keep the
// menu for that row. Every other owner row and the current user's row
// stay menu-less as before.
const isOwnerRow = row.roleName === "owner";
const isCurrentUserRow = row.user.email === email;
const canTransferOwnership =
isMerchantPortal && isOwnerRow && isCurrentUserRow;
if ((isOwnerRow || isCurrentUserRow) && !canTransferOwnership)
return null;
return (
<ActionsComponent
title="More"
onClick={(e) => {
e.stopPropagation();
handleOpenMenu(e, row);
}}
icon={() => <DotsThreeIcon fill="regular" size={20} />}
/>
);
},
hideColumn: isMobileView,
},
];
return columns;
};
const getOptionsList = (
selectedRow?: MemberData,
): ContextualMenuOptionProps[] => {
const isOwnerOrCurrentUser =
selectedRow?.roleName === "owner" || selectedRow?.user.email === email;
const isJoined = selectedRow?.memberStatus === "joined";
const isInvited =
selectedRow?.memberStatus === "invited" ||
selectedRow?.memberStatus === "pending";
// PAH006 bug 5: only the current PAH (owner) — on their own row, in the
// merchant portal — may initiate the ownership transfer. Non-PAH roles never
// see this option. AuthZ is also enforced server-side on the reassignment
// endpoint (only the current PAH or an acquirer/provider may initiate).
const canTransferOwnership =
isMerchantPortal &&
selectedRow?.roleName === "owner" &&
selectedRow?.user.email === email;
return [
{
text: "Transfer ownership",
onClick: () => {
closeMenu();
NiceModal.show(CHANGE_PAH_MODAL, {
merchantId: selectedRow?.accID,
enableMemberSuggestions: true,
});
},
IconRight: UserSwitchIcon,
hidden: !canTransferOwnership,
},
{
text: "Edit Details",
onClick: () => {
NiceModal.show(GIVE_EDIT_TEAM_MEMBER_MODAL, {
rowData: selectedRow,
});
},
IconRight: PencilSimpleIcon,
hidden:
isOwnerOrCurrentUser ||
["pending", "invited"]?.includes(selectedRow?.memberStatus || ""),
disabled: !isEditAllowed,
tooltipTitle: NEW_ACTION_DENY_MESSAGE,
disableTooltip: isEditAllowed,
},
{
text: "Manage Permissions",
onClick: () => {
if (isPermissionsTableEnabled && isAcquirerPortal) {
navigate(
`/acquirer/settings/permissions/${selectedRow?.user.accID}`,
);
} else if (isPermissionsTableEnabled && isEnterprisePortal) {
navigate(
`/provider/settings/permissions/${selectedRow?.user.accID}`,
);
} else if (
isMerchantPortal &&
isPermissionsTableEnabled &&
isMerchantPermissionsRebrandingEnabled
) {
navigate(
`/merchant/settings/permissions/${selectedRow?.user.accID}`,
);
} else {
NiceModal.show(TEAM_MEMBER_PANEL_MODAL, {
rowData: selectedRow,
openPermissions: true,
});
}
},
IconRight: CheckCircleIcon,
disabled: !isListAccessPoliciesAllowed || !isReadAllowed,
hidden:
isOwnerOrCurrentUser ||
(!isMerchantPermissionsRebrandingEnabled &&
isMerchantPortal &&
isInvited) ||
selectedRow?.memberStatus === "invited",
tooltipTitle: MANAGE_PERMISSIONS_DENY_MESSAGE,
disableTooltip: isListAccessPoliciesAllowed && isReadAllowed,
},
{
text: "Resend invitation",
onClick: () => handleResendInvitation(selectedRow, isMobileView),
// Stays available for a member who accepted but still carries the
// generated password — they can't sign in until it's replaced. A Host
// has no password to replace, so their `joined` is the end of it.
hidden: isMemberJoined(selectedRow),
disabled: checkIsInvitationSent(selectedRow) || !isInviteAllowed,
IconRight: PaperPlaneTiltIcon,
},
{
text: isJoined ? "Remove Member" : "Revoke invitation",
type: isJoined ? "destructive" : "default",
onClick: () => {
const url = `/accounts/${selectedRow?.accID}/members/${selectedRow?.user.accID}`;
NiceModal.show(GIVE_DELETE_TEAM_MEMBER_MODAL, {
variant: "team_member",
itemName:
selectedRow?.user.firstName && selectedRow?.user.lastName
? `${selectedRow?.user.firstName} ${selectedRow?.user.lastName}`
: selectedRow?.user.email,
url: url,
});
},
IconRight: isJoined ? TrashIcon : XCircleIcon,
hidden: isOwnerOrCurrentUser,
disabled: !isDeleteAllowed,
tooltipTitle: MANAGE_PERMISSIONS_DENY_MESSAGE,
disableTooltip: isDeleteAllowed,
},
];
};
return {
getColumns,
anchorEl,
selectedRow,
getOptionsList,
closeMenu,
};
};
export default useGetTeamMembersTable;
|