All files / src/shared/EmptyState GiveEmptyStateWrapper.tsx

92.3% Statements 24/26
95.12% Branches 117/123
60% Functions 3/5
92% Lines 23/25

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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609                                                                                                                                        261x                             386x 386x 386x       386x 142x                                                                                             244x   216x     261x             261x 386x 386x     386x   386x   386x           386x                 386x                     386x   386x             386x             386x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           386x         261x          
import { Stack, SxProps } from "@mui/material";
import React from "react";
import {
  TEmptyStateWrapperSection,
  TEmptyStateAction,
  GiveEmptyStateType,
} from "./types";
import GiveEmptyState from "./GiveEmptyState";
import {
  StorefrontIcon,
  BriefcaseIcon,
  XCircleIcon,
  MagnifyingGlassIcon,
  GridFourIcon,
  ArrowsLeftRightIcon,
  CreditCardIcon,
  CodeIcon,
  TagIcon,
  UsersIcon,
  PlusIcon,
  UsersFourIcon,
  BankIcon,
  IdentificationBadgeIcon,
  FileTextIcon,
  LockIcon,
  AtIcon,
  ChatsCircleIcon,
  ArrowUpIcon,
  ArrowsCounterClockwiseIcon,
  CheckIcon,
  TicketIcon,
  UserCircleGearIcon,
  EnvelopeOpenIcon,
} from "@phosphor-icons/react";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { useNavigate } from "react-router-dom";
import { checkPortals } from "@utils/routing";
import { MERCHANT_ADD_EDIT_CUSTOMER_V2 } from "modals/modal_names";
import NiceModal from "@ebay/nice-modal-react";
import { selectMerchantTab } from "@redux/slices/enterprise/merchants";
import { useAppSelector } from "@redux/hooks";
import { GiveTooltipProps } from "@shared/Tooltip/GiveTooltip.types";
import {
  MANAGE_MONEY_TABLE_TYPES,
  TRANSACTIONS_TABLE_TYPES,
} from "@constants/constants";
 
type Props = {
  children?: React.ReactNode;
  isEmpty?: boolean;
  section?: TEmptyStateWrapperSection;
  sectionName?: string;
  sx?: SxProps;
  iconContainerSx?: SxProps;
  giveEmptyStateSx?: SxProps;
  action?: Omit<TEmptyStateAction, "label">;
  /**
   * The handler (and gate) for the second button of a two-action state. Inert
   * for a section whose config declares no `secondaryAction`.
   */
  secondaryAction?: Omit<TEmptyStateAction, "label">;
  actionTooltipProps?: Partial<GiveTooltipProps>;
  searchValue?: string;
  iconSize?: number;
  noWrapper?: boolean;
};
 
const GiveEmptyStateWrapper = ({
  isEmpty = false,
  children,
  section,
  sectionName,
  sx,
  action,
  secondaryAction,
  actionTooltipProps,
  searchValue,
  giveEmptyStateSx,
  iconContainerSx,
  iconSize,
  noWrapper = false,
}: Props) => {
  const { generateData } = useGenerateData();
  const tab = useAppSelector(selectMerchantTab);
  const currentData = section
    ? generateData({ searchValue, tab, sectionName, iconSize })[section]
    : null;
 
  if (isEmpty && section && currentData) {
    return (
      <GiveEmptyState
        {...currentData}
        action={
          currentData?.action
            ? {
                label: currentData?.action?.label,
                handleAction:
                  currentData?.action?.handleAction || action?.handleAction,
                disabled: action?.disabled,
                startIcon: currentData?.action?.startIcon,
                variant: currentData?.action?.variant,
                // From the caller, not the section config: the tooltip carries
                // the reason this particular caller's button is closed.
                tooltipProps: action?.tooltipProps,
              }
            : undefined
        }
        secondaryAction={
          currentData?.secondaryAction
            ? {
                label: currentData.secondaryAction.label,
                handleAction:
                  currentData.secondaryAction.handleAction ||
                  secondaryAction?.handleAction,
                disabled: secondaryAction?.disabled,
                startIcon: currentData.secondaryAction.startIcon,
                variant: currentData.secondaryAction.variant,
                tooltipProps: secondaryAction?.tooltipProps,
              }
            : undefined
        }
        actionTooltipProps={actionTooltipProps}
        sx={giveEmptyStateSx}
        dataTestId={section}
        iconContainerSx={
          {
            width: "36px",
            height: "36px",
            ...iconContainerSx,
            ...currentData?.iconContainerSx,
          } as SxProps
        }
      />
    );
  }
 
  if (noWrapper) return children;
 
  return <Container sx={sx}>{children}</Container>;
};
 
const Container = styled(Stack)({
  width: "100%",
  height: "100%",
  flexGrow: 1,
  alignItems: "center",
});
 
const useGenerateData = () => {
  const { isEnterprisePortal, isAcquirerEnterprises } = checkPortals();
  const { palette } = useAppTheme();
  // Only the Host tab's states change copy by breakpoint — the 390px frames
  // shorten "Assign Host"/"Invite Host" to fit two buttons on one row.
  const { isMobileView } = useCustomThemeV2();
 
  const navigate = useNavigate();
 
  const handleAction = () => {
    navigate(
      `${isEnterprisePortal ? "/provider" : "/acquirer"}/settings/manage-team`,
    );
  };
 
  const TAB_NAMES_MAP: Record<string, string> = {
    "-invited": "invited",
    "-kyb": "in KYB",
    "-underwriting": "in underwriting",
    "-sponsor": "in sponsor",
    "-approved": "approved",
    "-risk": "in risk",
  };
 
  const generateData = ({
    searchValue,
    tab,
    sectionName,
    iconSize,
  }: {
    searchValue?: string;
    tab?: string;
    sectionName?: string;
    iconSize?: number;
  }): Record<TEmptyStateWrapperSection, GiveEmptyStateType> => {
    const emptyTabLabel = isAcquirerEnterprises ? "providers" : "merchants";
 
    const noTransactionState = {
      Icon: <ArrowsLeftRightIcon size={iconSize || 28} />,
      title: {
        main: `No transactions`,
      },
    };
 
    const noTransfersState = {
      Icon: <ArrowUpIcon size={iconSize || 28} />,
      title: {
        main: `No transfers`,
      },
    };
 
    return {
      merchant: {
        Icon: <StorefrontIcon size={iconSize || 28} />,
        title: {
          main: "No merchants",
          secondary: "Create your first merchant",
        },
        action: {
          label: "Create Merchant",
        },
      },
      emptyTab: {
        Icon: <StorefrontIcon size={iconSize || 28} />,
        title: {
          main: `No ${emptyTabLabel} available`,
          secondary: `There are currently no ${emptyTabLabel} ${
            TAB_NAMES_MAP?.[tab as string] || "in this step"
          }`,
        },
      },
      provider: {
        Icon: <BriefcaseIcon size={iconSize || 28} />,
        title: {
          main: "No providers",
          secondary: "Create your first provider",
        },
        action: {
          label: "Create Provider",
        },
      },
 
      "no-filter-results-customers": {
        Icon: <XCircleIcon size={iconSize || 28} />,
        title: {
          main: "No recurring customers",
          secondary: "Please try removing the filters",
        },
        action: {
          label: "Clear Filters",
        },
      },
      "no-filter-results": {
        iconContainerSx: { minWidth: "68px", minHeight: "68px" },
        Icon: <XCircleIcon size={iconSize || 28} />,
        title: {
          main: "No results",
          secondary: "Please try removing the filters",
        },
        action: {
          label: "Clear Filters",
        },
      },
 
      "empty-team-members-list": {
        Icon: <UsersIcon size={iconSize || 28} />,
        title: {
          main: "",
          secondary: "You do not have any team members",
        },
        action: {
          label: "Add Team Member",
          startIcon: <PlusIcon size={iconSize || 18} />,
          handleAction,
        },
      },
      "empty-legal-documents": {
        iconContainerSx: { minWidth: "68px", minHeight: "68px" },
        Icon: <FileTextIcon size={iconSize || 28} />,
        title: {
          main: "",
          secondary: "You do not have any documents",
        },
      },
      settlements: {
        Icon: <BankIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: "No settlements",
          secondary: "",
        },
      },
      "settlements-transactions": {
        Icon: <BankIcon size={iconSize || 28} />,
        iconContainerSx: { width: "68px", height: "68px" },
        title: {
          main: "No settled transactions",
          secondary: "",
        },
      },
      "settlements-merchants": {
        Icon: <StorefrontIcon size={iconSize || 28} />,
        iconContainerSx: { width: "68px", height: "68px" },
        title: {
          main: "No settlements recorded",
          secondary:
            "There was no settlement activity for merchants on the selected date.",
        },
      },
      "empty-search": {
        iconContainerSx: { minWidth: "68px", minHeight: "68px" },
        Icon: <MagnifyingGlassIcon size={iconSize || 28} />,
        title: {
          main: `No results for "${searchValue}"`,
          secondary: "Please try a different search term",
        },
        action: {
          label: "Clear Search",
        },
      },
      "empty-search-and-filter": {
        iconContainerSx: { minWidth: "68px", minHeight: "68px" },
        Icon: <MagnifyingGlassIcon size={iconSize || 28} />,
        title: {
          main: `No results for "${searchValue}"`,
          secondary: "Please try a different search term or filter criteria",
        },
        action: {
          label: "Clear Search",
        },
      },
      products: {
        Icon: <GridFourIcon size={iconSize || 28} />,
        title: {
          main: ``,
          secondary:
            "There’s currently nothing to see here. Please check back soon for updates!",
        },
      },
      events: {
        Icon: <GridFourIcon size={iconSize || 28} />,
        title: {
          main: ``,
          secondary: "This event has ended, tickets are no longer available.",
        },
      },
      disputes: {
        Icon: (
          <ArrowsCounterClockwiseIcon
            fill={palette.text.secondary}
            size={iconSize || 28}
          />
        ),
        iconContainerSx: {
          width: "68px !important",
          height: "68px !important",
        },
        title: {
          main: `No disputes`,
        },
      },
      transactions: {
        Icon: <CreditCardIcon size={iconSize || 28} />,
        title: {
          main: `No transactions`,
        },
      },
      // PayBuilder 032 — Event Detail Tickets tab (frame 7397-90358).
      "event-tickets": {
        Icon: <TicketIcon size={iconSize || 28} />,
        title: {
          main: "No tickets purchased yet",
        },
      },
      // PayBuilder — Event Detail Inventory tab (frame 7278-37114). "No
      // tickets" here means the event defines no ticket types at all, which is
      // a different thing from the Tickets tab's "none sold yet".
      "event-inventory": {
        Icon: <TicketIcon size={iconSize || 28} />,
        // The mockup draws the standard 68px circle; without this the
        // wrapper's 36px default squeezes the 28px glyph.
        iconContainerSx: { width: "68px", height: "68px" },
        title: {
          main: "This event has no tickets",
        },
      },
      // PayBuilder — Event Detail Host tab, an event with no hosts at all
      // (frame 7187-24163).
      //
      // Both host states draw the same Icon frame: a 56px circle inset 16px
      // around a 24px glyph. The wrapper's 36px default left the 28px glyph
      // almost filling its circle, with 4px to spare.
      // With the toolbar hidden on an empty tab, these buttons are the only way
      // in — and there are two ways to fill the tab, so the state offers both
      // (frame 8089-55598): assign a host the merchant already has, or invite a
      // new one. Mobile shortens both labels (frame 8123-61444).
      "event-hosts": {
        Icon: <UserCircleGearIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: "No host assigned yet",
        },
        action: {
          label: isMobileView ? "Assign" : "Assign Host",
          startIcon: <PlusIcon size={18} />,
          variant: "filled",
        },
        secondaryAction: {
          label: isMobileView ? "Invite" : "Invite Host",
          startIcon: <EnvelopeOpenIcon size={18} />,
        },
      },
      // Same tab, but with invitations already listed above (frame 8119-109601,
      // "Filled - Has Invited - No Assigned Host"). Only Assign Host here: an
      // invitation is already outstanding, so repeating Invite beside the
      // toolbar's own button would put the same CTA on the page twice.
      "event-hosts-invited-only": {
        Icon: <UserCircleGearIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: "No host assigned yet",
        },
        action: {
          // Shortened on mobile for the same reason as the sibling above: same
          // 390px column, same button, and this state has the invited list
          // above it (frame 8123-61444).
          label: isMobileView ? "Assign" : "Assign Host",
          startIcon: <PlusIcon size={18} />,
          variant: "filled",
        },
      },
      // PayBuilder — the Assign Host modal with nothing on the bench (frame
      // 8119-113344). Message only: the state is not the merchant's to fix from
      // here, since a host becomes assignable by accepting their invitation.
      "assign-host": {
        Icon: <UserCircleGearIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          secondary:
            "The host will be available to assign once they accept the invitation and sign in to GiveCash",
        },
      },
      // Same modal, a search that matched nothing (frame 8122-59649). Its own
      // section rather than the shared "empty-search" because the copy names
      // what is searchable here.
      "assign-host-search": {
        iconContainerSx: { minWidth: "68px", minHeight: "68px" },
        Icon: <MagnifyingGlassIcon size={iconSize || 28} />,
        title: {
          main: `No results for “${searchValue}”`,
          secondary: "Please try another name or email",
        },
        action: {
          label: "Clear Search",
        },
      },
      [MANAGE_MONEY_TABLE_TYPES.MERCHANT]: noTransactionState,
      [TRANSACTIONS_TABLE_TYPES.TRANSFERS]: noTransfersState,
      customers: {
        Icon: <UsersIcon size={iconSize || 28} />,
        title: {
          main: `No customers`,
          secondary: "Add your first customer",
        },
        action: {
          label: "Add customer",
        },
      },
      "customers-list": {
        Icon: <UsersIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `You do not have any customers`,
        },
        action: {
          label: "Add customer",
          startIcon: <PlusIcon size={iconSize || 18} />,
          handleAction: () => {
            NiceModal.show(MERCHANT_ADD_EDIT_CUSTOMER_V2, {});
          },
        },
      },
      developer: {
        Icon: <CodeIcon size={iconSize || 28} />,
        title: {
          main: `No API keys`,
          secondary: `Create your first API Key`,
        },
        action: {
          label: "Add API Key",
        },
      },
      "empty-mcc": {
        Icon: <TagIcon size={iconSize || 28} />,
        title: {
          main: `No MCC`,
        },
      },
      "empty-mcc-provider": {
        Icon: <TagIcon size={iconSize || 28} />,
        title: {
          main: `No merchant category codes added`,
        },
        action: {
          label: "Add MCC",
          startIcon: <PlusIcon size={iconSize || 18} />,
        },
      },
      "empty-settings-team-members": {
        Icon: <UsersFourIcon size={iconSize || 28} />,
        title: {
          main: "No team members",
          secondary: "Add your first team member",
        },
        action: {
          label: "Add Team Member",
        },
      },
      "bank-accounts-with-action": {
        Icon: <BankIcon size={iconSize || 24} />,
        title: {
          main: "No Bank Accounts",
        },
        action: {
          label: "Add Bank Account",
        },
      },
      "bank-accounts": {
        Icon: <BankIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `There are no Bank Accounts`,
        },
      },
      "no-bank-accounts": {
        Icon: <BankIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: "No Bank Accounts",
        },
      },
      "business-owner": {
        Icon: <BriefcaseIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `There are no Business Owners`,
        },
      },
      pah: {
        Icon: <IdentificationBadgeIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `There is no Primary Account Holder`,
        },
      },
      "pah-no-full-name": {
        Icon: <IdentificationBadgeIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `Create a Primary Account Holder, providing both first and last names`,
        },
      },
      "business-profile": {
        Icon: <FileTextIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `There is no Business Profile`,
        },
      },
      "not-authorized": {
        Icon: <LockIcon size={iconSize || 28} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          main: `You don't have the right permission to access ${sectionName} section`,
        },
      },
      "no-mentions": {
        Icon: <AtIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          secondary: `You haven’t been mentioned yet`,
        },
      },
      "no-team-conversations": {
        Icon: <ChatsCircleIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          secondary: `Write a message to the team`,
        },
      },
      "no-merchant-conversations": {
        Icon: <StorefrontIcon size={iconSize || 24} />,
        iconContainerSx: { width: "56px", height: "56px" },
        title: {
          secondary: `Write a message to the ${
            isAcquirerEnterprises ? "provider" : "merchant"
          } `,
        },
      },
      "no-activity": {
        Icon: <CheckIcon size={iconSize || 28} />,
        iconContainerSx: { width: "68px", height: "68px" },
        title: {
          main: "No activity",
        },
      },
      [MANAGE_MONEY_TABLE_TYPES.ACQUIRER_PROVIDER]: noTransactionState,
    };
  };
  return { generateData };
};
 
export default GiveEmptyStateWrapper;
 
export const mapTypeToEmptyState: Record<string, TEmptyStateWrapperSection> = {
  event: "events",
  standard: "products",
  // ... add other types when needed
};