2023-08-10 09:28:10 +02:00
|
|
|
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
|
|
|
|
);
|
2023-08-18 10:40:35 +02:00
|
|
|
const routes = [...adminRoutes];
|
2023-08-10 09:28:10 +02:00
|
|
|
|
2023-08-18 10:40:35 +02:00
|
|
|
if (uiConfig.flags.UNLEASH_CLOUD) {
|
|
|
|
const adminBillingMenuItem = adminRoutes.findIndex(
|
|
|
|
route => route.title === 'Billing & invoices'
|
|
|
|
);
|
|
|
|
routes[adminBillingMenuItem] = {
|
|
|
|
...routes[adminBillingMenuItem],
|
|
|
|
path: '/admin/billing',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return routes
|
2023-08-10 09:28:10 +02:00
|
|
|
.filter(filterByConfig(uiConfig))
|
|
|
|
.filter(route =>
|
|
|
|
filterAdminRoutes(
|
|
|
|
route?.menu,
|
|
|
|
{
|
|
|
|
enterprise: isEnterprise(),
|
|
|
|
pro: isPro(),
|
|
|
|
billing: isBilling,
|
|
|
|
},
|
|
|
|
showEnterpriseOptionsInPro
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.map(mapRouteLink);
|
|
|
|
};
|