All files / src/components/ProfileMenu/modals/hooks useAlertsTabs.ts

88.23% Statements 15/17
50% Branches 8/16
100% Functions 2/2
88.23% Lines 15/17

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                      8x 167x   167x   167x       167x 167x   167x                                               167x   167x 14x 14x   14x     14x     167x                 8x          
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
import { checkPortals } from "@utils/routing";
import { useState } from "react";
 
type TabNames = "acquirer" | "enterprise" | "submerchant";
export type TabsArrayItem = {
  name: string;
  value: TabNames;
  hidden?: boolean;
};
 
const useAlertsTabs = () => {
  const { isMasqueradeMode, origin } = useMasqueradeReducer();
  const { currentPortal, isEnterprisePortal, isMerchantPortal } =
    checkPortals();
 
  const defaultTab = (
    currentPortal === "provider" ? "enterprise" : currentPortal
  ) as TabNames;
 
  const isOriginAcquirer = origin?.startsWith("/acquirer");
  const isOriginEnterprise = origin?.startsWith("/enterprise");
 
  const tabsMap: Record<TabNames, TabsArrayItem> = {
    acquirer: {
      name: tabsNames.acquirer,
      value: "acquirer",
      hidden: isMasqueradeMode
        ? !isOriginAcquirer
        : isEnterprisePortal || isMerchantPortal,
    },
    enterprise: {
      name: tabsNames.enterprise,
      value: "enterprise",
      hidden: isMasqueradeMode
        ? isOriginAcquirer || isOriginEnterprise
          ? false
          : true
        : isMerchantPortal,
    },
    submerchant: {
      name: tabsNames.submerchant,
      value: "submerchant",
      hidden: false,
    },
  };
 
  const [tab, setTab] = useState<TabsArrayItem>(tabsMap[defaultTab]);
 
  const setActiveTab = (tabName: string) => {
    let t: TabNames = "submerchant";
    Iif (tabName === "acquirer") {
      t = "acquirer";
    } else Iif (tabName === "enterprise") {
      t = "enterprise";
    }
    setTab(tabsMap[t]);
  };
 
  return {
    activeTab: tab,
    setActiveTab,
    tabs: Object.values(tabsMap),
  };
};
 
export default useAlertsTabs;
 
const tabsNames: Record<TabNames, string> = {
  submerchant: "Merchants",
  enterprise: "Providers",
  acquirer: "Acquirer",
};