All files / src/features/Merchants/MerchantSidePanel/components ProviderPanelBody.tsx

100% Statements 14/14
88.88% Branches 8/9
100% Functions 3/3
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 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                                      7x   7x 7x     7x 2x     7x     7x   7x   7x                                                       7x     49x 35x              
import React, { useEffect } from "react";
import { useMerchantSidePanelContext } from "../Provider/MerchantSidePanelProvider";
import KYBUnderwriterSponsorAssignCard from "./UnderwriterRiskAnalystAssignCard/KYBUnderwriterSponsorAssignCard";
import NewApprovalCard from "../ApprovalFlowPanel/NewApprovalCard";
import MerchantInformationSection from "./MerchantInformationSection";
import ApprovalAccountOverview from "../ApprovalFlowPanel/components/AccountOverview/ApprovalAccountOverview";
import ProviderMccSection from "./ProviderMccSection";
import ProviderConfigurationSection from "./ProviderConfigurationSection";
import GiveDisclaimer from "./GiveDisclaimer/GiveDisclaimer";
import { isMidErrorStatus } from "../utils/statusHelpers";
 
function ProviderPanelBody() {
  const {
    isLoadingUnderwriting,
    setIsLoadingUnderwriting,
    isUnderwritingView,
    isKYBView,
    data,
    isApproving,
  } = useMerchantSidePanelContext();
 
  const isDeclined = data?.status?.statusName === "declined";
  const isApproved = data?.status?.statusName === "approved";
 
  //set underwriting loading to false automatically if we are hiding the section
  useEffect(() => {
    if (isLoadingUnderwriting) setIsLoadingUnderwriting(false);
  }, [isLoadingUnderwriting]);
 
  const isDeclinedOrApproved = isDeclined || isApproved;
 
  const showNewApprovalCard =
    (isUnderwritingView || isKYBView) && !isDeclinedOrApproved;
 
  const isMIDerror = isMidErrorStatus(data?.status?.statusName, data?.processor);
 
  const merchantsSidePanelComponents = [
    {
      component: (
        <GiveDisclaimer
          disclaimerType="msp_warning_provider"
          showApproveRetry={isApproving}
        />
      ),
      hide: !isMIDerror,
    },
    {
      component: <ApprovalAccountOverview />,
      hide: showNewApprovalCard,
    },
    {
      component: <NewApprovalCard />,
      hide: !showNewApprovalCard,
    },
    {
      component: <MerchantInformationSection />,
      hide: showNewApprovalCard,
    },
    {
      component: <KYBUnderwriterSponsorAssignCard />,
    },
    { component: <ProviderMccSection /> },
    { component: <ProviderConfigurationSection /> },
  ];
  return (
    <>
      {merchantsSidePanelComponents?.map(({ component, hide }, i) => {
        if (hide) return null;
        return <React.Fragment key={i}>{component}</React.Fragment>;
      })}
    </>
  );
}
 
export default ProviderPanelBody;