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 | 19x 11x 11x 11x 11x 11x 6x 6x 5x 5x 6x 11x | import { useMemo } from "react";
import { useLocation } from "react-router-dom";
import { getSubPathsRoute } from "@utils/routing";
import { Role, useUser } from "./useUser";
import { MappedPathName } from "@constants/routing";
import { ACQUIRER_PATHS } from "@routes/paths";
import useMasqueradeReducer from "@hooks/Reducers/useMasqueradeReducer";
export const useRouting = () => {
const { pathname } = useLocation();
const { userRole } = useUser();
const { isMasqueradeMode, masqueradeUserRole } = useMasqueradeReducer();
const _useRole = isMasqueradeMode ? masqueradeUserRole : userRole;
const subPathRoutes = useMemo(() => {
const routes = getSubPathsRoute(pathname, MappedPathName[_useRole as Role]);
const formattedSubPaths = routes.subPaths.map((item) => {
Iif (item.pageName === "Products") {
return {
...item,
path: item.path.replace("payment-forms", "products"),
};
}
return item;
});
return {
...routes,
subPaths: formattedSubPaths,
};
}, [pathname, userRole]);
return {
...subPathRoutes,
isSettingsPage: subPathRoutes.pathArray[1] === ACQUIRER_PATHS.SETTINGS,
isBankAccountPage: subPathRoutes.pathArray[2] === "bank-account",
isPermissionsPage: subPathRoutes.pathArray[2] === "permissions",
isLegalDocumentDetailPage:
subPathRoutes.pathArray[2] === "legal-documents" &&
subPathRoutes.pathArray.length > 3,
};
};
|