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 | 6x 6x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 93x 56x 56x 56x 56x 21x 21x 21x 56x 112x | import { useEffect, useState } from "react";
import { Box } from "@mui/material";
import { WarningIcon } from "@phosphor-icons/react";
import GiveMotionWrapper from "@shared/Motion/GiveMotionWrapper";
import GiveAlert from "@shared/GiveAlert/GiveAlert";
import { MemberData } from "@customTypes/team.member";
import { addSizeToImage } from "@components/UploadAvatar/UploadAvatar";
import { useAppSelector } from "@redux/hooks";
import {
PanelContainerV2,
TeamInfoContainerV2,
} from "./TeamPanelBodyV2.styles";
import { selectUser } from "@redux/slices/auth/auth";
import { useTeamPermissions } from "features/Permissions/AccessControl/hooks";
import { GiveLoadingSkeleton } from "./components";
import JoinedContentHeader from "./JoinedContentHeader";
import InvitedContentHeader from "./InvitedContentHeader";
import MemberDetails from "./MemberDetails";
import { checkPortals } from "@utils/routing";
import { useGetCurrentMerchantId } from "@hooks/common";
import { usePahReassignmentStatus } from "@hooks/common/usePahReassignmentStatus";
import { getPahPanelState } from "@features/Settings/Team/helpers/pahPanelState";
import useTeamPahTransferActions from "@features/Settings/Team/hooks/useTeamPahTransferActions";
import { isMemberJoined } from "@features/Settings/Team/helpers/memberJoinState";
const PAH_REASSIGNMENT_BANNER_TEXT =
"The Primary Account Holder has been changed. The current Primary Account Holder will remain active until the new one accepts the invitation.";
type Props = {
rowData: MemberData;
handleClose?: () => void;
showPermissions: boolean;
customCallback?: () => void;
};
const TeamPanelBodyV2 = ({ rowData, handleClose, customCallback }: Props) => {
const isLoading = false;
const {
imageURL,
email,
firstName,
lastName,
occupation,
employer,
accID: memberId,
} = rowData?.user || {};
const [memberInfo, setMemberInfo] = useState({
firstName,
lastName,
email,
roleName: rowData?.roleName || null,
occupation,
employer,
});
const image = addSizeToImage(imageURL, "medium");
const { email: currentUserEmail } = useAppSelector(selectUser);
const isCurrentUser = currentUserEmail === email;
const isOwner = rowData?.roleName === "owner" || false;
const isJoined = rowData.memberStatus === "joined";
// Not the same test as `isJoined`: a member who accepted but still carries the
// generated password can't sign in yet, so the panel keeps them on the invited
// header to leave the resend action in reach. See memberJoinState for why a
// Host is exempt from the password half of that.
const hasFinishedJoining = isMemberJoined(rowData);
// The PAH transfer flow lives on the current PAH's own panel in the
// merchant portal only. We gate the reassignment query on that so other
// members' panels never fire it.
const { isMerchantPortal } = checkPortals();
const { merchantId } = useGetCurrentMerchantId();
const isOwnPahCandidate = isOwner && isCurrentUser && isMerchantPortal;
const { reassignment } = usePahReassignmentStatus(isOwnPahCandidate);
const pahPanelState = getPahPanelState({
isOwner,
isCurrentUser,
isMerchantPortal,
reassignmentState: reassignment?.state,
});
const { onTransferOwnership, onCancelChange } = useTeamPahTransferActions(
merchantId,
reassignment,
);
const hasNotGetPermissionsListPermission = useAppSelector(
(state) => state.app.permissions?.["get-team-members-all-permissions"],
);
const {
isEditAllowed,
isDeleteAllowed,
isListAccessPoliciesAllowed,
isDeleteOwnerAllowed,
isInviteAllowed,
isReadAllowed,
} = useTeamPermissions();
const commonProps = {
rowData,
imageUrl: image,
isCurrentUser,
isDeleteAllowed,
isDeleteOwnerAllowed,
isEditAllowed,
};
const teamMemberDetails = [
{
section: hasFinishedJoining ? (
<JoinedContentHeader
{...commonProps}
isOwner={isOwner}
memberInfo={memberInfo}
setMemberInfo={setMemberInfo}
/>
) : (
<InvitedContentHeader
{...commonProps}
isInviteAllowed={isInviteAllowed}
/>
),
delay: 250,
},
{
section: (
<MemberDetails
isJoined={isJoined}
memberInfo={memberInfo}
joinedAt={rowData?.joinedAt}
memberId={memberId}
roleDisplayName={rowData?.roleDisplayName}
isListPermissionsAllowed={
!isCurrentUser &&
!isOwner &&
isListAccessPoliciesAllowed &&
isReadAllowed &&
!hasNotGetPermissionsListPermission
}
customCallback={customCallback}
handleClose={handleClose}
showTransferOwnership={pahPanelState.showTransferButton}
showCancelChange={pahPanelState.showCancelButton}
showNewRoleRow={pahPanelState.showNewRoleRow}
onTransferOwnership={onTransferOwnership}
onCancelChange={onCancelChange}
/>
),
delay: 300,
},
];
useEffect(() => {
Eif (rowData?.user) {
const { email, firstName, lastName, occupation, employer } = rowData.user;
setMemberInfo({
firstName,
lastName,
email,
roleName: rowData?.roleName || null,
occupation,
employer,
});
}
}, [rowData]);
return (
<PanelContainerV2 data-testid="team-pah-panel">
{pahPanelState.showReassignmentBanner && (
<Box mb={2}>
<GiveAlert
type="warning"
variant="alert"
Icon={<WarningIcon />}
description={PAH_REASSIGNMENT_BANNER_TEXT}
dataTestId="team-pah-pending-reassignment"
/>
</Box>
)}
<TeamInfoContainerV2>
{isLoading ? (
<GiveLoadingSkeleton />
) : (
teamMemberDetails.map(({ section, delay }, index) => (
<GiveMotionWrapper key={index} delay={delay}>
{section}
</GiveMotionWrapper>
))
)}
</TeamInfoContainerV2>
</PanelContainerV2>
);
};
export default TeamPanelBodyV2;
|