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
+1 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useState } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'
import UserMenu from './UserMenu'
import { useNotifications } from '../context/NotificationContext'
@@ -15,7 +15,6 @@ export default function ConnectivityBar() {
const isOnline = status === 'online'
const isReconnecting = status === 'reconnecting'
const isOffline = status === 'offline'
const color = isOnline
? (liveAlive ? '#22c55e' : '#3b82f6')
+52 -53
View File
@@ -1,16 +1,10 @@
import { useState, useEffect, useCallback, useRef } from 'react'
import { useState, useEffect, useRef } from 'react'
import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
import client from '../api/client'
import { getVenueSettings } from '../api/venueSettings'
import { assetUrl } from '../config/server'
// ── Helpers ──────────────────────────────────────────────────────────────────
function fmt(n) {
if (n === 0) return ''
const s = n > 0 ? `+${n.toFixed(2)} €` : `${n.toFixed(2)} €`
return s
}
function buildInitialState(product) {
const preferenceSets = product.preference_sets || []
@@ -445,7 +439,7 @@ function FavoritesTab({ product, waiterOverride, quickState, setQuickState, extr
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
{favorites.map((fav, fi) => {
{favorites.map((fav, _fi) => {
if (fav.type === 'quick') {
return <QuickOptionRow key={`quick-${fav.item.id}`} opt={fav.item} quickState={quickState} setQuickState={setQuickState} compact={false} />
}
@@ -931,49 +925,54 @@ function NotesTab({ note, setNote, quickNotes = FALLBACK_QUICK_NOTES }) {
// ── Tab: Summary ──────────────────────────────────────────────────────────────
function SummaryTab({ product, summaryLines, note, onJumpTab }) {
/** One group of the summary (prefs, quick options, extras, removed) with its "change" link. */
function Section({ title, tab, lines, onJumpTab }) {
if (lines.length === 0) return null
return (
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 2px 8px' }}>
<div style={{ fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6 }}>{title}</div>
<button onClick={() => onJumpTab(tab)} style={{ background: 'none', border: 'none', fontSize: 12, fontWeight: 700, color: '#f59e0b', cursor: 'pointer', textTransform: 'uppercase', letterSpacing: 0.6 }}>Αλλαγή</button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{lines.map((l, i) => (
<div key={i} style={{ padding: '10px 14px', background: 'var(--bg2)', border: '1px solid var(--border)', borderRadius: 10, display: 'flex', alignItems: 'center', gap: 10, minHeight: 44 }}>
<div style={{ flex: 1 }}>
{l.group === 'prefs' ? (
<>
<div style={{ fontSize: 12, color: 'var(--muted)', marginBottom: 2 }}>{l.label}</div>
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>{l.value}</div>
</>
) : l.group === 'removed' ? (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
Χωρίς {l.label}
</div>
) : l.group === 'extras' ? (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
{l.label}
{l.subName && <span> · {l.subName}</span>}
{l.qty > 1 && <span style={{ color: 'var(--muted)', marginLeft: 6, fontVariantNumeric: 'tabular-nums' }}>×{l.qty}</span>}
</div>
) : (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
{l.qty > 1 && <span style={{ color: 'var(--muted)', marginRight: 6, fontVariantNumeric: 'tabular-nums' }}>{l.qty}×</span>}
{l.label}
</div>
)}
</div>
{l.price !== 0 && <div style={{ fontSize: 13, fontWeight: 600, color: l.price < 0 ? 'var(--danger)' : 'var(--text)', fontVariantNumeric: 'tabular-nums' }}>{l.price > 0 ? '+' : ''}{l.price.toFixed(2)} €</div>}
</div>
))}
</div>
</div>
)
}
function SummaryTab({ _product, summaryLines, note, onJumpTab }) {
const isEmpty = summaryLines.length === 0 && !note
const byGroup = { quick: [], extras: [], removed: [], prefs: [] }
summaryLines.forEach(l => byGroup[l.group]?.push(l))
const Section = ({ title, tab, lines }) => lines.length === 0 ? null : (
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 2px 8px' }}>
<div style={{ fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6 }}>{title}</div>
<button onClick={() => onJumpTab(tab)} style={{ background: 'none', border: 'none', fontSize: 12, fontWeight: 700, color: '#f59e0b', cursor: 'pointer', textTransform: 'uppercase', letterSpacing: 0.6 }}>Αλλαγή</button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{lines.map((l, i) => (
<div key={i} style={{ padding: '10px 14px', background: 'var(--bg2)', border: '1px solid var(--border)', borderRadius: 10, display: 'flex', alignItems: 'center', gap: 10, minHeight: 44 }}>
<div style={{ flex: 1 }}>
{l.group === 'prefs' ? (
<>
<div style={{ fontSize: 12, color: 'var(--muted)', marginBottom: 2 }}>{l.label}</div>
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>{l.value}</div>
</>
) : l.group === 'removed' ? (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
Χωρίς {l.label}
</div>
) : l.group === 'extras' ? (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
{l.label}
{l.subName && <span> · {l.subName}</span>}
{l.qty > 1 && <span style={{ color: 'var(--muted)', marginLeft: 6, fontVariantNumeric: 'tabular-nums' }}>×{l.qty}</span>}
</div>
) : (
<div style={{ fontSize: 14, fontWeight: 500, color: 'var(--text)' }}>
{l.qty > 1 && <span style={{ color: 'var(--muted)', marginRight: 6, fontVariantNumeric: 'tabular-nums' }}>{l.qty}×</span>}
{l.label}
</div>
)}
</div>
{l.price !== 0 && <div style={{ fontSize: 13, fontWeight: 600, color: l.price < 0 ? 'var(--danger)' : 'var(--text)', fontVariantNumeric: 'tabular-nums' }}>{l.price > 0 ? '+' : ''}{l.price.toFixed(2)} €</div>}
</div>
))}
</div>
</div>
)
return (
<div>
@@ -983,10 +982,10 @@ function SummaryTab({ product, summaryLines, note, onJumpTab }) {
</div>
) : (
<>
<Section title="Προτιμήσεις" tab="prefs" lines={byGroup.prefs} />
<Section title="Γρήγορες Επιλογές" tab="quick" lines={byGroup.quick} />
<Section title="Extras" tab="extras" lines={byGroup.extras} />
<Section title="Αφαιρέθηκαν" tab="ingredients" lines={byGroup.removed} />
<Section title="Προτιμήσεις" tab="prefs" lines={byGroup.prefs} onJumpTab={onJumpTab} />
<Section title="Γρήγορες Επιλογές" tab="quick" lines={byGroup.quick} onJumpTab={onJumpTab} />
<Section title="Extras" tab="extras" lines={byGroup.extras} onJumpTab={onJumpTab} />
<Section title="Αφαιρέθηκαν" tab="ingredients" lines={byGroup.removed} onJumpTab={onJumpTab} />
{note && (
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 2px 8px' }}>
@@ -1051,7 +1050,7 @@ export default function OrderDrawer({ product, isOpen, onClose, onAdd, initialSt
const [priceAdjAllowed, setPriceAdjAllowed] = useState(false)
useEffect(() => {
client.get('/api/settings/')
getVenueSettings()
.then(r => setPriceAdjAllowed(r.data?.['orders.waiter_price_adjust_allowed']?.value === 'true'))
.catch(() => {})
}, [])
+1 -2
View File
@@ -208,7 +208,7 @@ const PRICING_EVENT_STYLE = {
deal_offer_accepted: { color: '#4ade80', label: null }, // label from deal_name
}
function PricingRows({ events, layout, nameIndent = 12 }) {
function PricingRows({ events, _layout, nameIndent = 12 }) {
const rows = events.filter(ev =>
ev.event_type === 'modifier_applied' ||
ev.event_type === 'waiter_discount' ||
@@ -225,7 +225,6 @@ function PricingRows({ events, layout, nameIndent = 12 }) {
const evStyle = PRICING_EVENT_STYLE[ev.event_type] || { color: '#94a3b8', label: ev.event_type }
const label = ev.modifier_name || ev.deal_name || evStyle.label || ev.event_type
const delta = ev.delta_amount
const afterPrice = ev.price_after
return (
<div key={i} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
+1 -1
View File
@@ -181,7 +181,7 @@ function ProductCard({ product, onOpen, onQuickAdd, onShowDetail }) {
const onDetail = useCallback(() => onShowDetail(product), [onShowDetail, product])
const longPress = useLongPress(onDetail, 1200)
function handleClick(e) {
function handleClick(_e) {
// If a long-press just fired, don't open the drawer
if (longPress.didFire()) return
onOpen(product)
+5 -6
View File
@@ -51,7 +51,6 @@ function computeKdsBadge(order) {
if (!order?.items) return null
const relevant = order.items.filter(i => i.status !== 'cancelled' && kds(i.kds_status) !== 'served')
if (relevant.length === 0) return null
const pending = relevant.filter(i => kds(i.kds_status) === 'pending').length
const preparing = relevant.filter(i => kds(i.kds_status) === 'preparing').length
const done = relevant.filter(i => kds(i.kds_status) === 'done').length
const total = relevant.length
@@ -282,7 +281,7 @@ function Amount({ value, size = 22, color }) {
// ─── Card variants ────────────────────────────────────────────────────────────
// 1x1 — square-ish, 4 per row. Badges top (up to 2 + +N), name center, KDS badge bottom (replaces status).
function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
function Card1x1({ table, _order, flags, _waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
return (
<div style={{
width: '100%', aspectRatio: '1 / 1.05',
@@ -329,7 +328,7 @@ function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge,
}
// 2x1 — half width, compact horizontal. Name left, KDS badge (or status) + flags right.
function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
function Card2x1({ table, _order, flags, _waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
return (
<div style={{
width: '100%', height: 64,
@@ -369,7 +368,7 @@ function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge,
}
// 2x2 — current-style square. Name top-left, status below, amount bottom-left, KDS badge top-right, flags right.
function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
function Card2x2({ table, order, flags, _waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
const isFree = !order
const total = order?.items?.filter(i => i.status === 'active').reduce((s, i) => s + i.unit_price * i.quantity, 0) ?? 0
@@ -419,7 +418,7 @@ function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge,
}
// 4x1 — full width horizontal. Name + amount left-center, flags, KDS badge (or status) right.
function Card4x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
function Card4x1({ table, order, flags, _waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
const isFree = !order
const total = order?.items?.filter(i => i.status === 'active').reduce((s, i) => s + i.unit_price * i.quantity, 0) ?? 0
@@ -555,7 +554,7 @@ function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey
}
// 4x3 — full width, two-column detail card. Left: name/zone/status/amount. Right: items. KDS footer. Waiter footer.
function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey, kdsBadge, flashOverlay }) {
function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey, _kdsBadge, flashOverlay }) {
const isFree = !order
const activeItems = order?.items?.filter(i => i.status === 'active') ?? []
const total = activeItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
+3 -1
View File
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useCan } from '@xenia/access'
import useAuthStore from '../store/authStore'
import useShiftStore from '../store/shiftStore'
import useThemeStore from '../store/themeStore'
@@ -46,8 +47,9 @@ export default function UserMenu() {
navigate('/login')
}
const canDashboard = useCan('core.dashboard.access')
const activeBreak = shift?.breaks?.find(b => !b.ended_at)
const isWaiter = user?.role === 'waiter'
const isWaiter = !canDashboard // works in a shift (plan 4.1: the key, not the role)
async function handleEndShift() {
if (!window.confirm('Να τελειώσει η βάρδια σου;')) return