feat: foundations for the manager conversion (platform-v2 step 6.1)

- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes,
  texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read;
  bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions.
- Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them,
  tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make
  set-state-in-effect an error.
- src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now
  uses it.
- Dead manager files removed (3.1k lines unreachable from main.jsx).
- Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live
  bell check passed on a rerun).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 04:31:36 +02:00
co-authored by Claude Opus 5.5
parent 218a6c9c5e
commit 2dc5da446e
48 changed files with 918 additions and 3498 deletions
@@ -1,14 +0,0 @@
export default function ConfirmModal({ title, message, confirmLabel = 'Επιβεβαίωση', confirmClass = 'btn-danger', onConfirm, onCancel }) {
return (
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4">
<div className="bg-white rounded-2xl shadow-xl w-full max-w-sm p-6 space-y-4">
<h2 className="text-lg font-bold text-gray-800">{title}</h2>
{message && <p className="text-gray-600 text-sm">{message}</p>}
<div className="flex gap-3 pt-2">
<button onClick={onCancel} className="flex-1 btn btn-secondary">Ακύρωση</button>
<button onClick={onConfirm} className={`flex-1 btn ${confirmClass}`}>{confirmLabel}</button>
</div>
</div>
</div>
)
}
@@ -1,79 +0,0 @@
/**
* DateInput / DateTimeInput
*
* Native date pickers display in the OS/browser locale (MM/DD/YYYY on en-US).
* These wrappers overlay the native input with a visible DD/MM/YYYY display
* while keeping the full native picker UX (click, keyboard, mobile wheel).
*
* Props mirror a plain <input>: value (YYYY-MM-DD or YYYY-MM-DDTHH:MM),
* onChange (receives the same synthetic event), className.
*/
import { useRef } from 'react'
function formatDateGR(value) {
// value is "YYYY-MM-DD"
if (!value) return ''
const [y, m, d] = value.split('-')
if (!y || !m || !d) return value
return `${d}/${m}/${y}`
}
function formatDateTimeGR(value) {
// value is "YYYY-MM-DDTHH:MM"
if (!value) return ''
const [datePart, timePart] = value.split('T')
if (!datePart) return value
const [y, m, d] = datePart.split('-')
if (!y || !m || !d) return value
return `${d}/${m}/${y}${timePart ? ' ' + timePart : ''}`
}
export function DateInput({ value, onChange, className = '', ...rest }) {
const ref = useRef(null)
return (
<div
className={`relative cursor-pointer ${className}`}
onClick={() => ref.current?.showPicker?.()}
>
{/* Visible display */}
<div className="absolute inset-0 flex items-center px-3 pointer-events-none z-10 bg-white rounded-lg text-sm text-gray-800">
{value ? formatDateGR(value) : <span className="text-gray-400">ΗΗ/ΜΜ/ΕΕΕΕ</span>}
</div>
{/* Native input — invisible but functional (provides the picker) */}
<input
ref={ref}
type="date"
value={value}
onChange={onChange}
className="opacity-0 w-full h-full absolute inset-0 cursor-pointer"
tabIndex={0}
{...rest}
/>
</div>
)
}
export function DateTimeInput({ value, onChange, className = '', ...rest }) {
const ref = useRef(null)
return (
<div
className={`relative cursor-pointer ${className}`}
onClick={() => ref.current?.showPicker?.()}
>
<div className="absolute inset-0 flex items-center px-3 pointer-events-none z-10 bg-white rounded-lg text-sm text-gray-800">
{value ? formatDateTimeGR(value) : <span className="text-gray-400">ΗΗ/ΜΜ/ΕΕΕΕ ΩΩ:ΛΛ</span>}
</div>
<input
ref={ref}
type="datetime-local"
value={value}
onChange={onChange}
className="opacity-0 w-full h-full absolute inset-0 cursor-pointer"
tabIndex={0}
{...rest}
/>
</div>
)
}
@@ -1,18 +0,0 @@
const MAP = {
free: { label: 'Ελεύθερο', cls: 'bg-gray-100 text-gray-600' },
open: { label: 'Ανοιχτό', cls: 'bg-green-100 text-green-700' },
partially_paid: { label: 'Μερική πληρωμή', cls: 'bg-amber-100 text-amber-700' },
paid: { label: 'Πληρώθηκε', cls: 'bg-blue-100 text-blue-700' },
closed: { label: 'Κλειστό', cls: 'bg-gray-200 text-gray-500' },
cancelled: { label: 'Ακυρώθηκε', cls: 'bg-red-100 text-red-600' },
active: { label: 'Ενεργό', cls: 'bg-green-100 text-green-700' },
}
export default function StatusBadge({ status }) {
const { label, cls } = MAP[status] ?? { label: status, cls: 'bg-gray-100 text-gray-600' }
return (
<span className={`inline-block text-xs font-semibold px-2 py-0.5 rounded-full ${cls}`}>
{label}
</span>
)
}
@@ -0,0 +1,38 @@
// A page's server data that stays current by itself (plan step 6.1): react-query loads it
// (cached between visits, no flash of a spinner when coming back, one request for several
// readers), and the live events that change it invalidate it. After every (re)connect the
// 'ready' event refreshes it too, so a page never shows what happened while it was offline.
//
// const { data, error, isPending, refetch } = useLiveQuery({
// queryKey: ['sessions', { showEnded }],
// queryFn: () => client.get('/api/auth/sessions', { params: { include_ended: showEnded } }).then(r => r.data),
// events: ['session.changed'], // optional: live event types that change this data
// refetchInterval: 30_000, // optional: for data no event tells about
// })
//
// After a change the page itself made, call `refetch()` (or invalidate the key).
import { useContext, useEffect, useRef } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { LiveContext } from './context'
/** Run `handler(type, data)` for each live event of any of `types`. */
export function useLiveEvents(types, handler) {
const live = useContext(LiveContext)
const ref = useRef(handler)
useEffect(() => { ref.current = handler }, [handler])
const key = types.join('|')
useEffect(() => {
if (!live || !key) return undefined
const offs = key.split('|').map(type => live.subscribe(type, data => ref.current?.(type, data)))
return () => offs.forEach(off => off?.())
}, [live, key])
}
export function useLiveQuery({ queryKey, queryFn, events = [], ...options }) {
const qc = useQueryClient()
const query = useQuery({ queryKey, queryFn, ...options })
const keyRef = useRef(queryKey)
useEffect(() => { keyRef.current = queryKey })
useLiveEvents([...events, 'ready'], () => { qc.invalidateQueries({ queryKey: keyRef.current }) })
return query
}
@@ -1,27 +0,0 @@
import { useState } from 'react'
import { ShoppingBag, LayoutGrid, Users } from 'lucide-react'
import ProductsTab from './Management/ProductsTab'
import TablesConfigTab from './TablesConfigTab'
import StaffTab from './StaffTab'
import { TabGroup } from '../ui/Tabs'
const TABS = [
{ id: 'products', label: 'Προϊόντα', icon: ShoppingBag },
{ id: 'tables', label: 'Τραπέζια', icon: LayoutGrid },
{ id: 'staff', label: 'Προσωπικό', icon: Users },
]
export default function ManagementPage() {
const [activeTab, setActiveTab] = useState('products')
return (
<div className="flex flex-col h-full min-h-0">
<TabGroup tabs={TABS} active={activeTab} onChange={setActiveTab} />
<div className="flex-1 min-h-0">
{activeTab === 'products' && <ProductsTab />}
{activeTab === 'tables' && <TablesConfigTab />}
{activeTab === 'staff' && <StaffTab />}
</div>
</div>
)
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,105 +0,0 @@
import { useState } from 'react'
import { Users, Utensils, Printer } from 'lucide-react'
import { TabGroup, TabBar } from '../../ui/Tabs'
// Staff Analytics
import ShiftsOverview from './staff/ShiftsOverview'
import Payments from './staff/Payments'
import Activity from './staff/Activity'
import StaffLeaderboard from './staff/StaffLeaderboard'
// Restaurant Performance
import Today from './restaurant/Today'
import WorkDaySummary from './restaurant/WorkDaySummary'
import OrderHistory from './restaurant/OrderHistory'
import ProductPerformance from './restaurant/ProductPerformance'
import CategoryPerformance from './restaurant/CategoryPerformance'
import TrafficAnalytics from './restaurant/TrafficAnalytics'
import RevenueTrends from './restaurant/RevenueTrends'
import TableAnalytics from './restaurant/TableAnalytics'
// Operations
import PrinterHistory from './operations/PrinterHistory'
import PrinterHealthLog from './operations/PrinterHealthLog'
import CancellationsLog from './operations/CancellationsLog'
import DiscountsLog from './operations/DiscountsLog'
const PARENT_TABS = [
{
id: 'staff',
label: 'Ανάλυση Προσωπικού',
icon: Users,
subTabs: [
{ id: 'shifts', label: 'Βάρδιες', Component: ShiftsOverview },
{ id: 'payments', label: 'Πληρωμές', Component: Payments },
{ id: 'activity', label: 'Δραστηριότητα', Component: Activity },
{ id: 'leaderboard', label: 'Κατάταξη', Component: StaffLeaderboard },
],
},
{
id: 'restaurant',
label: 'Απόδοση Καταστήματος',
icon: Utensils,
subTabs: [
{ id: 'today', label: 'Σήμερα', Component: Today },
{ id: 'workday', label: 'Ημέρες Λειτουργίας', Component: WorkDaySummary },
{ id: 'orders', label: 'Ιστορικό Παραγγελιών', Component: OrderHistory },
{ id: 'products', label: 'Απόδοση Προϊόντων', Component: ProductPerformance },
{ id: 'categories', label: 'Κατηγορίες', Component: CategoryPerformance },
{ id: 'traffic', label: 'Κίνηση', Component: TrafficAnalytics },
{ id: 'trends', label: 'Τάσεις Εσόδων', Component: RevenueTrends },
{ id: 'tables', label: 'Τραπέζια', Component: TableAnalytics },
],
},
{
id: 'ops',
label: 'Λειτουργίες',
icon: Printer,
subTabs: [
{ id: 'printer-history', label: 'Ιστορικό Εκτυπωτή', Component: PrinterHistory },
{ id: 'printer-health', label: 'Υγεία Εκτυπωτή', Component: PrinterHealthLog },
{ id: 'cancellations', label: 'Ακυρώσεις', Component: CancellationsLog },
{ id: 'discounts', label: 'Εκπτώσεις', Component: DiscountsLog },
],
},
]
export default function ReportsPage() {
const [activeParent, setActiveParent] = useState('staff')
const [activeSubByParent, setActiveSubByParent] = useState({
staff: 'shifts',
restaurant: 'today',
ops: 'printer-history',
})
const [subProps, setSubProps] = useState({})
const parent = PARENT_TABS.find(t => t.id === activeParent)
const activeSubId = activeSubByParent[activeParent]
const sub = parent.subTabs.find(s => s.id === activeSubId) || parent.subTabs[0]
const { Component: SubComponent } = sub
function setActiveSub(id) {
setSubProps({})
setActiveSubByParent(prev => ({ ...prev, [activeParent]: id }))
}
function navigateTo({ parent: parentId, sub: subId, ...props }) {
setSubProps(props)
setActiveSubByParent(prev => ({ ...prev, [parentId]: subId }))
setActiveParent(parentId)
}
return (
<div className="flex flex-col h-full min-h-0">
<TabGroup tabs={PARENT_TABS} active={activeParent} onChange={setActiveParent} />
<TabBar tabs={parent.subTabs} active={activeSubId} onChange={setActiveSub} />
<div className="flex-1 min-h-0 flex flex-col">
<SubComponent
key={`${activeParent}-${activeSubId}-${JSON.stringify(subProps)}`}
onNavigate={navigateTo}
{...subProps}
/>
</div>
</div>
)
}
@@ -4,7 +4,7 @@
// (core.staff.manage; a support session only by a superadmin). Your own session is marked
// and can't be ended here (that's "Sign out"). A session has no time limit (only support's
// 4 hours), so "last active" is what tells an old phone from someone working now.
import { useCallback, useEffect, useState } from 'react'
import { useState } from 'react'
import toast from 'react-hot-toast'
import { LogIn } from 'lucide-react'
import { errorMessage } from '@xenia/api'
@@ -12,6 +12,7 @@ import { useAccess } from '@xenia/access'
import { useTranslation, useFormat } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Spinner } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { canEndSession } from './permissionsLogic'
const REFRESH_MS = 30_000
@@ -21,28 +22,18 @@ export default function SessionsPage() {
const f = useFormat()
const access = useAccess()
const actorIsSuperadmin = access.user?.role === 'superadmin'
const [rows, setRows] = useState(null)
const [error, setError] = useState(null)
const [showEnded, setShowEnded] = useState(false)
const [ending, setEnding] = useState(null)
const load = useCallback(async () => {
try {
const r = await client.get('/api/auth/sessions', { params: { include_ended: showEnded } })
setRows(r.data)
setError(null)
} catch (err) {
setError(errorMessage(err, t))
}
}, [showEnded, t])
// react-query + live refresh (6.1): sessions have no live event yet, so they are re-read every 30 s
const { data: rows, error, refetch: load } = useLiveQuery({
queryKey: ['auth', 'sessions', { showEnded }],
queryFn: () => client.get('/api/auth/sessions', { params: { include_ended: showEnded } }).then(r => r.data),
refetchInterval: REFRESH_MS,
placeholderData: prev => prev,
})
useEffect(() => {
load()
const id = setInterval(load, REFRESH_MS)
return () => clearInterval(id)
}, [load])
if (error && !rows) return <div className="p-8"><EmptyState title={error} action={<Button variant="secondary" onClick={load}>{t('common:actions.retry')}</Button>} /></div>
if (error && !rows) return <div className="p-8"><EmptyState title={errorMessage(error, t)} action={<Button variant="secondary" onClick={() => load()}>{t('common:actions.retry')}</Button>} /></div>
if (!rows) return <div className="p-8 flex justify-center"><Spinner /></div>
const person = s => (s.client === 'support' ? t('sessions.support') : (s.full_name || s.username || '—'))
-39
View File
@@ -1,39 +0,0 @@
// Card / Panel primitive — wraps the PANEL_CLASS pattern with an optional header slot.
export function Card({ title, subtitle, right, children, padded = true, className = '' }) {
return (
<div className={`overflow-hidden rounded-lg border border-slate-200 bg-white shadow-[0_1px_0_rgba(15,23,42,0.04)] ${className}`}>
{(title || right) && (
<div className="flex items-center justify-between border-b border-slate-100 px-5 py-3">
<div>
{title && <div className="text-[13px] font-semibold text-slate-900">{title}</div>}
{subtitle && <div className="text-[12px] text-slate-500">{subtitle}</div>}
</div>
{right}
</div>
)}
<div className={padded ? 'p-5' : ''}>{children}</div>
</div>
)
}
export function StatCard({ label, value, sub, icon: Icon, accent, size = 'md', className = '' }) {
const sizes = {
sm: { val: 'text-2xl', pad: 'p-4' },
md: { val: 'text-[28px]', pad: 'p-5' },
lg: { val: 'text-4xl', pad: 'p-6' },
}
const s = sizes[size] || sizes.md
return (
<div className={`relative overflow-hidden rounded-lg border border-slate-200 bg-white ${s.pad} shadow-[0_1px_0_rgba(15,23,42,0.04)] ${className}`}>
<div className="flex items-start justify-between">
<div className="text-[11px] font-medium uppercase tracking-[0.1em] text-slate-500">{label}</div>
{Icon && <Icon className="h-4 w-4 text-slate-300" />}
</div>
<div className={`mt-2 font-mono ${s.val} font-medium tabular-nums tracking-tight ${accent ? 'text-sky-600' : 'text-slate-900'}`}>
{value ?? '—'}
</div>
{sub && <div className="mt-1 text-[12px] text-slate-500">{sub}</div>}
</div>
)
}
-7
View File
@@ -1,7 +0,0 @@
export { default as Button } from './Button'
export { TabGroup, TabBar, TabRow, TabCard } from './Tabs'
export { Card, StatCard } from './Card'
export { default as Badge } from './Badge'
export { Input, Select, DateInput, LabelledInput } from './Input'
export { default as Modal, ConfirmModal } from './Modal'
export * from './tokens'