All files / src/features/Merchants/MerchantSidePanel/GiveMerchantFile/businessProfile DeclinedBPLinking.tsx

75% Statements 6/8
75% Branches 3/4
33.33% Functions 1/3
75% Lines 6/8

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                                        22x         1x   1x         1x               1x               1x                                          
import { useEnterprisePermissions } from "@components/AcquirerEnterprises/CreateEnterprise/hooks/useEnterprisePermissions";
import RESOURCE_BASE, { OPERATIONS } from "@constants/permissions";
import NiceModal from "@ebay/nice-modal-react";
import { WarningIcon } from "@phosphor-icons/react";
import GiveAlert from "@shared/GiveAlert/GiveAlert";
import {
  composePermission,
  useAccessControl,
} from "features/Permissions/AccessControl";
import { CREATE_BUSINESS_PROFILE_MODAL } from "modals/modal_names";
import { businessProfileDefaultValues } from "@validation/merchant";
import { TBusinessProfileInfo } from "@components/Merchants/MerchantPreview/data.types";
import { getTaxIdFormat } from "@utils/index";
 
type Props = {
  merchantId: number;
  merchantName: string;
  businessProfile: TBusinessProfileInfo;
};
 
const DeclinedBPLinking = ({
  merchantId,
  merchantName,
  businessProfile,
}: Props) => {
  const { modify_merchant } = useEnterprisePermissions();
 
  const declinedLinkedTaxID = getTaxIdFormat(
    businessProfile?.pendingLegalEntityTaxIDNumber,
    businessProfile?.pendingLegalEntityTinType,
  );
 
  const isAllowedCreateBusinessProfile = useAccessControl({
    resource: composePermission(
      RESOURCE_BASE.MERCHANT,
      RESOURCE_BASE.LEGAL_ENTITY,
    ),
    operation: OPERATIONS.CREATE,
  });
 
  const handleAddBusinessProfile = () => {
    NiceModal.show(CREATE_BUSINESS_PROFILE_MODAL, {
      merchantId,
      merchantName,
      data: businessProfileDefaultValues,
    });
  };
 
  return (
    <GiveAlert
      withBorder
      type="warning"
      label="Business profile linking declined"
      description={`The business profile link request (${declinedLinkedTaxID}) has been declined. A new Tax ID is required to set up the business profile.`}
      variant="alert"
      Icon={<WarningIcon size={20} />}
      action={
        isAllowedCreateBusinessProfile && modify_merchant
          ? {
              label: "Add Business Profile",
              onClick: () => handleAddBusinessProfile(),
            }
          : {}
      }
    />
  );
};
 
export default DeclinedBPLinking;