All files / src/features/Merchants/MerchantSidePanel/hooks useComponentVisibilityOnStatus.ts

100% Statements 12/12
95.23% Branches 20/21
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                            22x           1010x                     1010x 1010x   1010x 522x 2610x 870x         1010x     1010x             1010x   1010x                                  
import { useMemo } from "react";
import {
  getAccountStatus,
  statusOverviewList,
} from "@components/Merchants/MerchantPreview/sections/StatusReview/utils/status";
import { TStatusReview } from "@components/Merchants/MerchantPreview/data.types";
 
type Props = {
  data: TStatusReview;
  isEnterprise?: boolean;
  isRebranding?: boolean;
  sponsorStatusName?: string;
};
 
export const useComponentVisibilityOnStatus = ({
  data,
  isEnterprise,
  isRebranding = false,
  sponsorStatusName,
}: Props) => {
  const statusListItems = statusOverviewList(
    {
      primaryAccount: data?.approvedOwner,
      businessProfile: data?.hasApprovedLegalEntity,
      bankAccount: data?.hasApprovedBankAccount,
      merchantAgreement: data?.approvedAgreement,
      score: data?.underwritingScorePercentage || 0,
    },
    isEnterprise,
  );
 
  const { isReadyToApprove } = useMemo(() => {
    let isReadyToApprove = true;
 
    if (data?.statusName !== "approved") {
      statusListItems.forEach((status) => {
        if (!status.approved) {
          isReadyToApprove = false;
        }
      });
    }
 
    return { isReadyToApprove };
  }, [statusListItems]);
 
  const status = getAccountStatus(
    isReadyToApprove,
    data?.statusName,
    isRebranding,
    sponsorStatusName,
  );
  const isIncomplete =
    !["declined", "closed"].includes(data?.statusName) && !isReadyToApprove;
 
  return {
    isUnderwritingReportVisible:
      (isReadyToApprove || isIncomplete || data?.statusName === "declined") &&
      data?.statusName !== "approved" &&
      data?.statusName !== "suspended" &&
      data?.statusName !== "closed",
    isRiskSummaryVisible:
      data?.statusName === "approved" ||
      data?.statusName === "suspended" ||
      data?.statusName === "closed",
    isStatusOverviewVisible:
      data?.statusName === "approved" ||
      data?.statusName === "suspended" ||
      data?.statusName === "closed",
    status: status,
  };
};