All files / src/hooks useSettingsBreadcrumbs.tsx

100% Statements 15/15
83.33% Branches 5/6
100% Functions 2/2
100% Lines 14/14

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                  2x 23x 23x 23x 23x   58x   23x       23x   23x     23x     23x   23x   23x   23x                          
import { SettingsMenuListItem } from "@customTypes/data.types";
import { useLocation } from "react-router-dom";
import { ACQUIRER_PATHS, ENTERPRISE_PATHS } from "@routes/paths";
 
interface Props {
  base: "acquirer" | "provider" | "merchant";
  nestedRoutes: SettingsMenuListItem[];
}
 
export const useSettingsBreadcrumbs = ({ nestedRoutes, base }: Props) => {
  const { pathname } = useLocation();
  const pathSegments = pathname.split("/").filter(Boolean);
  const lastSegment = pathSegments[pathSegments.length - 1];
  const isSettingsBasePage = /.*\/settings$/.test(pathname);
  const breadcrumbTitle =
    nestedRoutes.find((route) => route.path === lastSegment)?.name ||
    "Settings";
  const breadcrumbItems = [
    { label: "Settings", path: `/${base}/settings` },
    { label: breadcrumbTitle },
  ];
  const isPermissions = pathname.includes("permissions");
  const isLegalDocumentDetail =
    pathname.includes(ACQUIRER_PATHS.LEGAL_DOCUMENTS) &&
    pathSegments.length > 3;
 
  const isBusinessDetailsTab = pathname.includes(
    ACQUIRER_PATHS.BUSINESS_DETAILS,
  );
  const isTeamTab = pathname.includes(ACQUIRER_PATHS.MANAGE_TEAM);
  const isRevanueTab =
    pathname.includes(ACQUIRER_PATHS.ACQUIRER_REVENUE) ||
    pathname.includes(ENTERPRISE_PATHS.REVENUE);
  const isMCCTab = pathname.includes(ACQUIRER_PATHS.MERCHANT_CATEGORY_CODES);
 
  return {
    isSettingsBasePage,
    breadcrumbTitle,
    breadcrumbItems,
    lastSegment,
    isPermissions,
    isBusinessDetailsTab,
    isTeamTab,
    isRevanueTab,
    isMCCTab,
    isLegalDocumentDetail,
  };
};