feat(waiter): the waiter app on the shared foundations (api client, access, i18n), lint clean, starts offline

Plan step 4.1. No visible change to layout or flows.
- api/client.js on @xenia/api createApiClient (CS-8 baseURL, 401 → sign out, no answer →
  backend-offline, err.xenia, the manager-approval retry); the PIN login handles its own 401
  (before, a wrong PIN reloaded the page).
- <AccessProvider> at the root with an i18n instance: modules, permission keys, venue,
  language from bootstrap; who is signed in comes with it (no more /api/auth/me polling).
  packages/access: AccessProvider gains `cache` (the last bootstrap per session; used when
  the server can't be reached, `offline` in the context, keeps retrying) and `failed` (the
  app's own screen when there's nothing cached). The waiter caches per venue, shows its
  offline page (server search) on a first start without a server, retries every 5 s;
  ServerRediscovery and BundleSync run outside the bootstrap.
- Role names → keys: the shift gate and the user menu use core.dashboard.access.
- One shared, offline-cached read of the venue settings (api/venueSettings.js) instead of
  seven GET /api/settings/ calls; apiError() shows backend error codes in the user's
  language (17 places).
- Lint: 78 errors → 0 (unused code, empty catches, two duplicate style keys, a component
  created during render, refs read during render → state, hooks after an early return);
  set-state-in-effect is a warning like the manager/terminal; lint in run-all.
- Tests: tests/bootstrapCache.test.mjs; e2e browser: an offline restart stays signed in.
  Android rediscovery waits for what the screen shows instead of fixed sleeps: 10/10 three
  runs in a row (KI-009). Terminal 3.4 waits for both displays before the sale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 11:37:47 +02:00
co-authored by Claude Opus 5.5
parent f85894a72e
commit 9f5498332a
41 changed files with 389 additions and 213 deletions
+25 -26
View File
@@ -1,9 +1,10 @@
import { useEffect, useState, useRef, useCallback } from 'react'
import { useEffect, useState, useRef } from 'react'
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
import OrderSummary from '../components/OrderSummary'
import useAuthStore from '../store/authStore'
import useConnectionStore from '../store/connectionStore'
import client from '../api/client'
import { apiError } from '../api/errors'
import { getVenueSettings } from '../api/venueSettings'
import db from '../db/posdb'
import { queueOfflineSplit, queueOfflinePayment as queueOfflinePaymentOp } from '../services/offlineOrders'
import { TransferIcon, MergeIcon, FlagsIcon, WaiterIcon, PrintIcon } from '../components/Icons'
@@ -365,13 +366,13 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
// ─── Apply Discount modal ─────────────────────────────────────────────────────
function ApplyDiscountModal({ order, waiterId, onClose, onApplied }) {
function ApplyDiscountModal({ order, _waiterId, onClose, onApplied }) {
const activeItems = (order?.items ?? []).filter(i => i.status === 'active')
const [selectedIds, setSelectedIds] = useState(activeItems.map(i => i.id))
const [pct, setPct] = useState(10)
const [note, setNote] = useState('')
const [applying, setApplying] = useState(false)
const [remaining, setRemaining] = useState(null) // { shift, workday }
const [, setRemaining] = useState(null) // { shift, workday }
const [error, setError] = useState('')
const PCT_PRESETS = [5, 10, 15, 20, 25, 50, 100]
@@ -406,7 +407,7 @@ function ApplyDiscountModal({ order, waiterId, onClose, onApplied }) {
onApplied()
onClose()
} catch (e) {
setError(e?.response?.data?.detail || 'Σφάλμα εφαρμογής έκπτωσης')
setError(apiError(e, 'Σφάλμα εφαρμογής έκπτωσης'))
} finally {
setApplying(false)
}
@@ -546,7 +547,7 @@ function DiscountIcon({ width = 20, height = 20 }) {
)
}
function ActionsSheet({ order, tableId, isStandalone, onClose, onTransfer, onMerge, onSetFlags, onAssignWaiter, onPrintSynopsis, onCancelOrder, onMarkAllServed, canCancel, canDiscount, onApplyDiscount }) {
function ActionsSheet({ order, _tableId, isStandalone, onClose, onTransfer, onMerge, onSetFlags, onAssignWaiter, onPrintSynopsis, onCancelOrder, onMarkAllServed, canCancel, canDiscount, onApplyDiscount }) {
const hasOrder = !!order
const hasServable = hasOrder && order.items?.some(i => i.kds_status === 'done')
const hasActiveItems = hasOrder && order.items?.some(i => i.status === 'active')
@@ -605,7 +606,7 @@ function ActionsSheet({ order, tableId, isStandalone, onClose, onTransfer, onMer
// ─── Table picker (for transfer / merge / move-items) ─────────────────────────
function TablePicker({ title, subtitle, tables, currentTableId, onSelect, onClose, loading }) {
function TablePicker({ title, subtitle, tables, _currentTableId, onSelect, onClose, loading }) {
return (
<div className="modal-overlay modal-overlay--top" onClick={onClose}>
<div className="modal-sheet modal-sheet--top" onClick={e => e.stopPropagation()}>
@@ -651,7 +652,7 @@ function TablePicker({ title, subtitle, tables, currentTableId, onSelect, onClos
// ─── Flag picker ──────────────────────────────────────────────────────────────
function FlagPicker({ tableId, currentFlagIds, flagDefs, onSave, onClose, loading }) {
function FlagPicker({ _tableId, currentFlagIds, flagDefs, onSave, onClose, loading }) {
const [selected, setSelected] = useState(currentFlagIds || [])
// Sync selected when currentFlagIds loads
@@ -1037,7 +1038,6 @@ export default function TableDetailPage() {
const { tableId, orderId: standaloneOrderId } = useParams()
const isStandalone = !!standaloneOrderId
const [searchParams, setSearchParams] = useSearchParams()
const { user } = useAuthStore()
const navigate = useNavigate()
const [table, setTable] = useState(null)
@@ -1226,7 +1226,7 @@ export default function TableDetailPage() {
client.get('/api/pricing/discount-settings/me')
.then(r => setCanDiscount(!!r.data.can_apply_discounts))
.catch(() => {})
client.get('/api/settings/')
getVenueSettings()
.then(r => {
setCardEnabled(r.data?.['payments.card_enabled']?.value === 'true')
setRevertAllowed(r.data?.['payments.waiter_revert_allowed']?.value === 'true')
@@ -1322,7 +1322,7 @@ export default function TableDetailPage() {
await client.post('/api/orders/', { table_id: Number(tableId) })
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα ανοίγματος')
setError(apiError(err, 'Σφάλμα ανοίγματος'))
}
}
@@ -1358,15 +1358,14 @@ export default function TableDetailPage() {
if (res.data?.auto_closed || andClose) {
if (andClose && !res.data?.auto_closed) {
// Payment succeeded, now close the order explicitly
try { await client.post(`/api/orders/${order.id}/close`) } catch {}
try { await client.post(`/api/orders/${order.id}/close`) } catch { /* ignore */ }
}
navigate('/tables', { replace: true })
return
}
await load()
} catch (err) {
const detail = err?.response?.data?.detail
setError(detail ? `Σφάλμα πληρωμής: ${detail}` : 'Σφάλμα πληρωμής')
setError(apiError(err, 'Σφάλμα πληρωμής'))
} finally {
setPaying(false)
}
@@ -1379,7 +1378,7 @@ export default function TableDetailPage() {
setPaidSelectedIds([])
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα αναίρεσης πληρωμής')
setError(apiError(err, 'Σφάλμα αναίρεσης πληρωμής'))
}
}
@@ -1389,7 +1388,7 @@ export default function TableDetailPage() {
setConfirmClose(false)
navigate('/tables')
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα κλεισίματος')
setError(apiError(err, 'Σφάλμα κλεισίματος'))
}
}
@@ -1405,7 +1404,7 @@ export default function TableDetailPage() {
setItemActionTarget(null)
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα ακύρωσης')
setError(apiError(err, 'Σφάλμα ακύρωσης'))
}
}
@@ -1415,7 +1414,7 @@ export default function TableDetailPage() {
await client.delete(`/api/orders/${order.id}?print_cancellation=true`)
navigate('/tables')
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα ακύρωσης παραγγελίας')
setError(apiError(err, 'Σφάλμα ακύρωσης παραγγελίας'))
}
}
@@ -1434,7 +1433,7 @@ export default function TableDetailPage() {
setPaidSelectedIds([])
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα σήμανσης')
setError(apiError(err, 'Σφάλμα σήμανσης'))
}
}
@@ -1446,7 +1445,7 @@ export default function TableDetailPage() {
await client.post(`/api/kds/orders/${order.id}/items/mark-all-served`)
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα σήμανσης')
setError(apiError(err, 'Σφάλμα σήμανσης'))
}
}
@@ -1493,7 +1492,7 @@ export default function TableDetailPage() {
setSelectedIds([])
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα διαχωρισμού')
setError(apiError(err, 'Σφάλμα διαχωρισμού'))
}
}
@@ -1506,7 +1505,7 @@ export default function TableDetailPage() {
await client.post(`/api/orders/${order.id}/transfer`, { target_table_id: targetTable.id })
navigate('/tables')
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα μεταφοράς')
setError(apiError(err, 'Σφάλμα μεταφοράς'))
}
}
@@ -1521,7 +1520,7 @@ export default function TableDetailPage() {
await client.post(`/api/orders/${order.id}/merge`, { target_order_id: targetOrder.id })
navigate('/tables')
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα συγχώνευσης')
setError(apiError(err, 'Σφάλμα συγχώνευσης'))
}
}
@@ -1540,7 +1539,7 @@ export default function TableDetailPage() {
setSelectedIds([])
await load()
} catch (err) {
setError(err.response?.data?.detail || 'Σφάλμα μεταφοράς αντικειμένων')
setError(apiError(err, 'Σφάλμα μεταφοράς αντικειμένων'))
}
}
@@ -1778,7 +1777,7 @@ export default function TableDetailPage() {
onClick={() => setShowMergeModal(true)}
style={{
width: 40, flexShrink: 0,
borderRadius: 10, border: 'none', cursor: 'pointer',
borderRadius: 10, cursor: 'pointer',
background: mergeMode !== MERGE_OFF ? 'rgba(99,102,241,0.25)' : 'var(--bg2)',
color: mergeMode !== MERGE_OFF ? '#a5b4fc' : 'var(--muted)',
border: mergeMode !== MERGE_OFF ? '1px solid rgba(99,102,241,0.45)' : '1px solid var(--border)',
@@ -2177,7 +2176,7 @@ export default function TableDetailPage() {
if (order) {
try {
await client.patch(`/api/orders/${order.id}/customer-count`, { customer_count: v })
} catch {}
} catch { /* ignore */ }
}
}}
onClose={() => setCustomerCountOpen(false)}