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

56.25% Statements 9/16
41.17% Branches 7/17
20% Functions 1/5
56.25% Lines 9/16

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                                                              2x 2x 2x   2x   2x     2x       2x                     2x       2x                                                                  
import { Box, Stack } from "@mui/material";
import GiveAvatar from "@shared/Avatar/GiveAvatar";
import GiveText from "@shared/Text/GiveText";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { MemberData } from "@customTypes/team.member";
import {
  GIVE_DELETE_TEAM_MEMBER_MODAL,
  TEAM_MEMBER_PANEL_MODAL,
} from "modals/modal_names";
import NiceModal from "@ebay/nice-modal-react";
import InvitationDisclaimer from "./InvitationDisclaimer";
import { useSendInvitationAction } from "@hooks/merchant-api/manage-team/useResendInvite";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
 
interface InvitedHeaderProps {
  rowData: MemberData;
  imageUrl: string;
  isCurrentUser: boolean;
  isDeleteAllowed: boolean;
  isDeleteOwnerAllowed: boolean;
  isInviteAllowed: boolean;
}
 
function InvitedContentHeader({
  rowData,
  imageUrl,
  isCurrentUser,
  isDeleteAllowed,
  isDeleteOwnerAllowed,
  isInviteAllowed,
}: InvitedHeaderProps) {
  const { isMobileView } = useCustomThemeV2();
  const { firstName, lastName, email } = rowData?.user || {};
  const hasFullName = firstName && lastName;
  const { resentInvitationsIDs, handleResendInvitation } =
    useSendInvitationAction();
  const isDeleteDisabled =
    (rowData.roleName === "owner" && !isDeleteOwnerAllowed) ||
    isCurrentUser ||
    !isDeleteAllowed;
  const isSendInvitationDisabled = resentInvitationsIDs.some(
    (id) => id === rowData?.user.accID,
  );
 
  const handleDelete = () => {
    const { user, accID } = rowData;
    const { accID: userAccID, firstName, lastName, email } = user;
    const url = `/accounts/${accID}/members/${userAccID}`;
    NiceModal.show(GIVE_DELETE_TEAM_MEMBER_MODAL, {
      itemName: hasFullName ? `${firstName} ${lastName}` : email,
      url: url,
      onSuccess: () => NiceModal.remove(TEAM_MEMBER_PANEL_MODAL),
    });
  };
 
  const handleResend = () => {
    handleResendInvitation(rowData, true, isMobileView);
  };
 
  return (
    <Stack direction="column" gap={4}>
      <InvitationDisclaimer
        email={email}
        isSendDisabled={isSendInvitationDisabled}
        isSendHidden={!isInviteAllowed}
        isDeleteEnabled={!isDeleteDisabled}
        handleResend={handleResend}
        handleRevoke={handleDelete}
      />
      <Stack
        direction="row"
        justifyContent={"space-between"}
        alignItems="center"
      >
        <Box
          display="flex"
          flexDirection="column"
          paddingRight={3}
          gap={"16px"}
          width="100%"
        >
          {(firstName || lastName) && (
            <GiveText variant="h3" color="primary">
              {`${firstName || ""} ${lastName || ""}`.trim()}
            </GiveText>
          )}
        </Box>
      </Stack>
    </Stack>
  );
}
export default InvitedContentHeader;