diff --git a/manager_dashboard/src/App.jsx b/manager_dashboard/src/App.jsx index 1e95b9f..809e902 100644 --- a/manager_dashboard/src/App.jsx +++ b/manager_dashboard/src/App.jsx @@ -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() { }> } /> } /> - } /> + } /> }> } /> @@ -155,31 +155,31 @@ export default function App() { } /> {/* ── Management (Headquarters) ── */} - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> {/* ── Inventory ── */} } /> } /> {/* ── Reports (Overwatch) ── */} - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> {/* ── Apps & Settings ── */} } /> } /> - } /> + } /> } /> {/* ── Legacy redirects (old URLs → new locations) ── */} diff --git a/manager_dashboard/src/components/PermissionGuard.jsx b/manager_dashboard/src/components/PermissionGuard.jsx deleted file mode 100644 index 1adcfe9..0000000 --- a/manager_dashboard/src/components/PermissionGuard.jsx +++ /dev/null @@ -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: - */ -export default function PermissionGuard({ perm, children }) { - const perms = usePermissions() - - if (!perms[perm]) { - return ( -
- -

Δεν έχετε πρόσβαση

-

- Δεν έχετε τα απαραίτητα δικαιώματα για αυτή τη σελίδα. - Επικοινωνήστε με τον διαχειριστή εάν νομίζετε ότι πρόκειται για λάθος. -

-
- ) - } - - return children -} diff --git a/manager_dashboard/src/components/Sidebar.jsx b/manager_dashboard/src/components/Sidebar.jsx index 044b413..ed0d420 100644 --- a/manager_dashboard/src/components/Sidebar.jsx +++ b/manager_dashboard/src/components/Sidebar.jsx @@ -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 (
- {label} - soon + {t(label)} + {t('nav.soon')}
) } @@ -127,7 +44,7 @@ function ChildLink({ to, icon: Icon, label, placeholder }) { {({ isActive }) => ( <> - {label} + {t(label)} {isActive && } )} @@ -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 (
@@ -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 ( )} - {label} + {t(label)} ) } // ─── 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 ( -