All files / src/features/Merchants/MerchantSidePanel/GiveMerchantFile/components PlaceholderSection.tsx

80% Statements 12/15
71.42% Branches 10/14
100% Functions 5/5
91.66% Lines 11/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 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                                                                                            23x         231x 1295x     231x   231x                             713x   713x 13x 13x                                                     713x                                             231x                    
import { Box } from "@mui/material";
import { Fragment } from "react";
import NiceModal from "@ebay/nice-modal-react";
import { FormType } from "@components/Merchants/CreateMerchantPanel/modals/CreateBusinessProfileModal";
import { PlaceholderCard } from "./PlaceholderCard";
import { styled } from "@theme/v2/Provider";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { BoxProps } from "@mui/material";
 
export type SectionPlaceholderProps = {
  placeholdersList: {
    icon: JSX.Element;
    title: string;
    description: string;
    hidden?: boolean;
    disabled?: boolean;
    modal?: string;
    onClose?: (data: any) => void;
    data?: any;
    merchantData?: any;
    businessType?: string;
    merchantId?: number;
    merchantName?: string;
    legalEntityID?: number;
    totalOwnerships?: number;
    noController?: boolean;
    formType?: FormType;
    parentCategories?: any[];
    categories?: any[];
    isDefault?: boolean;
    warning?: boolean;
    isIndividualSoleProprietorship?: boolean;
    isEnterprise?: boolean;
    onClick?: () => void;
    testId?: string;
    parentAccID?: number;
    tooltipProps?: {
      show: boolean;
      message: string;
    };
    primaryAccountHolder?: boolean;
  }[];
  sx?: BoxProps;
  isBusinessAddressAvailable?: boolean;
};
 
const PlaceholderSection = ({
  placeholdersList,
  sx,
  isBusinessAddressAvailable,
}: SectionPlaceholderProps) => {
  const visiblePlaceholders = placeholdersList.filter(
    (placeholder) => !placeholder.hidden && !placeholder.noController,
  );
 
  Iif (visiblePlaceholders.length === 0) return null;
 
  return (
    <PlaceholderCardContainer sx={sx}>
      {visiblePlaceholders.map((placeholder, index) => {
        const {
          formType,
          merchantId,
          businessType,
          isDefault,
          isEnterprise,
          onClick,
          tooltipProps,
          testId,
          merchantName,
          parentAccID,
          ...placeholdeRest
        } = placeholder;
 
        const handleClick = () => {
          if (placeholder.modal && !tooltipProps?.show) {
            NiceModal.show(placeholder.modal, {
              data: placeholder.data,
              merchantData: placeholder.merchantData,
              onClose: placeholder.onClose,
              merchantId,
              id: merchantId,
              legalEntityID: placeholder.legalEntityID,
              totalOwnerships: placeholder.totalOwnerships,
              parentCategories: placeholder.parentCategories,
              categories: placeholder.categories,
              isIndividualSoleProprietorship:
                placeholder.isIndividualSoleProprietorship,
              isDefault: isDefault || false,
              primaryAccountHolder: placeholder?.primaryAccountHolder,
              formType,
              isEnterprise,
              businessType,
              isMerchant: true,
              merchantName: merchantName,
              parentAccID,
              allowBankAccounts: true,
              allowTransfers: true,
              isBusinessAddressAvailable,
            });
          } else Eif (onClick) onClick();
        };
 
        return (
          <Fragment key={placeholder.title}>
            <GiveTooltip
              width="compact"
              alignment="left"
              title={tooltipProps?.message}
              color="default"
              disableHoverListener={!tooltipProps?.show}
            >
              <PlaceholderCard
                {...placeholdeRest}
                disabled={tooltipProps?.show || placeholdeRest.disabled}
                data-testid={testId}
                onClick={handleClick}
              />
            </GiveTooltip>
          </Fragment>
        );
      })}
    </PlaceholderCardContainer>
  );
};
 
const PlaceholderCardContainer = styled(Box)(({ theme }) => ({
  display: "flex",
  flexDirection: "column",
  gap: "8px",
  padding: "16px",
  borderRadius: "20px",
  background: theme.palette.surface?.primary,
  overflow: "hidden",
}));
export default PlaceholderSection;