All files / src/utils routing.ts

100% Statements 48/48
76.92% Branches 10/13
100% Functions 4/4
100% Lines 48/48

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                  447x       6x   15x   6x 5x           6x           447x 28159x 28157x 28157x 28157x 28157x 28157x   28157x 28157x 28157x 28157x   28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x 28157x       28157x     28157x   28157x 28157x 28157x 28157x   28157x 28157x   28157x 28157x 28157x 28157x     28157x             28157x                                                                                
import { useLocation } from "react-router-dom";
 
export type SubPathNameType = {
  pageName?: string;
  path: string;
};
 
//PathArray : table paths portions seperated by /
//subPaths  : an array of multiLevels of given Path ex: merchants/fundraisers/456 => ["merchants", "merchants/fundraisers", "merchants/fundraisers/456"]
export const getSubPathsRoute = (
  pathname: string,
  MapedPathName: Map<string, string>,
) => {
  const pathArray: string[] = pathname
    .split("/")
    .filter((sub_path) => sub_path !== "");
 
  const subPaths: SubPathNameType[] = pathArray.map((_, map_index: number) => {
    return {
      pageName: MapedPathName?.get(_),
      path: pathArray.slice(0, map_index + 1).join("/"),
    };
  });
 
  return {
    pathArray,
    subPaths,
  };
};
 
export const checkPortals = () => {
  const { pathname, search } = useLocation();
  const searchParams = new URLSearchParams(search);
  const hasToken = searchParams.has("token");
  const isEnterprisePortal = pathname.startsWith("/provider");
  const isAcquirerPortal = pathname.startsWith("/acquirer");
  const isMerchantPortal = pathname.startsWith("/merchant");
 
  const isNoSidebar = pathname.includes("advanced-builder");
  const isAcquirerEnterprises = pathname.startsWith("/acquirer/providers");
  const isAcquirerManageMoney = pathname.startsWith("/acquirer/manage-money");
  const isProviderManageMoney = pathname.startsWith("/provider/manage-money");
  const isAcquirerOrProviderManageMoney =
    isAcquirerManageMoney || isProviderManageMoney;
  const isManageMoney = pathname.includes("/manage-money");
  const isEvents = pathname.includes("/events");
  const isSweepStakes = pathname.includes("/sweepstakes");
  const isInvoice = pathname.includes("/invoices");
  const isFundraisers = pathname.includes("/fundraisers");
  const isProducts = pathname.includes("/products");
  const isMembership = pathname.includes("/memberships");
  const isDashBoard = pathname.includes("dashboard");
  const currentPortal = pathname.split("/")[1];
  const isTransfersPage = pathname.includes("/acquirer/transfers");
  const isAnyTransfersPage = pathname.includes("/transfers");
  const isDisputes = pathname.includes("/disputes");
  const isSettlementPage = pathname.includes("settlement");
  const isPayBuilder = pathname.includes("pay_product_builder");
  const isDeveloper = pathname.includes("/developer");
  const isAcquirerCategoryCodes = pathname.includes(
    "/settings/merchant-category-codes",
  );
 
  const isTransactions = pathname.includes("transactions");
  //TODO with the clean up to remove the isProcessing check since we dont have anymore
  const isProcessing =
    isTransactions && (isEnterprisePortal || isAcquirerPortal);
 
  const isSignup = pathname.includes("signup");
  const isTOS = pathname.includes("terms_of_service");
  const isSLA = pathname.includes("service_level_agreement");
  const isPrivacyPolicy = pathname.includes("privacy");
 
  const isMerchantsTable = pathname.includes("/merchants");
  const isEnterpriseTable = pathname.endsWith("/providers");
 
  const isMobileSelfie = pathname.includes("make_selfie");
  const isSetPassword = pathname.includes("set-password");
  const isChangePassword = pathname.includes("change-password");
  const isMobileBankPhoto = hasToken && pathname.includes("bank");
 
  const isAnyPaymentForm =
    isEvents ||
    isSweepStakes ||
    isInvoice ||
    isMembership ||
    isFundraisers ||
    isProducts;
 
  return {
    isChangePassword,
    isSetPassword,
    isEnterprisePortal,
    isAcquirerPortal,
    isMerchantPortal,
    isAcquirerEnterprises,
    isManageMoney,
    isEvents,
    isSweepStakes,
    isInvoice,
    isMembership,
    isFundraisers,
    currentPortal,
    isNoSidebar,
    isDashBoard,
    isAnyTransfersPage,
    isTransfersPage,
    isSettlementPage,
    isMerchantsTable,
    isPayBuilder,
    isDeveloper,
    isEnterpriseTable,
    isSignup,
    isTOS,
    isPrivacyPolicy,
    isAnyPaymentForm,
    isMobileSelfie,
    isMobileBankPhoto,
    isProducts,
    isProcessing,
    isTransactions,
    isAcquirerManageMoney,
    isProviderManageMoney,
    isAcquirerOrProviderManageMoney,
    isDisputes,
    isAcquirerCategoryCodes,
    isSLA,
  };
};