All files / src/features/Permissions/ModalV2/components MemberDetails.tsx

82.14% Statements 23/28
77.41% Branches 24/31
100% Functions 4/4
81.48% Lines 22/27

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                                  6x   6x                                           6x                             69x   69x 69x 69x 69x 69x 154x               69x 69x       69x   69x 1x   1x     1x     1x 1x 1x       69x                                                                                                                                                                                                                                                                                                   69x            
import { Box, Grid } from "@mui/material";
import { styled } from "@theme/v2/Provider";
import GiveText from "@shared/Text/GiveText";
import GiveTruncateText from "@shared/Text/GiveTruncateText";
import GiveButton from "@shared/Button/GiveButton";
import { useAppTheme } from "@theme/v2/Provider";
import { useRoles } from "@services/api/accounts";
import { TMemberInfo } from "../types";
import { useNavigate } from "react-router-dom";
import { checkPortals } from "@utils/routing";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import moment from "moment";
import { PLATFORM_TIMEZONE } from "@utils/timezones";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { InfoIcon } from "@phosphor-icons/react";
import { MANAGE_PERMISSIONS_DENY_MESSAGE } from "@constants/permissions";
 
const NEW_PAH_ROLE_LABEL = "Administrator";
const NEW_ROLE_TOOLTIP =
  "After the new PAH accepts the invitation, the previous PAH's role will automatically be updated to Administrator.";
 
interface MemberDetailsProps {
  memberInfo: TMemberInfo;
  joinedAt: number;
  memberId: number;
  /**
   * The member's own role label, as served on the member record. Used when the
   * role is absent from the assignable-roles list — see `roleLabel` below.
   */
  roleDisplayName?: string;
  isListPermissionsAllowed: boolean;
  handleClose?: () => void;
  isJoined?: boolean;
  customCallback?: () => void;
  // GB-21471: Primary Account Holder transfer flow (own PAH panel only).
  showTransferOwnership?: boolean;
  showCancelChange?: boolean;
  showNewRoleRow?: boolean;
  onTransferOwnership?: () => void;
  onCancelChange?: () => void;
}
const MemberDetails = ({
  memberId,
  memberInfo,
  joinedAt,
  roleDisplayName,
  isListPermissionsAllowed,
  handleClose,
  isJoined,
  customCallback,
  showTransferOwnership,
  showCancelChange,
  showNewRoleRow,
  onTransferOwnership,
  onCancelChange,
}: MemberDetailsProps) => {
  const theme = useAppTheme();
  const { isAcquirerPortal, isMerchantPortal, isEnterprisePortal } =
    checkPortals();
  const navigate = useNavigate();
  const { email, occupation, employer } = memberInfo || {};
  const { data: rolesData } = useRoles();
  const role = rolesData?.data.find(
    (item) => item.value === memberInfo.roleName,
  );
  // `/member-roles` lists the roles a member can be *assigned*, which is not
  // every role a member can hold: the mobile-only Host (`operator`) role is
  // excluded there on purpose, so the lookup comes back empty and the row
  // rendered blank. Prefer the picker's label — it reflects a role
  // change made in this panel before the member list refetches — and fall back
  // to the label served on the member record itself.
  const roleLabel = role?.label || roleDisplayName || null;
  const formattedJoinedAt = joinedAt
    ? moment.unix(joinedAt).tz(PLATFORM_TIMEZONE).format("MM/DD/YYYY")
    : null;
 
  const { isMerchantPermissionsRebrandingEnabled } = useGetFeatureFlagValues();
 
  const onClickManagePermissions = () => {
    Iif (customCallback) {
      customCallback();
    } else Iif (isAcquirerPortal) {
      navigate(`/acquirer/settings/permissions/${memberId}`);
      handleClose?.();
    } else Iif (isEnterprisePortal) {
      navigate(`/provider/settings/permissions/${memberId}`);
      handleClose?.();
    } else Eif (isMerchantPortal && isMerchantPermissionsRebrandingEnabled) {
      navigate(`/merchant/settings/permissions/${memberId}`);
      handleClose?.();
    }
  };
 
  return (
    <Box>
      <GiveText mb={2}>Details</GiveText>
      <DetailsContainer>
        <Grid container spacing={2}>
          {joinedAt && (
            <>
              <Grid item xs={6}>
                <GiveText variant="bodyS" color="secondary">
                  Joined
                </GiveText>
              </Grid>
              <Grid item xs={6}>
                <GiveTruncateText lineClamp={2} variant="bodyS">
                  {formattedJoinedAt}
                </GiveTruncateText>
              </Grid>
            </>
          )}
 
          <Grid item xs={6}>
            <GiveText variant="bodyS" color="secondary">
              Role
            </GiveText>
          </Grid>
          <Grid item xs={6}>
            <GiveTruncateText lineClamp={2} variant="bodyS">
              {roleLabel}
            </GiveTruncateText>
          </Grid>
 
          {showNewRoleRow && (
            <>
              <Grid item xs={6}>
                <Box display="flex" alignItems="center" gap={0.5}>
                  <GiveText variant="bodyS" color="secondary">
                    New Role
                  </GiveText>
                  {/* GB-21490: constrain the tooltip trigger to the icon width.
                      The GiveTooltip trigger stretches as a flex sibling, eating
                      the column and forcing the "New Role" label to wrap. A
                      fixed-width box (the established HeaderElements pattern)
                      keeps the trigger fluid to its content. */}
                  <Box
                    width="16px"
                    flexShrink={0}
                    display="flex"
                    alignItems="center"
                  >
                    <GiveTooltip title={NEW_ROLE_TOOLTIP}>
                      <Box display="flex" alignItems="center">
                        <InfoIcon size={16} />
                      </Box>
                    </GiveTooltip>
                  </Box>
                </Box>
              </Grid>
              <Grid item xs={6}>
                <GiveTruncateText lineClamp={2} variant="bodyS">
                  {NEW_PAH_ROLE_LABEL}
                </GiveTruncateText>
              </Grid>
            </>
          )}
 
          <Grid item xs={6}>
            <GiveText variant="bodyS" color="secondary">
              Email
            </GiveText>
          </Grid>
          <Grid item xs={6}>
            <GiveTruncateText
              sx={{ wordBreak: "break-all" }}
              lineClamp={2}
              variant="bodyS"
            >
              {email || "-"}
            </GiveTruncateText>
          </Grid>
 
          <Grid item xs={6}>
            <GiveText variant="bodyS" color="secondary">
              Job Title
            </GiveText>
          </Grid>
          <Grid item xs={6}>
            <GiveTruncateText lineClamp={2} variant="bodyS">
              {occupation || "-"}
            </GiveTruncateText>
          </Grid>
 
          <Grid item xs={6}>
            <GiveText variant="bodyS" color="secondary">
              Employer
            </GiveText>
          </Grid>
          <Grid item xs={6}>
            <GiveTruncateText lineClamp={2} variant="bodyS">
              {employer || "-"}
            </GiveTruncateText>
          </Grid>
        </Grid>
        <Box mt={3} display="flex" justifyContent="center" gap={1.5}>
          {showTransferOwnership && (
            <GiveButton
              label="Transfer Ownership"
              color="light"
              size="large"
              onClick={onTransferOwnership}
              sx={{ width: "100%" }}
              data-testid="team-pah-transfer-ownership-button"
            />
          )}
          {showCancelChange && (
            <GiveButton
              label="Cancel Change"
              color="light"
              size="large"
              onClick={onCancelChange}
              sx={{ width: "100%" }}
              data-testid="team-pah-cancel-change-button"
            />
          )}
          <GiveTooltip
            title={MANAGE_PERMISSIONS_DENY_MESSAGE}
            disableHoverListener={isListPermissionsAllowed}
          >
            <GiveButton
              label="Manage Permissions"
              disabled={!isListPermissionsAllowed}
              color="light"
              size="large"
              onClick={onClickManagePermissions}
              sx={{
                width: "100%",
              }}
            />
          </GiveTooltip>
        </Box>
      </DetailsContainer>
    </Box>
  );
};
 
export default MemberDetails;
 
const DetailsContainer = styled(Box)(({ theme }) => ({
  backgroundColor: theme.palette.surface?.primary,
  borderRadius: "20px",
  padding: "20px",
  marginTop: theme.spacing(1),
}));