feat(manager): shell navigation from modules + permission keys; profile menu language
Platform-v2 step 2.6a: - shell/nav.js: one nav definition (module + key per page) read by the sidebar, the page titles and a RouteGuard around the layout outlet (and /kds): a module that's off hides its items and its routes say "turned off"; a missing key hides the item and the route says "no access". Same keys as before (v1 permission names mapped), plus the module check - labels/breadcrumbs are keys in a new i18n namespace `manager` (en + el) - removed the browser-only feature toggles (usePhase2Features, Settings -> Λειτουργίες, F-033), PermissionGuard and usePermissions - profile menu: language, saved to the profile (PATCH /api/auth/me) and bootstrap reloaded - e2e manager.mjs: module off/on, no-key user, language switch live + saved Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import { useAccess } from '@xenia/access'
|
||||
|
||||
// The current screens' permission names -> the v2 keys they stand for (the same pairs as
|
||||
// local_backend/core/access/legacy.py). Removed when the pages use useCan(key) directly (phase 6).
|
||||
const KEYS = {
|
||||
accessDashboard: 'core.dashboard.access',
|
||||
accessWaiterApp: 'waiter_app.access',
|
||||
accessKds: 'kds.access',
|
||||
cancelOrders: 'ordering.orders.cancel',
|
||||
applyDiscounts: 'pricing.discounts.apply',
|
||||
modifyPrices: 'ordering.prices.modify',
|
||||
openOrders: 'ordering.orders.open',
|
||||
closeOrders: 'ordering.orders.close',
|
||||
viewReports: 'reports.view',
|
||||
manageStaff: 'core.staff.manage',
|
||||
manageTables: 'catalog.tables.manage',
|
||||
manageMenu: 'catalog.menu.manage',
|
||||
manageSettings: 'core.settings.manage',
|
||||
}
|
||||
|
||||
/**
|
||||
* The signed-in user's permissions in the shape the current pages use, from the keys in
|
||||
* the platform bootstrap (@xenia/access). A key whose module is off counts as not held.
|
||||
* Superadmin holds every key (the backend sends them all).
|
||||
*/
|
||||
export default function usePermissions() {
|
||||
const { user, permissions } = useAccess()
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
isSuperadmin: false,
|
||||
accessDashboard: false,
|
||||
accessWaiterApp: false,
|
||||
accessKds: false,
|
||||
cancelOrders: false,
|
||||
applyDiscounts: false,
|
||||
modifyPrices: false,
|
||||
openOrders: false,
|
||||
closeOrders: false,
|
||||
viewReports: false,
|
||||
manageStaff: false,
|
||||
manageTables: false,
|
||||
manageMenu: false,
|
||||
manageSettings: false,
|
||||
}
|
||||
}
|
||||
|
||||
const out = { isSuperadmin: user.role === 'superadmin' }
|
||||
for (const [name, key] of Object.entries(KEYS)) out[name] = permissions.has(key)
|
||||
return out
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
const STORAGE_KEY = 'phase2_features'
|
||||
|
||||
// All Phase 2 features with their sidebar metadata.
|
||||
// enabled: true = shown by default (feature is polished)
|
||||
// enabled: false = hidden by default (still in development)
|
||||
export const PHASE2_FEATURE_DEFS = [
|
||||
{ id: 'online-orders', label: 'Online Orders', route: '/online-orders', enabled: true },
|
||||
{ id: 'notes', label: 'Σημειώσεις & Εργασίες', route: '/notes', enabled: true },
|
||||
{ id: 'expenses', label: 'Έξοδα', route: '/expenses', enabled: true },
|
||||
{ id: 'contacts', label: 'Επαφές / Προμηθευτές', route: '/contacts', enabled: true },
|
||||
{ id: 'customers', label: 'Πελάτες', route: '/customers', enabled: true },
|
||||
{ id: 'tabs', label: 'Καρτέλες', route: '/tabs', enabled: true },
|
||||
{ id: 'waste', label: 'Αποβλήτα / Φθορές', route: '/waste', enabled: true },
|
||||
{ id: 'kds', label: 'KDS — Κουζίνα', route: '/kds', enabled: true },
|
||||
{ id: 'schedule', label: 'Πρόγραμμα Βαρδιών', route: '/schedule', enabled: true },
|
||||
]
|
||||
|
||||
function _load() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
return raw ? JSON.parse(raw) : {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function isFeatureEnabled(id) {
|
||||
const overrides = _load()
|
||||
if (id in overrides) return overrides[id]
|
||||
const def = PHASE2_FEATURE_DEFS.find(f => f.id === id)
|
||||
return def ? def.enabled : true
|
||||
}
|
||||
|
||||
export function setFeatureEnabled(id, value) {
|
||||
const overrides = _load()
|
||||
overrides[id] = value
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(overrides))
|
||||
// Notify other components in this tab
|
||||
window.dispatchEvent(new Event('phase2features'))
|
||||
}
|
||||
|
||||
export function usePhase2Features() {
|
||||
const [, tick] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
const handler = () => tick(n => n + 1)
|
||||
window.addEventListener('phase2features', handler)
|
||||
window.addEventListener('storage', handler)
|
||||
return () => {
|
||||
window.removeEventListener('phase2features', handler)
|
||||
window.removeEventListener('storage', handler)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return PHASE2_FEATURE_DEFS.map(f => ({
|
||||
...f,
|
||||
enabled: isFeatureEnabled(f.id),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user