All files / src/components/ProfilePage/ProfileSetupHome ProfileSetupHome.tsx

95.65% Statements 22/23
83.33% Branches 10/12
100% Functions 6/6
95.65% Lines 22/23

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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176                                                                          18x                 20x 20x 20x   20x   3x 3x                   20x   20x         20x           20x         20x   20x           20x     20x       20x     20x                           3x                               3x                         2x         20x           80x                                            
import { Box, Stack } from "@mui/material";
import PageTitle from "./PageTitle";
import HomepageCard, { HomepageCardStatus } from "./HomepageCard";
import { THomepageOption } from "../types";
import { Text } from "@common/Text";
import { palette } from "@palette";
import NiceModal from "@ebay/nice-modal-react";
import { VERIFY_ACCOUNT_HOLDER_V2 } from "modals/modal_names";
import useCheckPAH from "@hooks/common/useCheckPAH";
import { useGetCurrentMerchantId } from "@hooks/common";
import useFindBusinessProfileById from "@hooks/enterprise-api/merchants/useFindBusinessProfileById";
import { checkPortals } from "@utils/routing";
import { useTriggerPathEffect } from "@hooks/common/router/useRedirect";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import { OFAC_STATUS } from "@constants/constants";
import { NOT_ALLOWED_TO_ADD_BANK_ACCOUNT_TOOLTIP_MESSAGE } from "@constants/stringConstants";
import { useAccessControl } from "@features/Permissions/AccessControl";
import RESOURCE_BASE, {
  EDIT_DENY_MESSAGE,
  OPERATIONS,
} from "@constants/permissions";
import BankAccountWarningAlert from "@components/BankAccounts/BankAccountWarningAlert";
 
export type ProfileSetupHomeProps = {
  taxID?: string;
  chooseSection: (section: THomepageOption) => void;
 
  backToWelcomePage: () => void;
  hasPrincipal: boolean;
  pahStatus: HomepageCardStatus;
  bankAccountStatus: HomepageCardStatus;
  businessDetailsStatus: HomepageCardStatus;
  msaStatus: HomepageCardStatus;
  isIncomplete?: boolean;
};
 
const ProfileSetupHome = ({
  chooseSection,
  backToWelcomePage,
  pahStatus,
  bankAccountStatus,
  businessDetailsStatus,
  msaStatus,
  isIncomplete,
}: ProfileSetupHomeProps) => {
  const { isLoggedInPAH } = useCheckPAH();
  const { merchantId } = useGetCurrentMerchantId();
  const { isMerchantPortal } = checkPortals();
 
  const handleVerifyIdentityClick = () => {
    // TODO: we need to check if we need to keep Verify Holder Modal for merchant
    if (isMerchantPortal) {
      NiceModal.show(VERIFY_ACCOUNT_HOLDER_V2, {
        isController: merchant?.legalEntityID ? merchant?.isController : true,
        merchant,
        isApproved: pahStatus === "APPROVED",
      });
    } else E{
      chooseSection("enterprise_verify_identity");
    }
  };
 
  useTriggerPathEffect(handleVerifyIdentityClick, { delay: 100 });
 
  const { data: merchant, isAllowedAddBankAccounts } = useGetMerchantById({
    merchantId: merchantId,
    enabled: !!merchantId,
  });
 
  const isUpdateLEAllowed = useAccessControl({
    resource: RESOURCE_BASE.LEGAL_ENTITY,
    operation: OPERATIONS.UPDATE,
    withPortal: true,
  });
 
  const canCreateBAPermission = useAccessControl({
    resource: RESOURCE_BASE.BANK_ACCOUNT,
    operation: OPERATIONS.CREATE,
    withPortal: true,
  });
  const isAllowedToAddBA = isAllowedAddBankAccounts && canCreateBAPermission;
 
  const { data: legalEntity } = useFindBusinessProfileById({
    id: merchant?.legalEntityID,
    merchantId,
  });
 
  const isPahUnderVerification =
    merchant?.owner?.statusName === "ready_for_verification";
 
  const isPahSuspended =
    merchant?.ownerOfac?.lastCheckStatusName === OFAC_STATUS.CONFIRMED_MATCH ||
    merchant?.ownerOfac?.lastCheckStatusName === OFAC_STATUS.POSSIBLE_MATCH;
 
  const isBpSuspended =
    legalEntity?.ofac?.lastCheckStatusName === OFAC_STATUS.CONFIRMED_MATCH ||
    legalEntity?.ofac?.lastCheckStatusName === OFAC_STATUS.POSSIBLE_MATCH;
 
  const options = [
    {
      title: "Verify your Identity",
      status: pahStatus,
      isSuspended: isPahSuspended,
      isUnderVerification: isPahUnderVerification,
      isLocked: !isLoggedInPAH,
      onClick: handleVerifyIdentityClick,
      isIncomplete: pahStatus === "INCOMPLETE",
      datatestID: "verify_identity",
    },
    {
      title: "Submit Business Details",
      status: businessDetailsStatus,
      onClick: () => chooseSection("business_details"),
      datatestID: "business_details",
      isIncomplete: isIncomplete,
      isSuspended: isBpSuspended,
      isLocked:
        legalEntity?.ofac?.lastCheckStatusName === "confirmed_match" ||
        !isUpdateLEAllowed,
      tooltipProps: {
        show: !isUpdateLEAllowed,
        message: EDIT_DENY_MESSAGE,
        placement: "top",
      },
    },
    {
      title: "Connect a Bank Account",
      status: bankAccountStatus,
      onClick: () => chooseSection("bank_account"),
      datatestID: "connect_your_bank_account",
      isLocked: !isAllowedToAddBA,
      tooltipProps: {
        show: !isAllowedToAddBA,
        message: NOT_ALLOWED_TO_ADD_BANK_ACCOUNT_TOOLTIP_MESSAGE,
        placement: "top",
      },
    },
    {
      title: "Sign Agreement",
      status: msaStatus,
      isLocked: false,
      onClick: () => chooseSection("merchant_agreement"),
      datatestID: "sign_agreement",
    },
  ];
 
  return (
    <Stack direction="column" flexGrow={1} gap={4}>
      <PageTitle />
      <BankAccountWarningAlert isAllowedAddAccounts={isAllowedToAddBA} />
      <Stack direction="column" gap={1.5}>
        {options.map((option) => (
          <HomepageCard key={option.title} {...option} />
        ))}
      </Stack>
      <Box
        alignSelf="center"
        onClick={backToWelcomePage}
        sx={{ cursor: "pointer", userSelect: "none" }}
      >
        <Text
          variant="link"
          lineHeight="16.8px"
          fontWeight="book"
          color={palette.gray[300]}
        >
          I&apos;ll do it later
        </Text>
      </Box>
    </Stack>
  );
};
 
export default ProfileSetupHome;