All files / src/features/Settings/Team/helpers pahPanelState.ts

100% Statements 4/4
100% Branches 11/11
100% Functions 1/1
100% Lines 4/4

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                    7x                     62x         62x   62x                          
import { isPahReassignmentInFlight } from "@components/Merchants/MerchantPreview/helpers/pahReassignment";
 
/**
 * GB-21471 — decides what the merchant Team-tab side panel shows for the
 * Primary Account Holder transfer flow.
 *
 * The flow is only ever exposed on the current PAH's *own* panel, and only in
 * the merchant portal. Non-PAH members and other people's owner rows never see
 * it (server-side authZ also enforces this on the reassignment endpoint).
 */
export const getPahPanelState = ({
  isOwner,
  isCurrentUser,
  isMerchantPortal,
  reassignmentState,
}: {
  isOwner: boolean;
  isCurrentUser: boolean;
  isMerchantPortal: boolean;
  reassignmentState?: "pending_reassignment" | "ready_for_approval";
}) => {
  const isOwnerOwnPanel = Boolean(
    isOwner && isCurrentUser && isMerchantPortal,
  );
  // Shared with the merchant side panel so the two surfaces agree on which
  // states count as "in flight" (both pending_reassignment and ready_for_approval).
  const hasReassignment = isPahReassignmentInFlight(reassignmentState);
 
  return {
    isOwnerOwnPanel,
    // Idle state: offer to start the transfer.
    showTransferButton: isOwnerOwnPanel && !hasReassignment,
    // Cancel is only possible until the new PAH accepts the invite — once they
    // have (state: "ready_for_approval"), the transfer can no longer be undone.
    showCancelButton:
      isOwnerOwnPanel && reassignmentState === "pending_reassignment",
    // Banner + upcoming-role row stay for the whole in-flight window.
    showNewRoleRow: isOwnerOwnPanel && hasReassignment,
    showReassignmentBanner: isOwnerOwnPanel && hasReassignment,
  };
};