Files
xenia-pos-local/manager_dashboard/src/App.jsx
T
bonaminandClaude Opus 5.5 cc00ec39c7 feat(manager): Devices page — pair by code, app, name, sign-in mode, link, change app, remove
Platform-v2 step 2.6d:
- /devices (core.devices.manage, sidebar): devices from /api/devices with
  status (online / last seen / waiting for the device / app turned off /
  removed), app, sign-in mode (own or venue default), linked device; usage per
  device app against the license limit (devices)
- pair dialog: code as typed (normalized), app (only apps that are on, "all in
  use" when the limit is reached), name, sign-in mode for apps with a choice,
  optional linked device; license.limit_reached explained with the app's limit
- edit (name, sign-in mode, link), change app (signs out whoever is on it),
  remove with confirm (the device goes back to pairing), show removed
- manager_dashboard gets node --test (tests/platform.test.mjs: module states,
  dependents, device status/usage/room/links), added to run-all
- e2e manager.mjs: 54 checks (+ wrong code, normalized code, pair, the device
  picks up its token, online, rename, change app, remove → device.revoked)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 23:22:43 +02:00

205 lines
8.7 KiB
React

import { lazy, Suspense, useEffect, useState } from 'react'
import { BrowserRouter, Routes, Route, Navigate, Outlet, useNavigate } from 'react-router-dom'
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'
import client from './api/client'
// Auth / setup
import LoginPage from './pages/LoginPage'
import SetupWizard from './pages/SetupWizard'
// Standalone (no shell)
import KdsPage from './pages/KdsPage'
// Operation
import DashboardPage from './pages/DashboardPage'
import TablesPage from './pages/TablesPage'
import OrderDetailPage from './pages/OrderDetailPage'
import OnlineOrdersPage from './pages/OnlineOrdersPage'
// CRM
import ContactsPage from './pages/crm/ContactsPage'
import CustomersPage from './pages/crm/CustomersPage'
// Financials
import ExpensesPage from './pages/financials/ExpensesPage'
import TabsPage from './pages/financials/TabsPage'
// Management
import ProductsPage from './pages/Management/ProductsPage'
import TablesConfigPage from './pages/Management/TablesConfigPage'
import StaffPage from './pages/Management/StaffPage'
import ManagementSchedulePage from './pages/Management/SchedulePage'
import PrepZonesConfigPage from './pages/Management/PrepZonesConfigPage'
import PricingPage from './pages/Management/PricingPage'
// Inventory
import ThrowawaysPage from './pages/inventory/ThrowawaysPage'
import StockPage from './pages/inventory/StockPage'
// Reports
import TodayPage from './pages/reports/TodayPage'
import StorePage from './pages/reports/StorePage'
import StaffReportPage from './pages/reports/StaffReportPage'
import ProductsReportPage from './pages/reports/ProductsReportPage'
import PrepZonesPage from './pages/reports/PrepZonesPage'
import ExpensesReportPage from './pages/reports/ExpensesReportPage'
import TechnicalPage from './pages/reports/TechnicalPage'
import MiscPage from './pages/reports/MiscPage'
// Other
import { AppsPage, IntegrationsPage } from './pages/platform/ModulesPage'
import LicensePage from './pages/platform/LicensePage'
import DevicesPage from './pages/platform/DevicesPage'
import PhonePage from './pages/PhonePage'
import SettingsPage from './pages/Settings/SettingsPage'
import NotesPage from './pages/NotesPage'
// 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).
const i18n = createI18n()
// Visual check pages for the shared packages, dev builds only (left out of production bundles)
const UiGallery = import.meta.env.DEV ? lazy(() => import('@xenia/ui/gallery')) : null
const I18nSample = import.meta.env.DEV ? lazy(() => import('@xenia/i18n/sample')) : null
function Spinner() {
return (
<div className="min-h-screen bg-slate-50 flex items-center justify-center">
<div className="w-6 h-6 rounded-full border-2 border-sky-500 border-t-transparent animate-spin" />
</div>
)
}
function AuthRehydrator({ children }) {
const { token, user, rehydrate, logout } = useAuthStore()
const [ready, setReady] = useState(false)
useEffect(() => {
if (token && !user) {
client.get('/api/auth/me')
.then(r => { rehydrate(r.data, token) })
.catch(() => { logout() })
.finally(() => setReady(true))
} else {
setReady(true)
}
}, []) // intentionally runs once on mount
if (!ready) return <Spinner />
return children
}
function RequireAuth({ children }) {
const token = useAuthStore(s => s.token)
return token ? children : <Navigate to="/login" replace />
}
function SetupGuard({ children }) {
const [checked, setChecked] = useState(false)
const navigate = useNavigate()
useEffect(() => {
client.get('/api/setup/status')
.then(({ data }) => {
if (data.needs_setup) navigate('/setup', { replace: true })
})
.catch(() => {})
.finally(() => setChecked(true))
}, [navigate])
if (!checked) return <Spinner />
return children
}
// Platform bootstrap (modules, permission keys, venue, language) for every real page; it
// reloads when the session token changes (login, logout, unlock). @xenia/access, plan step 2.5.
function ManagerRoot() {
const token = useAuthStore(s => s.token)
return (
<AccessProvider client={client} token={token} i18n={i18n} loading={<Spinner />}>
<AuthRehydrator>
<Outlet />
</AuthRehydrator>
</AccessProvider>
)
}
export default function App() {
return (
<BrowserRouter>
<Routes>
{UiGallery && <Route path="/ui-gallery" element={<Suspense fallback={null}><UiGallery /></Suspense>} />}
{I18nSample && <Route path="/i18n-sample" element={<Suspense fallback={null}><I18nSample /></Suspense>} />}
<Route element={<ManagerRoot />}>
<Route path="/setup" element={<SetupWizard />} />
<Route path="/login" element={<SetupGuard><LoginPage /></SetupGuard>} />
<Route path="/kds" element={<RequireAuth><RouteGuard><KdsPage /></RouteGuard></RequireAuth>} />
<Route path="/" element={<RequireAuth><AppLayout /></RequireAuth>}>
<Route index element={<Navigate to="/dashboard" replace />} />
{/* ── Operation ── */}
<Route path="dashboard" element={<DashboardPage />} />
<Route path="tables" element={<TablesPage />} />
<Route path="online-orders" element={<OnlineOrdersPage />} />
<Route path="orders/:orderId" element={<OrderDetailPage />} />
{/* ── CRM ── */}
<Route path="crm/contacts" element={<ContactsPage />} />
<Route path="crm/customers" element={<CustomersPage />} />
{/* ── Financials ── */}
<Route path="financials/expenses" element={<ExpensesPage />} />
<Route path="financials/tabs" element={<TabsPage />} />
{/* ── Management (Headquarters) ── */}
<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={<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="integrations" element={<IntegrationsPage />} />
<Route path="license" element={<LicensePage />} />
<Route path="devices" element={<DevicesPage />} />
<Route path="apps/phone" element={<PhonePage />} />
<Route path="settings" element={<SettingsPage />} />
<Route path="notes" element={<NotesPage />} />
{/* ── Legacy redirects (old URLs → new locations) ── */}
<Route path="contacts" element={<Navigate to="/crm/contacts" replace />} />
<Route path="customers" element={<Navigate to="/crm/customers" replace />} />
<Route path="expenses" element={<Navigate to="/financials/expenses" replace />} />
<Route path="tabs" element={<Navigate to="/financials/tabs" replace />} />
<Route path="waste" element={<Navigate to="/inventory/throwaways" replace />} />
<Route path="schedule" element={<Navigate to="/management/schedule" replace />} />
<Route path="management" element={<Navigate to="/management/products" replace />} />
<Route path="reports" element={<Navigate to="/reports/today" replace />} />
</Route>
</Route>
</Routes>
</BrowserRouter>
)
}