1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/frontend/src/component/admin/useAdminRoutes.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { adminRoutes } from './adminRoutes';
import { useInstanceStatus } from 'hooks/api/getters/useInstanceStatus/useInstanceStatus';
import { filterAdminRoutes } from './filterAdminRoutes';
import { filterByConfig, mapRouteLink } from 'component/common/util';
export const useAdminRoutes = () => {
const { uiConfig, isPro, isEnterprise } = useUiConfig();
const { isBilling } = useInstanceStatus();
const showEnterpriseOptionsInPro = Boolean(
uiConfig?.flags?.frontendNavigationUpdate
);
const routes = [...adminRoutes];
if (uiConfig.flags.UNLEASH_CLOUD) {
const adminBillingMenuItem = adminRoutes.findIndex(
route => route.title === 'Billing & invoices'
);
routes[adminBillingMenuItem] = {
...routes[adminBillingMenuItem],
path: '/admin/billing',
};
}
return routes
.filter(filterByConfig(uiConfig))
.filter(route =>
filterAdminRoutes(
route?.menu,
{
enterprise: isEnterprise(),
pro: isPro(),
billing: isBilling,
},
showEnterpriseOptionsInPro
)
)
.map(mapRouteLink);
};