Files
xenia-pos-local/packages/ui/gallery/Gallery.jsx
T
bonaminandClaude Opus 5.5 f57894dcb7 feat(waiter): table bookings on the phone; shared ReasonPicker (platform-v2 step 4.8c)
- Waiter: Bookings (side drawer, for whoever has connect_orders.manage or
  reservations.manage, with the online-orders app on): requests made online are
  confirmed or declined with a reason the guest sees; confirmed ones are seated at a free
  table (its seats shown, a warning mark when the party is bigger) or cancelled / marked
  as a no-show; the food ordered ahead and its kitchen time; live updates.
- Backend: the bookings routes take reservations.manage too (require_any).
- @xenia/ui ReasonPicker + reasonText (gallery, unit test), first piece moved from the
  terminal (4.6 → 4.8): the counter's online reject and booking decline dialogs use it;
  the waiter loads @xenia/ui styles.css (the .x-* components; tokens as before).
- Tests: waiter e2e +2 (request listed with the key, confirmed and seated from the phone);
  terminal.mjs and qr_table.mjs green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 10:10:14 +02:00

179 lines
9.7 KiB
React

// Visual check page for @xenia/ui (plan step 2.3). Dev builds only: the manager mounts
// it at /ui-gallery under `import.meta.env.DEV` (moves to the terminal dev build in 3.1).
// Sets data-theme / data-venue-theme on <html> while open and restores them on leave.
import { useEffect, useState } from 'react'
import {
Button, Dialog, EmptyState, Field, IconButton, InfoTip, Input, PinPad, Select, Sheet,
ReasonPicker, Spinner, Stepper, Switch, Textarea, ToastProvider, useToast,
} from '../src/index.js'
import '../src/styles.css'
const THEMES = ['light', 'dark', 'system']
const VENUES = ['teal', 'amber', 'blue', 'violet', 'rose']
const Plus = () => (
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14" /></svg>
)
const Trash = () => (
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14" /></svg>
)
const Inbox = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M22 12h-6l-2 3h-4l-2-3H2" /><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" /></svg>
)
const page = {
minHeight: '100vh', background: 'var(--x-canvas)', color: 'var(--x-ink)',
fontFamily: 'var(--x-font-sans)', fontSize: 'var(--x-text-body)', padding: 'var(--x-space-6)',
}
const card = {
background: 'var(--x-surface)', border: '1px solid var(--x-line)', borderRadius: 'var(--x-radius-card)',
boxShadow: 'var(--x-shadow-raised)', padding: 'var(--x-space-6)', marginBottom: 'var(--x-space-6)',
}
const row = { display: 'flex', flexWrap: 'wrap', gap: 'var(--x-space-3)', alignItems: 'center' }
const h2 = { margin: '0 0 var(--x-space-4)', fontSize: 'var(--x-text-title)', fontWeight: 600 }
function Section({ title, children }) {
return <section style={card} data-section={title}><h2 style={h2}>{title}</h2>{children}</section>
}
function Demo() {
const toast = useToast()
const [theme, setTheme] = useState('light')
const [venue, setVenue] = useState('teal')
const [dialog, setDialog] = useState(false)
const [reason, setReason] = useState(null)
const [reasonOther, setReasonOther] = useState('')
const [locked, setLocked] = useState(false)
const [sheet, setSheet] = useState(null)
const [on, setOn] = useState(true)
const [step, setStep] = useState(30)
const [off, setOff] = useState(false)
const [name, setName] = useState('')
const [lang, setLang] = useState('el')
const [pinError, setPinError] = useState('')
const [unlocked, setUnlocked] = useState('')
useEffect(() => {
const html = document.documentElement
const before = [html.getAttribute('data-theme'), html.getAttribute('data-venue-theme')]
html.setAttribute('data-theme', theme)
html.setAttribute('data-venue-theme', venue)
return () => {
before[0] == null ? html.removeAttribute('data-theme') : html.setAttribute('data-theme', before[0])
before[1] == null ? html.removeAttribute('data-venue-theme') : html.setAttribute('data-venue-theme', before[1])
}
}, [theme, venue])
const checkPin = pin => new Promise((resolve, reject) => setTimeout(() => {
if (pin === '1234') { setPinError(''); setUnlocked(n => `Unlocked (${n ? Number(n.slice(10, -1)) + 1 : 1})`); resolve() }
else { setPinError('Wrong PIN'); reject(new Error('wrong')) }
}, 500))
return (
<div style={page}>
<div style={{ ...row, justifyContent: 'space-between', marginBottom: 'var(--x-space-6)' }}>
<h1 style={{ margin: 0, fontSize: 'var(--x-text-heading)', fontWeight: 700 }}>@xenia/ui gallery</h1>
<div style={row}>
<Select aria-label="Theme" size="sm" value={theme} onChange={e => setTheme(e.target.value)} options={THEMES.map(t => ({ value: t, label: `Theme: ${t}` }))} />
<Select aria-label="Venue theme" size="sm" value={venue} onChange={e => setVenue(e.target.value)} options={VENUES.map(v => ({ value: v, label: `Venue: ${v}` }))} />
</div>
</div>
<Section title="Buttons">
<div style={row}>
<Button>Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="danger" icon={<Trash />}>Delete</Button>
<Button loading>Saving</Button>
<Button disabled>Disabled</Button>
<Button size="sm" icon={<Plus />}>Small</Button>
<Button size="lg">Large</Button>
<IconButton label="Add"><Plus /></IconButton>
<IconButton label="Delete" variant="danger"><Trash /></IconButton>
</div>
</Section>
<Section title="Dialog, Sheet, Toast">
<div style={row}>
<Button variant="secondary" onClick={() => setDialog(true)}>Open dialog</Button>
<Button variant="secondary" onClick={() => setLocked(true)}>Non-dismissible dialog</Button>
<Button variant="secondary" onClick={() => setSheet('bottom')}>Bottom sheet</Button>
<Button variant="secondary" onClick={() => setSheet('right')}>Side sheet</Button>
<Button variant="ghost" onClick={() => toast.success('Saved', { description: 'Product updated' })}>Toast: success</Button>
<Button variant="ghost" onClick={() => toast.error('Printer offline', { description: 'Bar printer did not answer' })}>Toast: danger</Button>
<Button variant="ghost" onClick={() => toast.show({ title: 'Order moved to table 4', action: { label: 'Undo', onClick: () => toast.info('Undone') } })}>Toast: action</Button>
</div>
<Dialog
open={dialog} onClose={() => setDialog(false)} title="Delete product?"
description="Freddo espresso will be removed from every category."
footer={<><Button variant="secondary" onClick={() => setDialog(false)}>Cancel</Button><Button variant="danger" onClick={() => { setDialog(false); toast.success('Deleted') }}>Delete</Button></>}
>
<Field label="Type DELETE to confirm"><Input placeholder="DELETE" /></Field>
</Dialog>
<Dialog
open={locked} dismissible={false} title="Finish the close of day" size="sm"
footer={<Button onClick={() => setLocked(false)}>Done</Button>}
>
Escape and the backdrop don&apos;t close this one.
</Dialog>
<Sheet
open={!!sheet} side={sheet || 'bottom'} onClose={() => setSheet(null)} title="Move order"
footer={<Button block onClick={() => setSheet(null)}>Move</Button>}
>
<Field label="To table"><Select placeholder="Choose…" defaultValue="" options={[1, 2, 3, 4].map(n => ({ value: String(n), label: `Table ${n}` }))} /></Field>
</Sheet>
</Section>
<Section title="Fields">
<div style={{ display: 'grid', gap: 'var(--x-space-4)', gridTemplateColumns: 'repeat(auto-fit, minmax(260px, 1fr))' }}>
<Field label="Product name" hint="Shown on tickets and the QR menu" required>
<Input value={name} onChange={e => setName(e.target.value)} placeholder="e.g. Freddo espresso" />
</Field>
<Field label="Price" error="Enter a price, e.g. 3,50">
<Input inputMode="decimal" defaultValue="3,5x" />
</Field>
<Field label="Language" info={<InfoTip>The language staff screens start in. Each person can change their own.</InfoTip>}>
<Select value={lang} onChange={e => setLang(e.target.value)} options={[{ value: 'el', label: 'Ελληνικά' }, { value: 'en', label: 'English' }]} />
</Field>
<Field label="Notes"><Textarea placeholder="Allergies, preparation…" /></Field>
<Field label="Disabled"><Input disabled value="Read only" /></Field>
</div>
</Section>
<Section title="ReasonPicker">
<div style={{ maxWidth: 360 }}>
<ReasonPicker ariaLabel="Reason" value={reason} onChange={setReason} other={reasonOther} onOther={setReasonOther}
options={[{ value: 'full', label: 'We are fully booked' }, { value: 'closed', label: 'Closed that day' }]} />
</div>
</Section>
<Section title="Switch + InfoTip">
<div style={{ display: 'grid', gap: 'var(--x-space-4)', maxWidth: 520 }}>
<Switch checked={on} onChange={setOn} label="Print kitchen tickets" description="Send new items to the kitchen printer." />
<Switch checked={off} onChange={setOff} label="Alert after print failures" />
<Switch checked disabled label="Disabled (on)" />
<div style={row}><Stepper value={step} steps={[10, 15, 20, 30, 45, 60]} format={v => `${v}s`} onChange={setStep} label="Check every" /> <Stepper value={3} min={1} max={5} disabled label="Disabled" /></div>
<div style={row}>Alert after <InfoTip side="bottom">How many failed print attempts before managers are notified. 0 turns the alert off.</InfoTip></div>
</div>
</Section>
<Section title="PinPad (1234 unlocks)">
<div style={{ ...row, alignItems: 'flex-start', gap: 'var(--x-space-12)' }}>
<PinPad title="Enter PIN" onComplete={checkPin} error={pinError} />
<div style={{ color: 'var(--x-ink-2)' }} data-testid="pin-result">{unlocked}</div>
</div>
</Section>
<Section title="Spinner + EmptyState">
<div style={row}><Spinner size="sm" /><Spinner /><Spinner size="lg" /></div>
<EmptyState icon={<Inbox />} title="No online orders yet" description="New orders from the QR menu appear here." action={<Button variant="secondary">Menu settings</Button>} />
</Section>
</div>
)
}
export default function Gallery() {
return <ToastProvider><Demo /></ToastProvider>
}