feat: staff apps show the menu in the reader's language (plan 6R.L)

The waiters' phones and the counter show categories, products and every
choice (quick options, extras and sub-choices, preferences, shared sets,
ingredients, groups) in the signed-in person's language, falling back to
the stored text. Display only: carts, lines, tickets and the kitchen keep
the venue's text (ids, sub-choices by stored name). In the venue's own
language nothing changes.

- @xenia/access: menuText / useMenuText (mt, mt.choice, mt.line, mt.matches)
- /api/pos/menu carries translations for products, categories and choices
- shared ProductDialog takes a text() prop (the counter passes useMenuText)
- search finds a product by its name in any language (counter, waiter)
- waiter: useMenuNames for sent lines; picker, drawer, cart, summary,
  table lines, quantity / price history, favourites setup
- counter: categories, cards, dialog, cart lines, table lines, payment rows
- tests: access menuText, ordering search, test_pos per-language,
  e2e waiter.mjs and terminal.mjs 6R.L blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 20:18:10 +02:00
co-authored by Claude Opus 5.5
parent f107deca8c
commit 0840247768
29 changed files with 518 additions and 123 deletions
+20 -16
View File
@@ -3,6 +3,8 @@
// product with preferences to pick opens it on tap. The price shown is the backend's (the menu
// price, then the app's quote endpoint through `fetchQuote(lines)`), never added up here.
// `product` is the counter's product shape (routers/pos._product_out).
// `text` (6R.L): how a name is shown, `text(item, field?)` (the counter passes `useMenuText()`, the
// cashier's language); display only: choices are still picked and sent by id / stored name.
import { useMemo, useState } from 'react'
import { Minus, Plus } from 'lucide-react'
import { useFormat, useTranslation } from '@xenia/i18n'
@@ -33,7 +35,9 @@ function Price({ value }) {
// fetchQuote(lines) → the server's quote ({lines, total}); each app its endpoint (the menu tablet's
// has in-store prices and no discounts, 6.6)
export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel }) {
const asStored = (item, field = 'name') => item?.[field] ?? ''
export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel, text = asStored }) {
const { t } = useTranslation('common')
const { formatMoney } = useFormat()
const unit = unitOf(product)
@@ -47,7 +51,7 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
const add = () => { onAdd(line); onClose() }
return (
<Dialog open onClose={onClose} size="lg" title={product.name} description={product.description || undefined}
<Dialog open onClose={onClose} size="lg" title={text(product)} description={text(product, 'description') || undefined}
footer={<>
<Button variant="secondary" size="lg" onClick={onClose}>{t('ordering.dialog.close')}</Button>
<Button size="lg" disabled={missing.length > 0} onClick={add} data-testid="dialog-add">
@@ -84,35 +88,35 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
const need = missing.find(m => m.kind === 'pref' && m.name === ps.name)
return (
<div key={ps.id} className="grid gap-3" data-pref={ps.id}>
<Section title={ps.name} hint={need ? t('ordering.dialog.pickOne') : null}>
<Section title={text(ps)} hint={need ? t('ordering.dialog.pickOne') : null}>
{ps.choices.map(c => {
const p = picked.find(x => x.id === c.id)
return (
<span key={c.id} className="flex items-center gap-1">
<button type="button" className={chip(!!p)} onClick={() => setSel(s => pickChoice(product, s, ps.id, c.id))} data-choice={c.id}>
{c.name} <Price value={c.price} />
{text(c)} <Price value={c.price} />
</button>
{ps.multi && p && (
<Stepper value={p.qty} min={1} max={99} onChange={v => setSel(s => setChoiceQty(s, ps.id, c.id, v))} label={c.name} />
<Stepper value={p.qty} min={1} max={99} onChange={v => setSel(s => setChoiceQty(s, ps.id, c.id, v))} label={text(c)} />
)}
</span>
)
})}
</Section>
{one?.subs?.length > 0 && (
<Section title={one.name}>
<Section title={text(one)}>
{one.subs.map(s => (
<button key={s.name} type="button" className={chip(picked[0].sub === s.name)} onClick={() => setSel(x => pickChoiceSub(x, ps.id, s.name))}>
{s.name} <Price value={s.price} />
{text(s)} <Price value={s.price} />
</button>
))}
</Section>
)}
{ps.shared && one && !one.disables_shared && (
<Section title={ps.shared.name}>
<Section title={text(ps.shared)}>
{ps.shared.subs.map(s => (
<button key={s.name} type="button" className={chip(sel.prefs[ps.id]?.shared === s.name)} onClick={() => setSel(x => pickShared(x, ps.id, s.name))}>
{s.name} <Price value={s.price} />
{text(s)} <Price value={s.price} />
</button>
))}
</Section>
@@ -128,10 +132,10 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
return (
<span key={q.id} className="flex items-center gap-1">
<button type="button" className={chip(n > 0)} onClick={() => setSel(s => setQuick(s, q.id, n > 0 ? 0 : 1))} data-quick={q.id}>
{q.name} <Price value={q.price} />
{text(q)} <Price value={q.price} />
</button>
{q.allow_multiple && n > 0 && (
<Stepper value={n} min={1} max={99} onChange={v => setSel(s => setQuick(s, q.id, v))} label={q.name} />
<Stepper value={n} min={1} max={99} onChange={v => setSel(s => setQuick(s, q.id, v))} label={text(q)} />
)}
</span>
)
@@ -147,15 +151,15 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
<span key={o.id} className="grid gap-2">
<span className="flex items-center gap-1">
<button type="button" className={chip(!!s)} onClick={() => setSel(x => toggleOption(product, x, o.id))} data-option={o.id}>
{o.name} <Price value={o.price} />
{text(o)} <Price value={o.price} />
</button>
{o.allow_multiple && s && <Stepper value={s.qty} min={1} max={99} onChange={v => setSel(x => setOptionQty(x, o.id, v))} label={o.name} />}
{o.allow_multiple && s && <Stepper value={s.qty} min={1} max={99} onChange={v => setSel(x => setOptionQty(x, o.id, v))} label={text(o)} />}
</span>
{s && o.subs.length > 0 && (
<span className="flex flex-wrap gap-1 pl-3">
{o.subs.map(sub => (
<button key={sub.name} type="button" className={chip(s.subs.includes(sub.name))} onClick={() => setSel(x => pickOptionSub(product, x, o.id, sub.name))}>
{sub.name} <Price value={sub.price} />
{text(sub)} <Price value={sub.price} />
</button>
))}
</span>
@@ -170,7 +174,7 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
<Section title={t('ordering.dialog.without')}>
{product.ingredients.map(i => (
<button key={i.id} type="button" className={chip(sel.removed.includes(i.id))} onClick={() => setSel(s => toggleRemoved(s, i.id))} data-ingredient={i.id}>
{sel.removed.includes(i.id) ? <Minus size={14} /> : <Plus size={14} className="opacity-40" />}{i.name}
{sel.removed.includes(i.id) ? <Minus size={14} /> : <Plus size={14} className="opacity-40" />}{text(i)}
</button>
))}
</Section>
@@ -189,7 +193,7 @@ export function ProductDialog({ product, onAdd, onClose, fetchQuote, addLabel })
</div>
</div>
{missing.length > 0 && (
<p className="text-label text-warning-ink" data-testid="dialog-missing">{t('ordering.dialog.missing', { list: missing.map(m => m.name).join(', ') })}</p>
<p className="text-label text-warning-ink" data-testid="dialog-missing">{t('ordering.dialog.missing', { list: missing.map(m => (text.choice ? text.choice(product, m.name) : m.name)).join(', ') })}</p>
)}
</div>
</Dialog>
+3 -1
View File
@@ -23,7 +23,9 @@ export function productsIn(products, categoryId) {
export function searchProducts(products, query) {
const words = fold(query).split(/\s+/).filter(Boolean)
if (!words.length) return []
return products.filter(p => { const name = fold(p.name); return words.every(w => name.includes(w)) })
// the stored name or its text in any language (6R.L: a cashier may type in theirs)
const texts = p => [p.name, ...Object.values(p.translations ?? {}).map(v => (typeof v === 'string' ? v : v?.name))].filter(Boolean).map(fold)
return products.filter(p => { const all = texts(p); return words.every(w => all.some(name => name.includes(w))) })
}
/** Categories that have products, in their order (top level first, then by sort order). */
+12
View File
@@ -21,3 +21,15 @@ test('a product with a preference to pick needs the dialog; the line holds ids o
assert.equal('unit_price' in line, false)
assert.deepEqual(line.removed, [9])
})
test('search: the stored name or its text in any language (6R.L)', async () => {
const { searchProducts } = await import('../src/cart.js')
const list = [
{ id: 1, name: 'Πίτα γύρος', translations: { el: { name: 'Πίτα γύρος' }, en: { name: 'Gyros pita' } } },
{ id: 2, name: 'Freddo', translations: {} },
]
assert.deepEqual(searchProducts(list, 'gyros').map(p => p.id), [1])
assert.deepEqual(searchProducts(list, 'γυρος πιτα').map(p => p.id), [1])
assert.deepEqual(searchProducts(list, 'fred').map(p => p.id), [2])
assert.deepEqual(searchProducts(list, 'gyros fred').map(p => p.id), [])
})