All files / src/features/Settings/Team/hooks useTeamPahTransferActions.ts

92.3% Statements 12/13
50% Branches 1/2
100% Functions 5/5
100% Lines 12/12

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                5x 5x 1x             5x         42x   42x 1x           42x 1x 1x           1x           42x        
import NiceModal from "@ebay/nice-modal-react";
import {
  CHANGE_PAH_MODAL,
  GIVE_CONFIRMATION_POP_UP,
} from "modals/modal_names";
import { PahReassignment } from "@hooks/common/usePahReassignmentStatus";
import useCancelPahReassignment from "./useCancelPahReassignment";
 
const CANCEL_PAH_MODAL_TITLE = "Cancel Primary Account Holder Change";
const getCancelPahDescription = (email: string) =>
  `Are you sure you want to cancel the Primary Account Holder change for ${email}? Cancelling will revoke the user's invitation, and the current Primary Account Holder for this merchant account will remain active.`;
 
/**
 * The two entry points the current PAH gets from their own Team-tab
 * side panel: start a transfer (opens the Change PAH modal) and, while one is
 * in flight, cancel it (a confirmation pop-up that revokes the invite).
 */
const useTeamPahTransferActions = (
  merchantId: number,
  reassignment: PahReassignment | undefined,
) => {
  const { cancelReassignment, isLoading } =
    useCancelPahReassignment(merchantId);
 
  const onTransferOwnership = () => {
    NiceModal.show(CHANGE_PAH_MODAL, {
      merchantId,
      enableMemberSuggestions: true,
    });
  };
 
  const onCancelChange = () => {
    Iif (!reassignment?.inviteId) return;
    NiceModal.show(GIVE_CONFIRMATION_POP_UP, {
      modalType: "declined",
      title: CANCEL_PAH_MODAL_TITLE,
      description: getCancelPahDescription(reassignment.newOwnerEmail),
      actions: {
        handleSuccess: {
          onClick: () => cancelReassignment(reassignment.inviteId),
        },
      },
    });
  };
 
  return { onTransferOwnership, onCancelChange, isLoading };
};
 
export default useTeamPahTransferActions;