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:
2026-11-13 21:48:08 +02:00
co-authored by Claude Opus 5.5
parent 78c8824356
commit df57fd1552
15 changed files with 454 additions and 545 deletions
+18 -18
View File
@@ -1,6 +1,7 @@
import { lazy, Suspense, useEffect, useState } from 'react'
import { BrowserRouter, Routes, Route, Navigate, Outlet, useNavigate } from 'react-router-dom'
import { AccessProvider, RequireModule } from '@xenia/access'
import { AccessProvider } from '@xenia/access'
import RouteGuard from './shell/RouteGuard'
import { createI18n } from '@xenia/i18n'
import useAuthStore from './store/authStore'
import AppLayout from './layouts/AppLayout'
@@ -54,7 +55,6 @@ import AppsPage from './pages/AppsPage'
import PhonePage from './pages/PhonePage'
import SettingsPage from './pages/Settings/SettingsPage'
import NotesPage from './pages/NotesPage'
import PermissionGuard from './components/PermissionGuard'
// Texts for the shared parts (approval dialog, "feature off" screens, component labels).
// The language follows bootstrap (user -> venue); the current pages are still Greek (phase 6).
@@ -135,7 +135,7 @@ export default function App() {
<Route element={<ManagerRoot />}>
<Route path="/setup" element={<SetupWizard />} />
<Route path="/login" element={<SetupGuard><LoginPage /></SetupGuard>} />
<Route path="/kds" element={<RequireAuth><RequireModule module="kds"><KdsPage /></RequireModule></RequireAuth>} />
<Route path="/kds" element={<RequireAuth><RouteGuard><KdsPage /></RouteGuard></RequireAuth>} />
<Route path="/" element={<RequireAuth><AppLayout /></RequireAuth>}>
<Route index element={<Navigate to="/dashboard" replace />} />
@@ -155,31 +155,31 @@ export default function App() {
<Route path="financials/tabs" element={<TabsPage />} />
{/* ── Management (Headquarters) ── */}
<Route path="management/products" element={<PermissionGuard perm="manageMenu"><ProductsPage /></PermissionGuard>} />
<Route path="management/tables" element={<PermissionGuard perm="manageTables"><TablesConfigPage /></PermissionGuard>} />
<Route path="management/staff" element={<PermissionGuard perm="manageStaff"><StaffPage /></PermissionGuard>} />
<Route path="management/schedule" element={<PermissionGuard perm="manageStaff"><ManagementSchedulePage /></PermissionGuard>} />
<Route path="management/prep-zones" element={<PermissionGuard perm="manageMenu"><PrepZonesConfigPage /></PermissionGuard>} />
<Route path="management/pricing" element={<PermissionGuard perm="manageMenu"><PricingPage /></PermissionGuard>} />
<Route path="management/products" element={<ProductsPage />} />
<Route path="management/tables" element={<TablesConfigPage />} />
<Route path="management/staff" element={<StaffPage />} />
<Route path="management/schedule" element={<ManagementSchedulePage />} />
<Route path="management/prep-zones" element={<PrepZonesConfigPage />} />
<Route path="management/pricing" element={<PricingPage />} />
{/* ── Inventory ── */}
<Route path="inventory/throwaways" element={<ThrowawaysPage />} />
<Route path="inventory/stock" element={<StockPage />} />
{/* ── Reports (Overwatch) ── */}
<Route path="reports/today" element={<PermissionGuard perm="viewReports"><TodayPage /></PermissionGuard>} />
<Route path="reports/store" element={<PermissionGuard perm="viewReports"><StorePage /></PermissionGuard>} />
<Route path="reports/staff" element={<PermissionGuard perm="viewReports"><StaffReportPage /></PermissionGuard>} />
<Route path="reports/products" element={<PermissionGuard perm="viewReports"><ProductsReportPage /></PermissionGuard>} />
<Route path="reports/prep-zones" element={<PermissionGuard perm="viewReports"><PrepZonesPage /></PermissionGuard>} />
<Route path="reports/expenses" element={<PermissionGuard perm="viewReports"><ExpensesReportPage /></PermissionGuard>} />
<Route path="reports/technical" element={<PermissionGuard perm="viewReports"><TechnicalPage /></PermissionGuard>} />
<Route path="reports/misc" element={<PermissionGuard perm="viewReports"><MiscPage /></PermissionGuard>} />
<Route path="reports/today" element={<TodayPage />} />
<Route path="reports/store" element={<StorePage />} />
<Route path="reports/staff" element={<StaffReportPage />} />
<Route path="reports/products" element={<ProductsReportPage />} />
<Route path="reports/prep-zones" element={<PrepZonesPage />} />
<Route path="reports/expenses" element={<ExpensesReportPage />} />
<Route path="reports/technical" element={<TechnicalPage />} />
<Route path="reports/misc" element={<MiscPage />} />
{/* ── Apps & Settings ── */}
<Route path="apps" element={<AppsPage />} />
<Route path="apps/phone" element={<PhonePage />} />
<Route path="settings" element={<PermissionGuard perm="manageSettings"><SettingsPage /></PermissionGuard>} />
<Route path="settings" element={<SettingsPage />} />
<Route path="notes" element={<NotesPage />} />
{/* ── Legacy redirects (old URLs → new locations) ── */}
@@ -1,25 +0,0 @@
import { ShieldAlert } from 'lucide-react'
import usePermissions from '../hooks/usePermissions'
/**
* Wraps a route element. Renders a 403 screen if the user lacks the required permission.
* Usage: <PermissionGuard perm="viewReports"><TodayPage /></PermissionGuard>
*/
export default function PermissionGuard({ perm, children }) {
const perms = usePermissions()
if (!perms[perm]) {
return (
<div className="flex flex-col items-center justify-center h-full gap-4 text-center p-8">
<ShieldAlert size={48} className="text-red-400" />
<h2 className="text-xl font-semibold text-gray-800">Δεν έχετε πρόσβαση</h2>
<p className="text-gray-500 max-w-sm">
Δεν έχετε τα απαραίτητα δικαιώματα για αυτή τη σελίδα.
Επικοινωνήστε με τον διαχειριστή εάν νομίζετε ότι πρόκειται για λάθος.
</p>
</div>
)
}
return children
}
+71 -182
View File
@@ -1,98 +1,14 @@
import { NavLink, useLocation } from 'react-router-dom'
import { useState, useEffect, useRef } from 'react'
import {
LayoutDashboard, LayoutGrid, ShoppingBag,
BookUser, Users, Receipt, CreditCard,
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
BarChart2, TrendingUp, Users2, ShoppingCart, Tag, Activity, Printer, Ban, Percent, ConciergeBell, FileText,
AppWindow, Settings, ChevronDown, CookingPot, StickyNote,
} from 'lucide-react'
import { useState, useEffect } from 'react'
import { ChevronDown } from 'lucide-react'
import { useAccess } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import { getIncomingOrders } from '../api/client'
import { isFeatureEnabled } from '../hooks/usePhase2Features'
import usePermissions from '../hooks/usePermissions'
import { NAV, NAV_BOTTOM, canSee } from '../shell/nav'
// ─── Nav structure ────────────────────────────────────────────────────────────
// `perm` — key from usePermissions(). If set, item is hidden when user lacks that permission.
function buildNav(pendingCount) {
return [
{
category: 'Operation',
items: [
{ type: 'solo', to: '/dashboard', icon: LayoutDashboard, label: 'Εικόνα' },
{ type: 'solo', to: '/tables', icon: LayoutGrid, label: 'Τραπέζια' },
{ type: 'solo', to: '/online-orders', icon: ShoppingBag, label: 'Online Παραγγ.', badge: pendingCount, phase2: 'online-orders' },
],
},
{
category: 'Financial',
items: [
{
type: 'group', id: 'crm', icon: BookUser, label: 'CRM',
children: [
{ to: '/crm/contacts', icon: BookUser, label: 'Επαφές', phase2: 'contacts' },
{ to: '/crm/customers', icon: Users, label: 'Πελάτες', phase2: 'customers' },
],
},
{
type: 'group', id: 'financials', icon: Receipt, label: 'Οικονομικά',
children: [
{ to: '/financials/expenses', icon: Receipt, label: 'Έξοδα', phase2: 'expenses' },
{ to: '/financials/tabs', icon: CreditCard, label: 'Καρτέλες Πελ.', phase2: 'tabs' },
],
},
],
},
{
category: 'Headquarters',
items: [
{
type: 'group', id: 'management', icon: Package, label: 'Διαχείριση',
children: [
{ to: '/management/products', icon: Package, label: 'Προϊόντα', perm: 'manageMenu' },
{ to: '/management/tables', icon: TableProperties, label: 'Τραπέζια', perm: 'manageTables' },
{ to: '/management/staff', icon: UserCog, label: 'Προσωπικό', perm: 'manageStaff' },
{ to: '/management/schedule', icon: CalendarDays, label: 'Πρόγραμμα', perm: 'manageStaff', phase2: 'schedule' },
{ to: '/management/prep-zones', icon: CookingPot, label: 'Ζώνες Ετοιμασίας', perm: 'manageMenu' },
{ to: '/management/pricing', icon: Percent, label: 'Προσφορές & Τιμές', perm: 'manageMenu' },
{ to: '/notes', icon: StickyNote, label: 'Σημειώσεις' },
],
},
{
type: 'group', id: 'inventory', icon: Boxes, label: 'Αποθήκη',
children: [
{ to: '/inventory/throwaways', icon: Trash2, label: 'Απορρίμματα', phase2: 'waste' },
{ to: '/inventory/stock', icon: Boxes, label: 'Απόθεμα', placeholder: true },
],
},
],
},
{
category: 'Overwatch',
perm: 'viewReports',
items: [
{
type: 'group', id: 'reports', icon: BarChart2, label: 'Αναφορές',
children: [
{ to: '/reports/today', icon: Activity, label: 'Σήμερα' },
{ to: '/reports/store', icon: TrendingUp, label: 'Κατάστημα' },
{ to: '/reports/staff', icon: Users2, label: 'Προσωπικό' },
{ to: '/reports/products', icon: ShoppingCart, label: 'Προϊόντα' },
{ to: '/reports/prep-zones', icon: ConciergeBell, label: 'Ζώνες Ετοιμασίας' },
{ to: '/reports/expenses', icon: FileText, label: 'Έξοδα' },
{ to: '/reports/technical', icon: Printer, label: 'Τεχνικά' },
{ to: '/reports/misc', icon: Tag, label: 'Λοιπά' },
],
},
],
},
]
}
const BOTTOM_ITEMS = [
{ to: '/apps', icon: AppWindow, label: 'Εφαρμογές' },
{ to: '/settings', icon: Settings, label: 'Ρυθμίσεις', perm: 'manageSettings' },
]
// The sidebar is drawn from shell/nav.js: an item shows when its module is on and the user
// holds its key (platform bootstrap, @xenia/access). Plan step 2.6a; this replaces the
// browser-only feature toggles (F-033).
// ─── Helpers ──────────────────────────────────────────────────────────────────
@@ -103,12 +19,13 @@ function isChildActive(children, pathname) {
// ─── Child link ───────────────────────────────────────────────────────────────
function ChildLink({ to, icon: Icon, label, placeholder }) {
const { t } = useTranslation('manager')
if (placeholder) {
return (
<div className="flex items-center gap-2.5 px-3 py-2 mx-2 rounded-md text-[13px] text-primary-400 cursor-default select-none">
<Icon size={14} className="shrink-0 opacity-50" />
<span>{label}</span>
<span className="ml-auto text-[10px] font-semibold bg-primary-700 text-primary-300 px-1.5 py-0.5 rounded">soon</span>
<span>{t(label)}</span>
<span className="ml-auto text-[10px] font-semibold bg-primary-700 text-primary-300 px-1.5 py-0.5 rounded">{t('nav.soon')}</span>
</div>
)
}
@@ -127,7 +44,7 @@ function ChildLink({ to, icon: Icon, label, placeholder }) {
{({ isActive }) => (
<>
<Icon size={14} className="shrink-0" />
<span>{label}</span>
<span>{t(label)}</span>
{isActive && <span className="ml-auto w-1 h-1 rounded-full bg-sky-400 shrink-0" />}
</>
)}
@@ -137,31 +54,23 @@ function ChildLink({ to, icon: Icon, label, placeholder }) {
// ─── Group item (collapsible parent) ─────────────────────────────────────────
function GroupItem({ id, icon: Icon, label, children, openGroup, onToggle, perms }) {
function GroupItem({ group, icon: Icon, label, children, openGroup, onToggle }) {
const { t } = useTranslation('manager')
const location = useLocation()
const hasActive = isChildActive(children, location.pathname)
const isOpen = openGroup === id
// Filter out phase2-gated children and children the user lacks permission for
const visibleChildren = children.filter(c => {
if (c.phase2 && !isFeatureEnabled(c.phase2)) return false
if (c.perm && !perms[c.perm]) return false
return true
})
if (visibleChildren.length === 0) return null
const isOpen = openGroup === group
return (
<div>
<button
onClick={() => onToggle(id)}
onClick={() => onToggle(group)}
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors ` +
(hasActive
? 'text-white bg-primary-700'
: 'text-primary-100 hover:bg-primary-700 hover:text-white')}
>
<Icon size={18} className="shrink-0" />
<span className="flex-1 text-left">{label}</span>
<span className="flex-1 text-left">{t(label)}</span>
<ChevronDown
size={14}
className={`shrink-0 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`}
@@ -170,7 +79,7 @@ function GroupItem({ id, icon: Icon, label, children, openGroup, onToggle, perms
{isOpen && (
<div className="mt-0.5 mb-1 space-y-0.5 py-1 border-l border-primary-600 ml-5">
{visibleChildren.map(child => (
{children.map(child => (
<ChildLink key={child.to} {...child} />
))}
</div>
@@ -182,6 +91,7 @@ function GroupItem({ id, icon: Icon, label, children, openGroup, onToggle, perms
// ─── Solo item (direct link) ──────────────────────────────────────────────────
function SoloItem({ to, icon: Icon, label, badge, onNavigate }) {
const { t } = useTranslation('manager')
return (
<NavLink
to={to}
@@ -200,23 +110,39 @@ function SoloItem({ to, icon: Icon, label, badge, onNavigate }) {
</span>
)}
</div>
<span>{label}</span>
<span>{t(label)}</span>
</NavLink>
)
}
// ─── Sidebar ──────────────────────────────────────────────────────────────────
/** The sections with only what this user may see (empty groups and sections dropped). */
function visibleNav(access) {
return NAV
.map(section => ({
...section,
items: section.items
.map(item => (item.children
? { ...item, children: item.children.filter(c => canSee(c, access)) }
: item))
.filter(item => (item.children ? item.children.length > 0 : canSee(item, access))),
}))
.filter(section => section.items.length > 0)
}
export default function Sidebar() {
const { t } = useTranslation('manager')
const access = useAccess()
const [pendingCount, setPendingCount] = useState(0)
const [openGroup, setOpenGroup] = useState(null)
const [, featTick] = useState(0)
const location = useLocation()
const pollRef = useRef(null)
const perms = usePermissions()
const nav = visibleNav(access)
const onlineOrdersShown = nav.some(s => s.items.some(i => i.badge === 'onlineOrders'))
// Online orders badge polling
// Online orders badge (only while that page is available)
useEffect(() => {
if (!onlineOrdersShown) return undefined
async function fetchPending() {
try {
const { data } = await getIncomingOrders()
@@ -224,28 +150,16 @@ export default function Sidebar() {
} catch { /* non-critical */ }
}
fetchPending()
pollRef.current = setInterval(fetchPending, 20_000)
return () => clearInterval(pollRef.current)
}, [])
// Re-render when feature flags change
useEffect(() => {
const handler = () => featTick(n => n + 1)
window.addEventListener('phase2features', handler)
window.addEventListener('storage', handler)
return () => {
window.removeEventListener('phase2features', handler)
window.removeEventListener('storage', handler)
}
}, [])
const timer = setInterval(fetchPending, 20_000)
return () => clearInterval(timer)
}, [onlineOrdersShown])
// Auto-open the group that contains the active route on location change
useEffect(() => {
const nav = buildNav(0)
for (const section of nav) {
for (const section of NAV) {
for (const item of section.items) {
if (item.type === 'group' && isChildActive(item.children, location.pathname)) {
setOpenGroup(item.id)
if (item.children && isChildActive(item.children, location.pathname)) {
setOpenGroup(item.group)
return
}
}
@@ -260,10 +174,8 @@ export default function Sidebar() {
setOpenGroup(null)
}
const nav = buildNav(pendingCount)
return (
<aside className="flex flex-col bg-primary-800 text-white shrink-0 w-56 h-full sidebar-scroll">
<aside className="flex flex-col bg-primary-800 text-white shrink-0 w-56 h-full sidebar-scroll" data-testid="sidebar">
{/* Brand */}
<div className="flex items-center px-4 py-4 border-b border-primary-700 shrink-0">
<span className="font-bold text-lg tracking-wide">XeniaPOS</span>
@@ -271,58 +183,35 @@ export default function Sidebar() {
{/* Main nav */}
<nav className="flex-1 py-3 px-2 space-y-4">
{nav.map(({ category, perm: sectionPerm, items }) => {
// Hide entire section if user lacks section-level permission
if (sectionPerm && !perms[sectionPerm]) return null
const visibleItems = items.filter(item => {
if (item.type === 'solo') {
if (item.perm && !perms[item.perm]) return false
return !item.phase2 || isFeatureEnabled(item.phase2)
}
if (item.type === 'group') {
const visible = item.children.filter(c => {
if (c.phase2 && !isFeatureEnabled(c.phase2)) return false
if (c.perm && !perms[c.perm]) return false
return true
})
return visible.length > 0
}
return true
})
if (visibleItems.length === 0) return null
return (
<div key={category}>
<div className="flex items-center gap-2 px-3 mb-1.5 select-none" style={{ opacity: 0.45 }}>
<span className="text-[9.5px] font-bold uppercase tracking-widest text-primary-100 whitespace-nowrap">
{category}
</span>
<div className="flex-1" style={{ height: 1, background: 'rgba(255,255,255,0.2)' }} />
</div>
<div className="space-y-0.5">
{visibleItems.map(item =>
item.type === 'solo' ? (
<SoloItem key={item.to} {...item} onNavigate={handleSoloClick} />
) : (
<GroupItem
key={item.id}
{...item}
openGroup={openGroup}
onToggle={handleGroupToggle}
perms={perms}
/>
)
)}
</div>
{nav.map(({ section, items }) => (
<div key={section}>
<div className="flex items-center gap-2 px-3 mb-1.5 select-none" style={{ opacity: 0.45 }}>
<span className="text-[9.5px] font-bold uppercase tracking-widest text-primary-100 whitespace-nowrap">
{t(section)}
</span>
<div className="flex-1" style={{ height: 1, background: 'rgba(255,255,255,0.2)' }} />
</div>
)
})}
<div className="space-y-0.5">
{items.map(item =>
item.children ? (
<GroupItem key={item.group} {...item} openGroup={openGroup} onToggle={handleGroupToggle} />
) : (
<SoloItem
key={item.to}
{...item}
badge={item.badge === 'onlineOrders' ? pendingCount : undefined}
onNavigate={handleSoloClick}
/>
)
)}
</div>
</div>
))}
</nav>
{/* Divider + bottom items */}
<div className="shrink-0 px-2 pb-3 border-t border-primary-700 pt-3 space-y-0.5">
{BOTTOM_ITEMS.filter(item => !item.perm || perms[item.perm]).map(item => (
{NAV_BOTTOM.filter(item => canSee(item, access)).map(item => (
<SoloItem key={item.to} {...item} onNavigate={handleSoloClick} />
))}
</div>
@@ -1,7 +1,20 @@
import { useState, useEffect, useRef } from 'react'
import { ChevronDown, User, LogOut } from 'lucide-react'
import { ChevronDown, User, LogOut, Languages, Check } from 'lucide-react'
import toast from 'react-hot-toast'
import { useAccess } from '@xenia/access'
import { LANGUAGE_NAMES, setUserLanguage, useLanguage, useTranslation } from '@xenia/i18n'
import client from '../api/client'
/**
* The profile menu (plan step 2.6a): edit profile, language, sign out.
* The language changes the screen at once, is saved to the user's profile
* (PATCH /api/auth/me) and then the platform bootstrap is reloaded, so it also
* applies on the next login and in the other apps (D-12).
*/
export default function UserMenuButton({ displayName, onEditProfile, onSignOut }) {
const { t, i18n } = useTranslation('manager')
const { language, languages } = useLanguage()
const { refresh } = useAccess()
const [open, setOpen] = useState(false)
const ref = useRef(null)
@@ -22,32 +35,68 @@ export default function UserMenuButton({ displayName, onEditProfile, onSignOut }
}
}, [open])
async function chooseLanguage(lng) {
setOpen(false)
if (lng === language) return
try {
await setUserLanguage(i18n, lng, { save: l => client.patch('/api/auth/me', { language: l }) })
await refresh()
} catch {
toast.error(t('common:language.notSaved'))
}
}
return (
<div className="relative" ref={ref}>
<button
onClick={() => setOpen(o => !o)}
className="flex items-center gap-1 text-[13px] text-slate-600 font-medium hover:text-slate-900 transition-colors"
aria-haspopup="menu"
aria-expanded={open}
data-testid="user-menu"
>
{displayName}
<ChevronDown className={`h-3.5 w-3.5 text-slate-400 transition-transform ${open ? 'rotate-180' : ''}`} />
</button>
{open && (
<div className="absolute right-0 top-full mt-1.5 w-44 rounded-xl border border-slate-200 bg-white shadow-lg py-1 z-50">
<div className="absolute right-0 top-full mt-1.5 w-52 rounded-xl border border-slate-200 bg-white shadow-lg py-1 z-50" role="menu">
<button
role="menuitem"
onClick={() => { setOpen(false); onEditProfile() }}
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-slate-700 hover:bg-slate-50 transition-colors"
>
<User className="h-3.5 w-3.5 text-slate-400" />
Edit Profile
{t('profile.edit')}
</button>
<div className="my-1 border-t border-slate-100" />
<div className="flex items-center gap-2.5 px-3.5 pt-1.5 pb-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">
<Languages className="h-3.5 w-3.5" />
{t('profile.language')}
</div>
{languages.map(lng => (
<button
key={lng}
role="menuitemradio"
aria-checked={lng === language}
lang={lng}
onClick={() => chooseLanguage(lng)}
className="flex w-full items-center gap-2.5 px-3.5 py-2 pl-9 text-[13px] text-slate-700 hover:bg-slate-50 transition-colors"
>
<span className="flex-1 text-left">{LANGUAGE_NAMES[lng]}</span>
{lng === language && <Check className="h-3.5 w-3.5 text-primary-700" />}
</button>
))}
<div className="my-1 border-t border-slate-100" />
<button
role="menuitem"
onClick={() => { setOpen(false); onSignOut() }}
className="flex w-full items-center gap-2.5 px-3.5 py-2 text-[13px] text-rose-500 hover:bg-rose-50 transition-colors"
>
<LogOut className="h-3.5 w-3.5" />
Sign Out
{t('profile.signOut')}
</button>
</div>
)}
@@ -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),
}))
}
+12 -55
View File
@@ -9,72 +9,29 @@ import UserMenuButton from '../components/UserMenuButton'
import EditProfileModal from '../components/EditProfileModal'
import useLicenseStatus from '../hooks/useLicenseStatus'
import PhoneListener from '../components/PhoneListener'
import { useTranslation } from '@xenia/i18n'
import { pageFor } from '../shell/nav'
import RouteGuard from '../shell/RouteGuard'
export const LicenseContext = createContext(null)
const DIGITS = ['1','2','3','4','5','6','7','8','9','','0','⌫']
// ─── Route → title/breadcrumb map ────────────────────────────────────────────
const ROUTE_META = {
'/dashboard': { title: 'Εικόνα' },
'/tables': { title: 'Τραπέζια' },
'/online-orders': { title: 'Online Παραγγελίες' },
'/crm/contacts': { title: 'Επαφές', crumbs: ['CRM', 'Επαφές'] },
'/crm/customers': { title: 'Πελάτες', crumbs: ['CRM', 'Πελάτες'] },
'/financials/expenses': { title: 'Έξοδα', crumbs: ['Οικονομικά', 'Έξοδα'] },
'/financials/tabs': { title: 'Καρτέλες Πελατών', crumbs: ['Οικονομικά', 'Καρτέλες Πελατών'] },
'/management/products': { title: 'Προϊόντα', crumbs: ['Διαχείριση', 'Προϊόντα'] },
'/management/tables': { title: 'Τραπέζια', crumbs: ['Διαχείριση', 'Τραπέζια'] },
'/management/staff': { title: 'Προσωπικό', crumbs: ['Διαχείριση', 'Προσωπικό'] },
'/management/schedule': { title: 'Πρόγραμμα', crumbs: ['Διαχείριση', 'Πρόγραμμα'] },
'/inventory/throwaways': { title: 'Απορρίμματα', crumbs: ['Αποθήκη', 'Απορρίμματα'] },
'/inventory/stock': { title: 'Απόθεμα', crumbs: ['Αποθήκη', 'Απόθεμα'] },
'/reports/today': { title: 'Σήμερα', crumbs: ['Αναφορές', 'Σήμερα'] },
'/reports/store': { title: 'Κατάστημα', crumbs: ['Αναφορές', 'Κατάστημα'] },
'/reports/staff': { title: 'Προσωπικό', crumbs: ['Αναφορές', 'Προσωπικό'] },
'/reports/products': { title: 'Προϊόντα', crumbs: ['Αναφορές', 'Προϊόντα'] },
'/reports/prep-zones': { title: 'Ζώνες Ετοιμασίας', crumbs: ['Αναφορές', 'Ζώνες Ετοιμασίας'] },
'/reports/expenses': { title: 'Έξοδα', crumbs: ['Αναφορές', 'Έξοδα'] },
'/reports/technical': { title: 'Τεχνικά', crumbs: ['Αναφορές', 'Τεχνικά'] },
'/reports/misc': { title: 'Λοιπά', crumbs: ['Αναφορές', 'Λοιπά'] },
'/apps': { title: 'Εφαρμογές' },
'/apps/phone': { title: 'Τηλέφωνο', crumbs: ['Εφαρμογές', 'Τηλέφωνο'] },
'/settings': { title: 'Ρυθμίσεις' },
'/notes': { title: 'Σημειώσεις' },
}
// ─── Page title / breadcrumb (from shell/nav.js) ─────────────────────────────
function PageTitle() {
const { pathname } = useLocation()
const { t } = useTranslation('manager')
const page = pageFor(pathname)
// Match exact first, then try prefix for dynamic routes like /orders/:id
let meta = ROUTE_META[pathname]
if (!meta && pathname.startsWith('/orders/')) {
meta = { title: 'Order Detail', crumbs: ['Order Detail'] }
}
if (!meta) return <span className="text-[15px] font-semibold text-slate-800">XeniaPOS</span>
if (!meta.crumbs) {
return <span className="text-[15px] font-semibold text-slate-800">{meta.title}</span>
}
if (!page) return <span className="text-[15px] font-semibold text-slate-800">XeniaPOS</span>
if (!page.parent) return <span className="text-[15px] font-semibold text-slate-800">{t(page.label)}</span>
return (
<nav className="flex items-center gap-1.5">
{meta.crumbs.map((crumb, i) => {
const isLast = i === meta.crumbs.length - 1
return (
<span key={i} className="flex items-center gap-1.5">
{i > 0 && <ChevronRight size={13} className="text-slate-300 shrink-0" />}
<span className={isLast
? 'text-[14px] font-semibold text-slate-800'
: 'text-[13px] text-slate-400 font-medium'
}>
{crumb}
</span>
</span>
)
})}
<span className="text-[13px] text-slate-400 font-medium">{t(page.parent)}</span>
<ChevronRight size={13} className="text-slate-300 shrink-0" />
<span className="text-[14px] font-semibold text-slate-800">{t(page.label)}</span>
</nav>
)
}
@@ -408,7 +365,7 @@ export default function AppLayout() {
</header>
<main className="flex-1 overflow-hidden flex flex-col min-h-0">
<Outlet />
<RouteGuard><Outlet /></RouteGuard>
</main>
</div>
@@ -5,7 +5,6 @@ import OperationTab from './tabs/OperationTab'
import PrintFontsTab from './tabs/PrintFontsTab'
import SecurityTab from './tabs/SecurityTab'
import DevelopmentTab from './tabs/DevelopmentTab'
import Phase2FeaturesTab from './tabs/Phase2FeaturesTab'
import FiscalTab from './tabs/FiscalTab'
import { TabGroup } from '../../ui/Tabs'
@@ -16,7 +15,6 @@ const TABS = [
{ id: 'colours', label: 'Εμφάνιση' },
{ id: 'print-fonts', label: 'Εκτύπωση' },
{ id: 'fiscal', label: 'Ταμειακή' },
{ id: 'features', label: 'Λειτουργίες' },
{ id: 'development', label: 'Developer' },
]
@@ -33,7 +31,6 @@ export default function SettingsPage() {
{activeTab === 'colours' && <ColoursTab />}
{activeTab === 'print-fonts' && <PrintFontsTab />}
{activeTab === 'fiscal' && <FiscalTab />}
{activeTab === 'features' && <Phase2FeaturesTab />}
{activeTab === 'development' && <DevelopmentTab />}
</div>
</div>
@@ -1,135 +0,0 @@
import { useState } from 'react'
import { PHASE2_FEATURE_DEFS, isFeatureEnabled, setFeatureEnabled, usePhase2Features } from '../../../hooks/usePhase2Features'
const SECRET = '4034'
function PinGate({ onUnlock }) {
const [pin, setPin] = useState('')
const [error, setError] = useState(false)
function submit() {
if (pin === SECRET) {
onUnlock()
} else {
setError(true)
setPin('')
setTimeout(() => setError(false), 1500)
}
}
return (
<div className="flex flex-col items-center justify-center gap-5 py-16 max-w-xs mx-auto">
<div className="flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-2xl">🔒</div>
<div className="text-center">
<p className="font-semibold text-slate-800">Περιορισμένη πρόσβαση</p>
<p className="text-sm text-slate-400 mt-1">Εισάγετε τον κωδικό για να συνεχίσετε</p>
</div>
<div className="flex flex-col items-center gap-3 w-full">
<input
type="password"
value={pin}
onChange={e => setPin(e.target.value)}
onKeyDown={e => e.key === 'Enter' && submit()}
autoFocus
maxLength={8}
placeholder="••••"
className={`w-full text-center text-xl tracking-[0.4em] border rounded-xl px-4 py-3 outline-none transition-colors ${
error ? 'border-red-400 bg-red-50 text-red-600' : 'border-slate-200 focus:border-sky-400'
}`}
/>
{error && <p className="text-xs text-red-500 font-medium">Λάθος κωδικός</p>}
<button
onClick={submit}
className="w-full rounded-xl bg-slate-900 text-white font-semibold py-2.5 text-sm hover:bg-slate-700 transition-colors"
>
Είσοδος
</button>
</div>
</div>
)
}
function Toggle({ checked, onChange }) {
return (
<button
role="switch"
aria-checked={checked}
onClick={() => onChange(!checked)}
style={{
width: 44, height: 24, borderRadius: 999, border: 'none', cursor: 'pointer',
background: checked ? '#16a34a' : '#d1d5db',
position: 'relative', transition: 'background 150ms', flexShrink: 0,
}}
>
<span style={{
position: 'absolute', top: 3, left: checked ? 23 : 3,
width: 18, height: 18, borderRadius: '50%', background: 'white',
transition: 'left 150ms', boxShadow: '0 1px 3px rgba(0,0,0,0.2)',
}} />
</button>
)
}
export default function Phase2FeaturesTab() {
const [unlocked, setUnlocked] = useState(false)
const features = usePhase2Features()
if (!unlocked) return <PinGate onUnlock={() => setUnlocked(true)} />
const allOn = features.every(f => f.enabled)
const allOff = features.every(f => !f.enabled)
function toggleAll(value) {
PHASE2_FEATURE_DEFS.forEach(f => setFeatureEnabled(f.id, value))
}
return (
<div className="space-y-4 max-w-xl">
<div className="rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 text-xs text-blue-800">
Αυτές οι επιλογές ελέγχουν ποιες σελίδες Phase 2 εμφανίζονται στο πλαϊνό μενού.
Απενεργοποίηση <strong>δεν σβήνει δεδομένα</strong> — απλώς κρύβει τον σύνδεσμο.
Χρήσιμο για να κρατάτε σελίδες σε εξέλιξη κρυφές από πελάτες.
</div>
<div className="card divide-y divide-gray-100">
{/* Master toggle row */}
<div className="flex items-center justify-between gap-4 px-5 py-3 bg-gray-50/60">
<span className="text-sm font-semibold text-gray-600">Όλες οι λειτουργίες</span>
<div className="flex gap-3">
<button
onClick={() => toggleAll(true)}
disabled={allOn}
className="text-xs font-semibold px-3 py-1 rounded-full border border-green-300 text-green-700 hover:bg-green-50 disabled:opacity-40 disabled:cursor-default"
>
Ενεργοποίηση όλων
</button>
<button
onClick={() => toggleAll(false)}
disabled={allOff}
className="text-xs font-semibold px-3 py-1 rounded-full border border-red-300 text-red-600 hover:bg-red-50 disabled:opacity-40 disabled:cursor-default"
>
Απενεργοποίηση όλων
</button>
</div>
</div>
{features.map(f => (
<div key={f.id} className="flex items-center justify-between gap-4 px-5 py-3">
<div>
<p className="text-sm font-medium text-gray-700">{f.label}</p>
<p className="text-xs text-gray-400 mt-0.5 font-mono">{f.route}</p>
</div>
<Toggle
checked={f.enabled}
onChange={val => setFeatureEnabled(f.id, val)}
/>
</div>
))}
</div>
<p className="text-xs text-gray-400">
Οι ρυθμίσεις αποθηκεύονται τοπικά στον browser. Ισχύουν αμέσως χωρίς ανανέωση.
</p>
</div>
)
}
@@ -0,0 +1,21 @@
import { useLocation } from 'react-router-dom'
import { ModuleOff, NoAccess, useAccess } from '@xenia/access'
import { pageFor } from './nav'
/**
* Guards whatever route is showing by its path, with the same rules as the sidebar
* (shell/nav.js): module off → "this feature is turned off"; key missing → "no access".
* Mounted around the layout's <Outlet> (and /kds), so a new page only needs a nav entry.
*/
export default function RouteGuard({ children }) {
const { pathname } = useLocation()
const { modules, permissions } = useAccess()
const page = pageFor(pathname)
if (page?.module && !modules.has(page.module)) return <Centered><ModuleOff /></Centered>
if (page?.perm && !permissions.has(page.perm)) return <Centered><NoAccess /></Centered>
return children
}
function Centered({ children }) {
return <div className="flex h-full min-h-[50vh] items-center justify-center p-8" data-testid="route-guard">{children}</div>
}
+127
View File
@@ -0,0 +1,127 @@
// The manager's navigation (plan step 2.6a): ONE definition read by the sidebar, the page
// titles and the route guards, so an item a user can't see is also a route they can't open.
//
// Every page names
// module the backend module its API belongs to (local_backend/modules/<key>/manifest.py);
// if the module is off or not licensed, the item is hidden and the route shows
// "this feature is turned off"
// perm the permission key it needs. Same rules as before platform v2: the old
// permission names map to keys (core/access/legacy.py); pages that had no
// permission need core.dashboard.access (what their APIs check, require_manager).
// Finer keys (pricing.manage, expenses.manage…) replace these when phase 6
// converts those routers.
// label a key in the i18n `manager` namespace
import {
LayoutDashboard, LayoutGrid, ShoppingBag,
BookUser, Users, Receipt, CreditCard,
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
BarChart2, TrendingUp, Users2, ShoppingCart, Tag, Activity, Printer, ConciergeBell, FileText,
AppWindow, Settings, CookingPot, StickyNote, Percent,
} from 'lucide-react'
const DASH = 'core.dashboard.access'
export const NAV = [
{
section: 'nav.sections.operation',
items: [
{ to: '/dashboard', icon: LayoutDashboard, label: 'nav.dashboard', module: 'core', perm: DASH },
{ to: '/tables', icon: LayoutGrid, label: 'nav.tables', module: 'ordering', perm: DASH },
{ to: '/online-orders', icon: ShoppingBag, label: 'nav.onlineOrders', module: 'connect_orders', perm: DASH, badge: 'onlineOrders' },
],
},
{
section: 'nav.sections.financial',
items: [
{
group: 'crm', icon: BookUser, label: 'nav.crm',
children: [
{ to: '/crm/contacts', icon: BookUser, label: 'nav.contacts', module: 'expenses', perm: DASH },
{ to: '/crm/customers', icon: Users, label: 'nav.customers', module: 'crm', perm: DASH },
],
},
{
group: 'financials', icon: Receipt, label: 'nav.finance',
children: [
{ to: '/financials/expenses', icon: Receipt, label: 'nav.expenses', module: 'expenses', perm: DASH },
{ to: '/financials/tabs', icon: CreditCard, label: 'nav.tabs', module: 'tabs', perm: DASH },
],
},
],
},
{
section: 'nav.sections.headquarters',
items: [
{
group: 'management', icon: Package, label: 'nav.management',
children: [
{ to: '/management/products', icon: Package, label: 'nav.products', module: 'catalog', perm: 'catalog.menu.manage' },
{ to: '/management/tables', icon: TableProperties, label: 'nav.tablesConfig', module: 'catalog', perm: 'catalog.tables.manage' },
{ to: '/management/staff', icon: UserCog, label: 'nav.staff', module: 'core', perm: 'core.staff.manage' },
{ to: '/management/schedule', icon: CalendarDays, label: 'nav.schedule', module: 'staff_planning', perm: 'core.staff.manage' },
{ to: '/management/prep-zones', icon: CookingPot, label: 'nav.prepZones', module: 'catalog', perm: 'catalog.menu.manage' },
{ to: '/management/pricing', icon: Percent, label: 'nav.pricing', module: 'pricing', perm: 'catalog.menu.manage' },
{ to: '/notes', icon: StickyNote, label: 'nav.notes', module: 'notes', perm: DASH },
],
},
{
group: 'inventory', icon: Boxes, label: 'nav.inventory',
children: [
{ to: '/inventory/throwaways', icon: Trash2, label: 'nav.waste', module: 'inventory', perm: DASH },
{ to: '/inventory/stock', icon: Boxes, label: 'nav.stock', module: 'inventory', perm: DASH, placeholder: true },
],
},
],
},
{
section: 'nav.sections.overwatch',
items: [
{
group: 'reports', icon: BarChart2, label: 'nav.reports',
children: [
{ to: '/reports/today', icon: Activity, label: 'nav.reportsToday', module: 'reports', perm: 'reports.view' },
{ to: '/reports/store', icon: TrendingUp, label: 'nav.reportsStore', module: 'reports', perm: 'reports.view' },
{ to: '/reports/staff', icon: Users2, label: 'nav.reportsStaff', module: 'reports', perm: 'reports.view' },
{ to: '/reports/products', icon: ShoppingCart, label: 'nav.reportsProducts', module: 'reports', perm: 'reports.view' },
{ to: '/reports/prep-zones', icon: ConciergeBell, label: 'nav.reportsPrepZones', module: 'reports', perm: 'reports.view' },
{ to: '/reports/expenses', icon: FileText, label: 'nav.reportsExpenses', module: 'reports', perm: 'reports.view' },
{ to: '/reports/technical', icon: Printer, label: 'nav.reportsTechnical', module: 'reports', perm: 'reports.view' },
{ to: '/reports/misc', icon: Tag, label: 'nav.reportsMisc', module: 'reports', perm: 'reports.view' },
],
},
],
},
]
export const NAV_BOTTOM = [
{ to: '/apps', icon: AppWindow, label: 'nav.apps', module: 'core', perm: DASH },
{ to: '/settings', icon: Settings, label: 'nav.settings', module: 'core', perm: 'core.settings.manage' },
]
// Pages that aren't in the sidebar but still have a title and a guard
const EXTRA = [
{ to: '/apps/phone', label: 'nav.phone', parent: 'nav.apps', module: 'caller_id', perm: DASH },
{ to: '/kds', label: 'nav.kds', module: 'kds', perm: DASH },
{ prefix: '/orders/', label: 'nav.order', module: 'ordering', perm: DASH },
]
/** Every page: { to | prefix, label, parent (group label) , module, perm } */
export const PAGES = [
...NAV.flatMap(s => s.items.flatMap(item => (item.children
? item.children.map(c => ({ ...c, parent: item.label }))
: [item]))),
...NAV_BOTTOM,
...EXTRA,
]
/** The page entry for a path (exact first, then prefix pages like /orders/:id). */
export function pageFor(pathname) {
return PAGES.find(p => p.to === pathname) || PAGES.find(p => p.prefix && pathname.startsWith(p.prefix)) || null
}
/** Can this user see this page? modules / permissions are the Sets from useAccess(). */
export function canSee(page, { modules, permissions }) {
if (!page) return true
if (page.module && !modules.has(page.module)) return false
return !page.perm || permissions.has(page.perm)
}
+50
View File
@@ -0,0 +1,50 @@
{
"nav": {
"sections": {
"operation": "Λειτουργία",
"financial": "Οικονομικά",
"headquarters": "Διοίκηση",
"overwatch": "Εποπτεία"
},
"dashboard": "Εικόνα",
"tables": "Τραπέζια",
"onlineOrders": "Online παραγγελίες",
"crm": "CRM",
"contacts": "Επαφές",
"customers": "Πελάτες",
"finance": "Οικονομικά",
"expenses": "Έξοδα",
"tabs": "Καρτέλες πελατών",
"management": "Διαχείριση",
"products": "Προϊόντα",
"tablesConfig": "Τραπέζια",
"staff": "Προσωπικό",
"schedule": "Πρόγραμμα",
"prepZones": "Ζώνες ετοιμασίας",
"pricing": "Προσφορές & τιμές",
"notes": "Σημειώσεις",
"inventory": "Αποθήκη",
"waste": "Απορρίμματα",
"stock": "Απόθεμα",
"reports": "Αναφορές",
"reportsToday": "Σήμερα",
"reportsStore": "Κατάστημα",
"reportsStaff": "Προσωπικό",
"reportsProducts": "Προϊόντα",
"reportsPrepZones": "Ζώνες ετοιμασίας",
"reportsExpenses": "Έξοδα",
"reportsTechnical": "Τεχνικά",
"reportsMisc": "Λοιπά",
"apps": "Εφαρμογές",
"phone": "Τηλέφωνο",
"settings": "Ρυθμίσεις",
"order": "Παραγγελία",
"kds": "Οθόνη κουζίνας",
"soon": "σύντομα"
},
"profile": {
"edit": "Επεξεργασία προφίλ",
"signOut": "Αποσύνδεση",
"language": "Γλώσσα"
}
}
+50
View File
@@ -0,0 +1,50 @@
{
"nav": {
"sections": {
"operation": "Operation",
"financial": "Finance",
"headquarters": "Headquarters",
"overwatch": "Overview"
},
"dashboard": "Overview",
"tables": "Tables",
"onlineOrders": "Online orders",
"crm": "CRM",
"contacts": "Contacts",
"customers": "Customers",
"finance": "Finance",
"expenses": "Expenses",
"tabs": "Customer tabs",
"management": "Management",
"products": "Products",
"tablesConfig": "Tables",
"staff": "Staff",
"schedule": "Schedule",
"prepZones": "Prep zones",
"pricing": "Offers & pricing",
"notes": "Notes",
"inventory": "Inventory",
"waste": "Waste",
"stock": "Stock",
"reports": "Reports",
"reportsToday": "Today",
"reportsStore": "Venue",
"reportsStaff": "Staff",
"reportsProducts": "Products",
"reportsPrepZones": "Prep zones",
"reportsExpenses": "Expenses",
"reportsTechnical": "Technical",
"reportsMisc": "Other",
"apps": "Apps",
"phone": "Phone",
"settings": "Settings",
"order": "Order",
"kds": "Kitchen display",
"soon": "soon"
},
"profile": {
"edit": "Edit profile",
"signOut": "Sign out",
"language": "Language"
}
}
+7 -5
View File
@@ -1,18 +1,20 @@
// Every locale file, bundled (they're small; no loading step, no flash of keys).
// Layout (APPS_PLATFORM §8): locales/<lang>/<namespace>.json. English is the source.
// Namespaces: common (shared words, component labels), errors (backend error codes,
// local_backend/core/errors.py; tests/errors.test.mjs keeps them complete), dev (sample screens). Apps add
// theirs here as they're converted: manager, waiter, terminal, modules.
// local_backend/core/errors.py; tests/errors.test.mjs keeps them complete), manager (the manager shell, 2.6),
// dev (sample screens). Apps add theirs here as they're converted: waiter, terminal, modules.
import elCommon from '../locales/el/common.json'
import elDev from '../locales/el/dev.json'
import elErrors from '../locales/el/errors.json'
import elManager from '../locales/el/manager.json'
import enCommon from '../locales/en/common.json'
import enDev from '../locales/en/dev.json'
import enErrors from '../locales/en/errors.json'
import enManager from '../locales/en/manager.json'
export const NAMESPACES = ['common', 'errors', 'dev']
export const NAMESPACES = ['common', 'errors', 'manager', 'dev']
export const resources = {
en: { common: enCommon, errors: enErrors, dev: enDev },
el: { common: elCommon, errors: elErrors, dev: elDev },
en: { common: enCommon, errors: enErrors, manager: enManager, dev: enDev },
el: { common: elCommon, errors: elErrors, manager: elManager, dev: elDev },
}
+45 -6
View File
@@ -1,4 +1,5 @@
// Manager suite (Playwright + Edge): the manager on the shared packages (plan step 2.5).
// Manager suite (Playwright + Edge): the manager on the shared packages (plan steps 2.5, 2.6).
// The demo venue has no venue.language set, so the shell starts in English.
// Starts a backend on a demo-seeded database (:8057, licensing off) and the manager's Vite
// dev server (:5186) proxied to it. Checks login and the platform bootstrap through
// @xenia/api + @xenia/access, the 401 rules (wrong password / wrong PIN stay on screen, an
@@ -70,11 +71,41 @@ try {
await sleep(1500)
r.check('login → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
r.check('bootstrap reloaded with the session token', bootstraps.some(b => b.startsWith('Bearer ')), bootstraps.join(','))
r.check('sidebar built from bootstrap permissions (Διαχείριση, Αναφορές)',
await page.getByText('Διαχείριση').count() > 0 && await page.getByText('Αναφορές').count() > 0)
const sidebar = page.getByTestId('sidebar')
r.check('sidebar built from modules + keys (Management, Reports)',
await sidebar.getByText('Management').count() > 0 && await sidebar.getByText('Reports').count() > 0)
await page.goto(`${APP}/management/products`)
await sleep(1500)
r.check('a PermissionGuard page renders for the manager', await page.getByText('Δεν έχετε πρόσβαση').count() === 0 && (await page.evaluate(() => document.body.innerText.length)) > 200)
r.check('a guarded page renders for the manager', await page.getByTestId('route-guard').count() === 0 && (await page.evaluate(() => document.body.innerText.length)) > 200)
r.check('page title from the nav (Management › Products)', (await page.locator('header nav').first().innerText()).replace(/\s+/g, ' ').includes('Management Products'))
// ── 2.6a: a module turned off disappears from the sidebar and its route ────
const mgrNotes = await page.evaluate(() => localStorage.getItem('manager_token'))
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: false } })
await page.goto(`${APP}/notes`)
await sleep(2000)
await sidebar.getByText('Management').click().catch(() => {})
r.check('notes off: no "Notes" in the sidebar', await sidebar.getByText('Notes', { exact: true }).count() === 0)
r.check('notes off: /notes shows "turned off"', await page.getByTestId('route-guard').getByText('This feature is turned off').count() === 1)
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: true } })
await page.goto(`${APP}/notes`)
await sleep(2000)
r.check('notes on again: the page and the item are back', await page.getByTestId('route-guard').count() === 0 && await sidebar.getByText('Notes', { exact: true }).count() === 1)
// ── 2.6a: the profile menu language switch (live, then saved) ──────────────
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Διαχείριση'), null, { timeout: 5000 }).catch(() => {})
r.check('language → Ελληνικά: the shell changes live', await sidebar.getByText('Διαχείριση').count() > 0 && await page.evaluate(() => document.documentElement.lang) === 'el')
await page.reload()
await sleep(2500)
r.check('…and it was saved (still Greek after a reload)', await sidebar.getByText('Διαχείριση').count() > 0)
await page.getByTestId('user-menu').click()
await page.getByRole('menuitemradio', { name: 'English' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Management'), null, { timeout: 5000 }).catch(() => {})
r.check('language → English again', await sidebar.getByText('Management').count() > 0)
// ── Lock screen: a wrong PIN stays locked (no logout), the right one unlocks ─
await page.goto(`${APP}/dashboard`)
@@ -104,8 +135,8 @@ try {
await page.goto(`${APP}/dashboard`)
await sleep(1500)
await api('POST', '/api/auth/logout', { token: mgr })
await page.getByText('Αναφορές').first().click()
await page.getByText('Σήμερα').first().click()
await sidebar.getByText('Reports').first().click()
await sidebar.getByText('Today').first().click()
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
r.check('session ended → back to /login, token cleared',
new URL(page.url()).pathname === '/login' && !(await page.evaluate(() => localStorage.getItem('manager_token'))), page.url())
@@ -124,6 +155,14 @@ try {
await w.evaluate(t => { localStorage.setItem('manager_token', t); localStorage.setItem('manager_username', 'demo_maria') }, waiter)
await w.goto(`${APP}/dashboard`)
await sleep(2500)
// ── 2.6a: a user without the keys: no item, and "no access" on the URL ─────
const wSidebar = w.getByTestId('sidebar')
r.check('waiter in the manager: no Reports / Management items', await wSidebar.getByText('Reports').count() === 0 && await wSidebar.getByText('Management').count() === 0)
await w.goto(`${APP}/reports/today`)
await sleep(2000)
r.check('waiter opens /reports/today by URL → "no access"', await w.getByTestId('route-guard').getByText("You don't have access to this page").count() === 1)
await w.goto(`${APP}/dashboard`)
await sleep(2000)
await w.evaluate(id => {
window.__res = window.__xeniaClient.delete(`/api/orders/${id}`) // cancel the whole order
.then(res => ({ ok: true, status: res.status }), e => ({ ok: false, code: e.xenia?.code, cancelled: !!e.xenia?.overrideCancelled }))