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:
@@ -16,6 +16,7 @@ import { assetUrl } from '../config/server'
|
||||
import { money } from '../i18n'
|
||||
import { LineError, estimate, wireLine } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { useMenuText } from '@xenia/access'
|
||||
import { fade } from '../logic/colour'
|
||||
import SeatsHint from '../components/SeatsHint'
|
||||
|
||||
@@ -156,6 +157,7 @@ function fmtDraftQty(qty, unitType) {
|
||||
|
||||
export default function AddItemsPage() {
|
||||
const { t } = useTranslation('waiter')
|
||||
const mt = useMenuText() // 6R.L: names in the waiter's language; the cart keeps ids and stored names
|
||||
const { tableId, orderType } = useParams()
|
||||
const isStandalone = !!orderType // true when on /standalone/:orderType/add
|
||||
const [searchParams] = useSearchParams()
|
||||
@@ -434,6 +436,7 @@ export default function AddItemsPage() {
|
||||
// Returns structured sections for the expanded cart view
|
||||
function buildItemSections(item, product) {
|
||||
const sections = []
|
||||
const c = name => mt.choice(product, name) // 6R.L: shown in the waiter's language
|
||||
|
||||
if (item.selected_options?.length) {
|
||||
const prefIds = new Set(
|
||||
@@ -442,7 +445,7 @@ export default function AddItemsPage() {
|
||||
// Build a map: prefChoiceId → preference set name
|
||||
const prefSetByChoiceId = {}
|
||||
;(product?.preference_sets || []).forEach(ps => {
|
||||
ps.choices.forEach(c => { prefSetByChoiceId[c.id] = ps.name })
|
||||
ps.choices.forEach(ch => { prefSetByChoiceId[ch.id] = mt(ps) })
|
||||
})
|
||||
const quickNames = new Set((product?.quick_options || []).map(o => o.name))
|
||||
const extraIds = new Set((product?.options || []).map(o => o.id))
|
||||
@@ -462,7 +465,7 @@ export default function AddItemsPage() {
|
||||
const setName = prefSetByChoiceId[o.id] ?? ''
|
||||
let subName = null
|
||||
if (i + 1 < opts.length && opts[i + 1].id == null) {
|
||||
subName = opts[i + 1].name
|
||||
subName = c(opts[i + 1].name)
|
||||
i += 2
|
||||
} else {
|
||||
i++
|
||||
@@ -471,15 +474,15 @@ export default function AddItemsPage() {
|
||||
const existing = prefGroups.find(g => g.setName === setName)
|
||||
if (existing) {
|
||||
// multiple choices from same set (shouldn't normally happen, but handle gracefully)
|
||||
existing.values.push(subName ? `${o.name} · ${subName}` : o.name)
|
||||
existing.values.push(subName ? `${c(o.name)} · ${subName}` : c(o.name))
|
||||
} else {
|
||||
prefGroups.push({ setName, values: [subName ? `${o.name} · ${subName}` : o.name] })
|
||||
prefGroups.push({ setName, values: [subName ? `${c(o.name)} · ${subName}` : c(o.name)] })
|
||||
}
|
||||
} else if (o.id != null && extraIds.has(o.id)) {
|
||||
// Collect sub immediately following
|
||||
let subName = null
|
||||
if (i + 1 < opts.length && opts[i + 1].id == null) {
|
||||
subName = opts[i + 1].name
|
||||
subName = c(opts[i + 1].name)
|
||||
i += 2
|
||||
} else {
|
||||
i++
|
||||
@@ -487,9 +490,9 @@ export default function AddItemsPage() {
|
||||
// Merge duplicates
|
||||
const existing = extraGroups.find(g => g.id === o.id && g.subName === subName)
|
||||
if (existing) existing.qty++
|
||||
else extraGroups.push({ id: o.id, name: o.name, subName, qty: 1 })
|
||||
else extraGroups.push({ id: o.id, name: c(o.name), subName, qty: 1 })
|
||||
} else if (quickNames.has(o.name)) {
|
||||
quickLines.push(o)
|
||||
quickLines.push({ ...o, name: c(o.name) })
|
||||
i++
|
||||
} else {
|
||||
i++
|
||||
@@ -510,7 +513,7 @@ export default function AddItemsPage() {
|
||||
}
|
||||
|
||||
if (item.removed_ingredients?.length) {
|
||||
sections.push({ type: 'removed', lines: item.removed_ingredients.map(n => ({ name: n })) })
|
||||
sections.push({ type: 'removed', lines: item.removed_ingredients.map(n => ({ name: c(n) })) })
|
||||
}
|
||||
|
||||
if (item.notes) {
|
||||
@@ -523,14 +526,15 @@ export default function AddItemsPage() {
|
||||
// Simple flat summary for the collapsed one-liner
|
||||
function buildItemSummary(item) {
|
||||
const lines = []
|
||||
const c = name => mt.choice(getProduct(item.product_id), name) // 6R.L
|
||||
if (item.selected_options?.length) {
|
||||
item.selected_options.forEach(o => {
|
||||
if (o.price_delta && o.price_delta !== 0)
|
||||
lines.push(`${o.name} (${o.price_delta > 0 ? '+' : ''}${money(o.price_delta)})`)
|
||||
else lines.push(o.name)
|
||||
lines.push(`${c(o.name)} (${o.price_delta > 0 ? '+' : ''}${money(o.price_delta)})`)
|
||||
else lines.push(c(o.name))
|
||||
})
|
||||
}
|
||||
if (item.removed_ingredients?.length) lines.push(t('add.withoutList', { names: item.removed_ingredients.join(', ') }))
|
||||
if (item.removed_ingredients?.length) lines.push(t('add.withoutList', { names: item.removed_ingredients.map(c).join(', ') }))
|
||||
if (item.notes) lines.push(item.notes)
|
||||
return lines
|
||||
}
|
||||
@@ -682,7 +686,7 @@ export default function AddItemsPage() {
|
||||
const p = getProduct(item.product_id)
|
||||
return (
|
||||
<div key={item._key} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flex: 1 }}>{p?.name ?? `#${item.product_id}`}</span>
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flex: 1 }}>{p ? mt(p) : `#${item.product_id}`}</span>
|
||||
<span style={{ fontSize: 12, fontWeight: 700, color: 'var(--x-warning)', fontVariantNumeric: 'tabular-nums', flexShrink: 0 }}>{fmtDraftQty(item.quantity, p?.unit_type)}</span>
|
||||
</div>
|
||||
)
|
||||
@@ -1167,7 +1171,8 @@ function DealOfferModal({ offer, _products, onAccept, onDismiss }) {
|
||||
|
||||
function QuickAddToast({ product, count }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const initials = product.name.trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()
|
||||
const mt = useMenuText()
|
||||
const initials = mt(product).trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()
|
||||
return (
|
||||
<div style={{
|
||||
position: 'fixed', top: 62, left: '50%',
|
||||
@@ -1199,7 +1204,7 @@ function QuickAddToast({ product, count }) {
|
||||
<div style={{
|
||||
fontSize: 13, fontWeight: 600, color: 'var(--text)',
|
||||
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
}}>{product.name}</div>
|
||||
}}>{mt(product)}</div>
|
||||
<div style={{ fontSize: 11, color: 'var(--muted)', marginTop: 1 }}>{t('add.inCart')}</div>
|
||||
</div>
|
||||
{/* Count badge */}
|
||||
@@ -1243,6 +1248,7 @@ function SectionIcon({ type }) {
|
||||
|
||||
function CartItem({ item, product, summaryLines, sections, onEdit, onRemove, onChangeQty }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const mt = useMenuText()
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const hasDetails = sections.length > 0
|
||||
|
||||
@@ -1261,7 +1267,7 @@ function CartItem({ item, product, summaryLines, sections, onEdit, onRemove, onC
|
||||
{/* Name */}
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{product?.name ?? `#${item.product_id}`}
|
||||
{product ? mt(product) : `#${item.product_id}`}
|
||||
</div>
|
||||
{!expanded && hasDetails && (
|
||||
<div style={{ fontSize: 11, color: 'var(--muted)', marginTop: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
@@ -1380,14 +1386,13 @@ function CartItem({ item, product, summaryLines, sections, onEdit, onRemove, onC
|
||||
|
||||
function SearchModal({ products, query, setQuery, onClose, onAdd, courses = [], quickNotes }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const mt = useMenuText() // 6R.L: shown in the waiter's language, found by either
|
||||
const [drawerProduct, setDrawerProduct] = useState(null)
|
||||
const activeProducts = products.filter(p => p.lifecycle_status !== 'archived')
|
||||
|
||||
const results = query.trim().length === 0
|
||||
? []
|
||||
: activeProducts.filter(p =>
|
||||
p.name.toLowerCase().includes(query.trim().toLowerCase())
|
||||
)
|
||||
: activeProducts.filter(p => mt.matches(p, query.trim().toLowerCase()))
|
||||
|
||||
function openProduct(p) {
|
||||
// Blur the input first so the keyboard dismisses, then open the drawer
|
||||
@@ -1425,7 +1430,7 @@ function SearchModal({ products, query, setQuery, onClose, onAdd, courses = [],
|
||||
{t('add.search.none', { query })}
|
||||
</p>
|
||||
) : results.map(p => {
|
||||
const initials = p.name.trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()
|
||||
const initials = mt(p).trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()
|
||||
return (
|
||||
<button
|
||||
key={p.id}
|
||||
@@ -1450,7 +1455,7 @@ function SearchModal({ products, query, setQuery, onClose, onAdd, courses = [],
|
||||
</div>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{p.name}
|
||||
{mt(p)}
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 2 }}>
|
||||
{money(p.base_price)}
|
||||
|
||||
Reference in New Issue
Block a user