feat(manager): the setup wizard and the shell on v2; all of src on the v2 rules (platform-v2 step 6.14b)
- setup wizard (src/pages/setup): welcome (pick the language: the wizard switches at once), the owner's account, the venue (kind, name, staff language, time zone), an optional lock-screen PIN, finish -> sign in; English and Greek - shell (src/shell): AppLayout (license banner in both languages, header, lock button, idle lock / sign-out), Sidebar on a new 'nav' token set in @xenia/ui (light + dark), ProfileDialog (name, username, password, 4-6 digit PIN), licenseContext; App.jsx loads the session and the setup state with react-query (no setState in effects); the header's dead search box gone - Management -> Tables -> List (src/pages/tables, was TablesConfigTab): zones as tabs (drag to reorder), zone name / prefix / colour, add many numbered on, a table's name (6 chars) / zone / seats, twice-used names flagged, off / on / delete, pick several to move, rename in a series or delete (says how many failed) - the old src/ui kit, layouts/, components/Sidebar + EditProfileModal, the 'primary' palette and the .btn/.card/.input classes deleted; NotificationBell / UserMenuButton on tokens; @xenia/ui: nav tokens, 'scrim' in the Tailwind preset - v2.json paths = src (the guards cover all of it); npm run lint = eslint src; argsIgnorePattern for components in JSX - tests: shell.test.mjs (3), e2e setup.mjs (new: a fresh install through the wizard in Greek to the overview, in run-all), manager.mjs 'tables list' (zone, 3 tables, rename series, profile PIN, rail tokens) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { lazy, Suspense, useEffect, useState } from 'react'
|
||||
import { BrowserRouter, Routes, Route, Navigate, Outlet, useNavigate } from 'react-router-dom'
|
||||
// The manager's routes (plan step 6.14b: the shell on v2). Every page sits in the platform
|
||||
// bootstrap (modules, keys, venue, language: @xenia/access); signed-in pages in the frame
|
||||
// (shell/AppLayout) with the live connection. A fresh install (no manager yet) goes to the setup
|
||||
// wizard; the sign-in page sends you there too.
|
||||
import { lazy, Suspense } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom'
|
||||
import { AccessProvider } from '@xenia/access'
|
||||
import RouteGuard from './shell/RouteGuard'
|
||||
import { createI18n } from '@xenia/i18n'
|
||||
import { Spinner } from '@xenia/ui'
|
||||
import useAuthStore from './store/authStore'
|
||||
import AppLayout from './layouts/AppLayout'
|
||||
import AppLayout from './shell/AppLayout'
|
||||
import LiveProvider from './live/LiveProvider'
|
||||
import client from './api/client'
|
||||
|
||||
// Auth / setup
|
||||
import LoginPage from './pages/LoginPage'
|
||||
import SetupWizard from './pages/SetupWizard'
|
||||
import SetupWizard from './pages/setup/SetupWizard'
|
||||
|
||||
// Operation
|
||||
import OverviewPage from './pages/overview/OverviewPage'
|
||||
@@ -63,37 +68,26 @@ import SettingsPage from './pages/Settings/SettingsPage'
|
||||
import NotesPage from './pages/notes/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).
|
||||
// The language follows bootstrap (user -> venue).
|
||||
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 Loading() {
|
||||
return <div className="min-h-screen bg-canvas grid place-items-center"><Spinner /></div>
|
||||
}
|
||||
|
||||
/** A token kept from an earlier visit: who it belongs to (else it is dropped and you sign in again). */
|
||||
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 />
|
||||
const needed = !!token && !user
|
||||
const { isPending } = useQuery({
|
||||
queryKey: ['auth-me', token], enabled: needed, retry: false, staleTime: Infinity,
|
||||
queryFn: () => client.get('/api/auth/me').then(r => { rehydrate(r.data, token); return r.data }).catch(e => { logout(); throw e }),
|
||||
})
|
||||
if (needed && isPending) return <Loading />
|
||||
return children
|
||||
}
|
||||
|
||||
@@ -102,20 +96,11 @@ function RequireAuth({ children }) {
|
||||
return token ? children : <Navigate to="/login" replace />
|
||||
}
|
||||
|
||||
/** The sign-in page, unless nobody can sign in yet (a fresh install): then the setup wizard. */
|
||||
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 />
|
||||
const { data, isPending } = useQuery({ queryKey: ['setup-status'], retry: false, queryFn: () => client.get('/api/setup/status').then(r => r.data) })
|
||||
if (isPending) return <Loading />
|
||||
if (data?.needs_setup) return <Navigate to="/setup" replace />
|
||||
return children
|
||||
}
|
||||
|
||||
@@ -124,7 +109,7 @@ function SetupGuard({ children }) {
|
||||
function ManagerRoot() {
|
||||
const token = useAuthStore(s => s.token)
|
||||
return (
|
||||
<AccessProvider client={client} token={token} i18n={i18n} loading={<Spinner />}>
|
||||
<AccessProvider client={client} token={token} i18n={i18n} loading={<Loading />}>
|
||||
<AuthRehydrator>
|
||||
<Outlet />
|
||||
</AuthRehydrator>
|
||||
|
||||
Reference in New Issue
Block a user