fix: return baseline menu for full-access accounts
Build & Deploy / Build & Push Docker Image (push) Failing after 6m52s
Build & Deploy / Deploy to VPS (push) Has been skipped
Test / Type Check (all packages) (push) Failing after 11s
Test / API Unit Tests (push) Has been skipped
Test / Homepage Unit Tests (push) Has been skipped
Test / Storefront Unit Tests (push) Has been skipped
Test / Admin Unit Tests (push) Has been skipped
Test / Dashboard Unit Tests (push) Has been skipped
Test / API Integration Tests (push) Has been skipped
Build & Deploy / Build & Push Docker Image (push) Failing after 6m52s
Build & Deploy / Deploy to VPS (push) Has been skipped
Test / Type Check (all packages) (push) Failing after 11s
Test / API Unit Tests (push) Has been skipped
Test / Homepage Unit Tests (push) Has been skipped
Test / Storefront Unit Tests (push) Has been skipped
Test / Admin Unit Tests (push) Has been skipped
Test / Dashboard Unit Tests (push) Has been skipped
Test / API Integration Tests (push) Has been skipped
This commit is contained in:
@@ -69,6 +69,17 @@ const MENU_ITEM_TYPES_WITHOUT_ROUTE = new Set([
|
||||
'SECTION_LABEL',
|
||||
'DIVIDER',
|
||||
])
|
||||
const ROLE_RANK: Record<EmployeeRole, number> = { OWNER: 3, MANAGER: 2, AGENT: 1 }
|
||||
const BASELINE_EMPLOYEE_MENU_ITEMS = [
|
||||
{ systemKey: 'dashboard', label: 'Dashboard', routeOrUrl: '/', icon: 'LayoutDashboard', displayOrder: 10, minRole: 'AGENT' },
|
||||
{ systemKey: 'reservations', label: 'Reservations', routeOrUrl: '/reservations', icon: 'Calendar', displayOrder: 20, minRole: 'AGENT' },
|
||||
{ systemKey: 'fleet', label: 'Fleet', routeOrUrl: '/fleet', icon: 'Car', displayOrder: 30, minRole: 'AGENT' },
|
||||
{ systemKey: 'customers', label: 'Customers', routeOrUrl: '/customers', icon: 'Users', displayOrder: 40, minRole: 'AGENT' },
|
||||
{ systemKey: 'reports', label: 'Reports', routeOrUrl: '/reports', icon: 'BarChart2', displayOrder: 50, minRole: 'MANAGER' },
|
||||
{ systemKey: 'billing', label: 'Billing', routeOrUrl: '/billing', icon: 'CreditCard', displayOrder: 60, minRole: 'MANAGER' },
|
||||
{ systemKey: 'settings', label: 'Settings', routeOrUrl: '/settings', icon: 'Settings', displayOrder: 70, minRole: 'OWNER' },
|
||||
] as const
|
||||
const MENU_RECOVERY_ROUTES = new Set(['/subscription', '/subscription/success', '/subscription/cancel'])
|
||||
|
||||
function normalizeNullableString(value?: string | null) {
|
||||
if (typeof value !== 'string') return null
|
||||
@@ -83,6 +94,10 @@ function sortByDisplayOrder<T extends { displayOrder: number; label?: string | n
|
||||
})
|
||||
}
|
||||
|
||||
function hasMinRole(role: EmployeeRole, minRole: EmployeeRole): boolean {
|
||||
return ROLE_RANK[role] >= ROLE_RANK[minRole]
|
||||
}
|
||||
|
||||
function toPlanValue(plan: Plan) {
|
||||
return plan
|
||||
}
|
||||
@@ -579,6 +594,32 @@ function buildMenuTree(items: Array<{
|
||||
return roots
|
||||
}
|
||||
|
||||
function hasFeatureMenuRoute(items: Array<{ itemType: MenuItemType; routeOrUrl: string | null }>) {
|
||||
return items.some((item) => (
|
||||
item.itemType === 'INTERNAL_PAGE' &&
|
||||
item.routeOrUrl &&
|
||||
item.routeOrUrl !== '/' &&
|
||||
!MENU_RECOVERY_ROUTES.has(item.routeOrUrl)
|
||||
))
|
||||
}
|
||||
|
||||
function buildBaselineEmployeeMenu(role: EmployeeRole) {
|
||||
return BASELINE_EMPLOYEE_MENU_ITEMS
|
||||
.filter((item) => hasMinRole(role, item.minRole))
|
||||
.map((item) => ({
|
||||
id: `baseline_${item.systemKey}`,
|
||||
systemKey: item.systemKey,
|
||||
label: item.label,
|
||||
itemType: 'INTERNAL_PAGE' as MenuItemType,
|
||||
routeOrUrl: item.routeOrUrl,
|
||||
icon: item.icon,
|
||||
parentId: null,
|
||||
openInNewTab: false,
|
||||
displayOrder: item.displayOrder,
|
||||
children: [],
|
||||
}))
|
||||
}
|
||||
|
||||
export async function previewCompanyMenu(input: MenuPreviewInput) {
|
||||
const context = await getMenuEvaluationContext(input.companyId, input.role)
|
||||
return {
|
||||
@@ -619,6 +660,23 @@ export async function getEmployeeMenu(employeeId: string) {
|
||||
|
||||
const context = await getMenuEvaluationContext(employee.companyId, employee.role, employee.isActive)
|
||||
const visibleItems = context.items.filter((item) => item.visible)
|
||||
const menuItems = buildMenuTree(
|
||||
visibleItems.map((item) => ({
|
||||
id: item.id,
|
||||
systemKey: item.systemKey,
|
||||
label: item.label,
|
||||
itemType: item.itemType,
|
||||
routeOrUrl: item.routeOrUrl,
|
||||
icon: item.icon,
|
||||
parentId: item.parentId,
|
||||
openInNewTab: item.openInNewTab,
|
||||
displayOrder: item.displayOrder,
|
||||
})),
|
||||
)
|
||||
const resolvedItems =
|
||||
context.subscriptionAccessLevel === 'full' && employee.isActive && !hasFeatureMenuRoute(menuItems)
|
||||
? buildBaselineEmployeeMenu(employee.role)
|
||||
: menuItems
|
||||
|
||||
return {
|
||||
companyId: employee.companyId,
|
||||
@@ -626,19 +684,7 @@ export async function getEmployeeMenu(employeeId: string) {
|
||||
subscriptionPlan: context.currentPlan,
|
||||
subscriptionStatus: context.subscriptionStatus,
|
||||
subscriptionAccessLevel: context.subscriptionAccessLevel,
|
||||
items: buildMenuTree(
|
||||
visibleItems.map((item) => ({
|
||||
id: item.id,
|
||||
systemKey: item.systemKey,
|
||||
label: item.label,
|
||||
itemType: item.itemType,
|
||||
routeOrUrl: item.routeOrUrl,
|
||||
icon: item.icon,
|
||||
parentId: item.parentId,
|
||||
openInNewTab: item.openInNewTab,
|
||||
displayOrder: item.displayOrder,
|
||||
})),
|
||||
),
|
||||
items: resolvedItems,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user