feat(menu): the menu in English and Greek (platform-v2 step 6.4, D-29)
- products.translations / categories.translations (Alembic 0033, core/menu_languages.py: el + en,
name / description / quick options by their base name; catalog.translation). Empty = the text
as typed; no machine translation (owner).
- In the manager's product editor ("In English" / "In Greek", quick extras), the category dialog,
and a menu board's Language (signage MenuContent.language).
- Customer screens only: cloud snapshot names / descriptions per language (C-2), the menu tablet's
EL / EN switch the names (localize), signage boards; tickets, KDS, counter, phones keep the base.
- Catalogue bundles carry translations; @xenia/access menuLanguages.js (a backend test compares).
- e2e: manager (the other language saved), menu tablet (EN / EL names), QR table (English on
the menu, the base name on the kitchen's order, Greek page as typed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// (top level or under another category).
|
||||
import { useState } from 'react'
|
||||
import { Check } from 'lucide-react'
|
||||
import { translatedLanguages, useAccess } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, Input, Select, cx } from '@xenia/ui'
|
||||
import MediaField from '../media/MediaField'
|
||||
@@ -13,16 +14,25 @@ export default function CategoryDialog({ category, parentName, saving, onSave, o
|
||||
const [name, setName] = useState(category.name ?? '')
|
||||
const [color, setColor] = useState(category.color ?? CATEGORY_COLOURS[0])
|
||||
const [image, setImage] = useState(category.image ?? null)
|
||||
const { venue } = useAccess()
|
||||
const others = translatedLanguages(venue?.language)
|
||||
const [tr, setTr] = useState(() => Object.fromEntries(others.map(l => [l, category.translations?.[l]?.name ?? ''])))
|
||||
const sub = !!category.parent_id
|
||||
const title = t(`products.category.${category.id ? 'edit' : 'new'}${sub ? 'Sub' : ''}`)
|
||||
return (
|
||||
<Dialog open size="sm" onClose={onClose} title={title} description={sub && parentName ? t('products.category.under', { name: parentName }) : undefined}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('products.cancel')}</Button>
|
||||
<Button disabled={!name.trim()} loading={saving} onClick={() => onSave({ name: name.trim(), color, media_id: image?.id ?? null })} data-testid="category-save">{t('products.save')}</Button>
|
||||
<Button disabled={!name.trim()} loading={saving} onClick={() => onSave({ name: name.trim(), color, media_id: image?.id ?? null,
|
||||
translations: Object.fromEntries(Object.entries(tr).filter(([, v]) => v.trim()).map(([l, v]) => [l, { name: v.trim() }])) })} data-testid="category-save">{t('products.save')}</Button>
|
||||
</>}>
|
||||
<div className="grid gap-4">
|
||||
<Field label={t('products.category.name')}><Input value={name} onChange={e => setName(e.target.value)} autoFocus data-testid="category-name" /></Field>
|
||||
{others.map(l => (
|
||||
<Field key={l} label={t('products.editor.inLanguage', { language: t(`products.editor.lang.${l}`) })} hint={t('products.editor.trNameHint')}>
|
||||
<Input value={tr[l] ?? ''} onChange={e => setTr(s => ({ ...s, [l]: e.target.value }))} placeholder={name} data-testid={`category-name-${l}`} />
|
||||
</Field>
|
||||
))}
|
||||
<MediaField value={image} onChange={setImage} nameAfter={name} nameAfterLabel={t('media.nameAfterCategory')} label={t('media.photo')} testid="category-photo" />
|
||||
<div className="grid gap-2">
|
||||
<span className="text-label font-semibold text-ink">{t('products.category.colour')}</span>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// shared sub-set shown for every choice except those marked to hide it
|
||||
import { useRef, useState } from 'react'
|
||||
import { Heart, Plus, Trash2 } from 'lucide-react'
|
||||
import { translatedLanguages, useAccess } from '@xenia/access'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, EmptyState, IconButton, Input, Select, cx } from '@xenia/ui'
|
||||
import { favourites, moveChoice, moveFavourite, moveItem, removeChoice, removeGroup, setSub, toggleFavourite } from './formLogic'
|
||||
@@ -96,8 +97,10 @@ function Favourites({ form, setForm }) {
|
||||
|
||||
function QuickList({ form, setForm }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { venue } = useAccess()
|
||||
const others = translatedLanguages(venue?.language)
|
||||
const set = (i, k, v) => setForm(f => ({ ...f, quick_options: f.quick_options.map((q, j) => (j === i ? { ...q, [k]: v } : q)) }))
|
||||
const add = () => setForm(f => ({ ...f, quick_options: [...f.quick_options, { name: '', price: 0, allow_multiple: false, is_favorite: false, favorite_sort_order: 0, is_compact: false }] }))
|
||||
const add = () => setForm(f => ({ ...f, quick_options: [...f.quick_options, { name: '', price: 0, allow_multiple: false, is_favorite: false, favorite_sort_order: 0, is_compact: false, tr: {} }] }))
|
||||
return (
|
||||
<div>
|
||||
<Intro text={t('products.editor.quickHint')}><Button size="sm" variant="secondary" icon={<Plus size={14} />} onClick={add}>{t('products.editor.addQuick')}</Button></Intro>
|
||||
@@ -109,6 +112,10 @@ function QuickList({ form, setForm }) {
|
||||
onUp={() => setForm(f => ({ ...f, quick_options: moveItem(f.quick_options, i, -1) }))} onDown={() => setForm(f => ({ ...f, quick_options: moveItem(f.quick_options, i, 1) }))} />
|
||||
<FavouriteToggle on={q.is_favorite} onClick={() => setForm(f => toggleFavourite(f, 'quick', i))} />
|
||||
<Input className="flex-1 min-w-36" value={q.name} onChange={e => set(i, 'name', e.target.value)} placeholder={t('products.editor.quickPlaceholder')} />
|
||||
{others.map(l => (
|
||||
<Input key={l} className="flex-1 min-w-32" value={q.tr?.[l] ?? ''} onChange={e => set(i, 'tr', { ...(q.tr ?? {}), [l]: e.target.value })}
|
||||
placeholder={t('products.editor.inLanguageShort', { language: t(`products.editor.lang.${l}`) })} aria-label={t('products.editor.inLanguageShort', { language: t(`products.editor.lang.${l}`) })} />
|
||||
))}
|
||||
<PriceInput className="w-32" value={q.price} onChange={v => set(i, 'price', v)} label={t('products.editor.extraCost')} />
|
||||
<Check checked={q.allow_multiple} onChange={v => set(i, 'allow_multiple', v)}>{t('products.editor.multiple')}</Check>
|
||||
<Check checked={q.is_compact} onChange={v => set(i, 'is_compact', v)}>{t('products.editor.compact')}</Check>
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
import { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Plus, Trash2, X } from 'lucide-react'
|
||||
import { SALES_POINTS } from '@xenia/access'
|
||||
import { SALES_POINTS, translatedLanguages, useAccess } from '@xenia/access'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Field, IconButton, InfoTip, Input, Select, Switch, Textarea, cx } from '@xenia/ui'
|
||||
import MediaField from '../../media/MediaField'
|
||||
import { costOf } from '../productsLogic'
|
||||
import { AllergensField, CategoriesField } from './Fields'
|
||||
import { UNITS, WEIGHED, cleanTag } from './formLogic'
|
||||
import { UNITS, WEIGHED, cleanTag, setTranslation } from './formLogic'
|
||||
import { Check, PriceInput } from './parts'
|
||||
|
||||
export function InfoTab({ form, set, setForm, categories, prepZones }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { venue } = useAccess()
|
||||
const service = form.is_service_item
|
||||
const others = translatedLanguages(venue?.language)
|
||||
return (
|
||||
<div className="grid gap-4">
|
||||
<Switch checked={service} onChange={v => set('is_service_item', v)} label={t('products.editor.serviceItem')}
|
||||
@@ -29,6 +31,20 @@ export function InfoTab({ form, set, setForm, categories, prepZones }) {
|
||||
<Textarea rows={3} value={form.description} onChange={e => set('description', e.target.value)} />
|
||||
</Field>
|
||||
)}
|
||||
{!service && others.map(l => (
|
||||
<section key={l} className="grid gap-3 rounded-card border border-line bg-surface p-3" data-testid={`translation-${l}`}>
|
||||
<span className="flex items-center gap-1 text-label font-semibold text-ink">
|
||||
{t('products.editor.inLanguage', { language: t(`products.editor.lang.${l}`) })}
|
||||
<InfoTip>{t('products.editor.translationTip')}</InfoTip>
|
||||
</span>
|
||||
<Field label={t('products.editor.trName')} hint={t('products.editor.trNameHint')}>
|
||||
<Input value={form.translations?.[l]?.name ?? ''} onChange={e => setForm(f => setTranslation(f, l, 'name', e.target.value))} placeholder={form.name} data-testid={`translation-${l}-name`} />
|
||||
</Field>
|
||||
<Field label={t('products.editor.trDescription')}>
|
||||
<Textarea rows={2} value={form.translations?.[l]?.description ?? ''} onChange={e => setForm(f => setTranslation(f, l, 'description', e.target.value))} placeholder={form.description} />
|
||||
</Field>
|
||||
</section>
|
||||
))}
|
||||
{!service && <Tags tags={form.tags} onChange={v => set('tags', v)} />}
|
||||
{!service && (
|
||||
<Field label={t('products.editor.unit')} hint={WEIGHED.has(form.unit_type) ? t('products.editor.unitWeighed') : undefined}>
|
||||
|
||||
@@ -26,9 +26,12 @@ export function buildForm(p) {
|
||||
lifecycle_status: p.lifecycle_status ?? 'active',
|
||||
prep_zone_ids: [...(p.prep_zone_ids ?? [])],
|
||||
allergens: { ...(p.allergens ?? {}) },
|
||||
// the menu in other languages (6.4): {lang: {name, description}}; quick options' own on each row (`tr`)
|
||||
translations: Object.fromEntries(Object.entries(p.translations ?? {}).map(([l, v]) => [l, { name: v.name ?? '', description: v.description ?? '' }])),
|
||||
quick_options: (p.quick_options ?? []).map(q => ({
|
||||
name: q.name, price: q.price ?? 0, allow_multiple: !!q.allow_multiple, is_favorite: !!q.is_favorite,
|
||||
favorite_sort_order: q.favorite_sort_order ?? 0, is_compact: !!q.is_compact,
|
||||
tr: Object.fromEntries(Object.entries(p.translations ?? {}).map(([l, v]) => [l, v.quick?.[q.name] ?? ''])),
|
||||
})),
|
||||
options: (p.options ?? []).map(o => ({
|
||||
name: o.name, extra_cost: o.extra_cost ?? 0, allow_multiple: !!o.allow_multiple, multi_select: !!o.multi_select,
|
||||
@@ -84,6 +87,7 @@ export function buildBody(f) {
|
||||
lifecycle_status: f.lifecycle_status,
|
||||
prep_zone_ids: f.prep_zone_ids,
|
||||
allergens: f.allergens,
|
||||
translations: translationsBody(f),
|
||||
quick_options: f.quick_options.map((q, i) => ({
|
||||
name: q.name, price: num(q.price), allow_multiple: q.allow_multiple, sort_order: i,
|
||||
is_favorite: q.is_favorite, favorite_sort_order: q.favorite_sort_order, is_compact: q.is_compact,
|
||||
@@ -128,6 +132,22 @@ export function buildBody(f) {
|
||||
}
|
||||
}
|
||||
|
||||
/** The translations for the API: per language its name, description and the quick options' names (by their base name). */
|
||||
export function translationsBody(f) {
|
||||
const langs = new Set([...Object.keys(f.translations ?? {}), ...f.quick_options.flatMap(q => Object.keys(q.tr ?? {}))])
|
||||
const out = {}
|
||||
for (const l of langs) {
|
||||
const t = f.translations?.[l] ?? {}
|
||||
const quick = Object.fromEntries(f.quick_options.filter(q => q.name.trim() && (q.tr?.[l] ?? '').trim()).map(q => [q.name, q.tr[l].trim()]))
|
||||
const v = { ...(t.name?.trim() ? { name: t.name.trim() } : {}), ...(t.description?.trim() ? { description: t.description.trim() } : {}), ...(Object.keys(quick).length ? { quick } : {}) }
|
||||
if (Object.keys(v).length) out[l] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** A translated field of the product. */
|
||||
export const setTranslation = (f, lang, field, value) => ({ ...f, translations: { ...f.translations, [lang]: { ...(f.translations?.[lang] ?? {}), [field]: value } } })
|
||||
|
||||
/** Can it be saved: a name, and a price unless it's a service item. */
|
||||
export const canSave = f => !!f.name.trim() && (f.is_service_item || (f.base_price !== '' && f.base_price != null))
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// the draft (PlaylistEditor asks for it as you change things).
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { ArrowDown, ArrowUp, EyeOff, X } from 'lucide-react'
|
||||
import { SALES_POINTS } from '@xenia/access'
|
||||
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Field, IconButton, Input, Select, Switch } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
@@ -155,6 +155,10 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
<Select value={c.sales_point ?? ''} onChange={e => setC({ sales_point: e.target.value || null })} data-testid="signage-menu-prices"
|
||||
options={[{ value: '', label: t('signage.menu.noPrices') }, ...SALES_POINTS.map(sp => ({ value: sp, label: t(`common:salesPoints.${sp}.name`) }))]} />
|
||||
</Field>
|
||||
<Field label={t('signage.menu.language')} hint={t('signage.menu.languageHint')}>
|
||||
<Select value={c.language ?? ''} onChange={e => setC({ language: e.target.value || null })} data-testid="signage-menu-language"
|
||||
options={[{ value: '', label: t('signage.menu.asTyped') }, ...MENU_LANGUAGES.map(l => ({ value: l, label: t(`products.editor.lang.${l}`) }))]} />
|
||||
</Field>
|
||||
<Field label={t('signage.menu.soldOut')}>
|
||||
<Select value={c.sold_out || 'strike'} onChange={e => setC({ sold_out: e.target.value })}
|
||||
options={[{ value: 'strike', label: t('signage.menu.strike') }, { value: 'hide', label: t('signage.menu.hideSoldOut') }]} />
|
||||
|
||||
@@ -109,3 +109,13 @@ test('the editor: favourites across lists, choices, groups', () => {
|
||||
assert.equal(body.ingredients[0].group_id, 0) // the group's index in modifier_groups
|
||||
assert.equal(buildBody(removeGroup(f, 7)).ingredients[0].group_id, null)
|
||||
})
|
||||
|
||||
test('the editor keeps the menu in other languages (6.4)', () => {
|
||||
const f = buildForm({ name: 'Σουβλάκι', base_price: 3, quick_options: [{ name: 'Πίτα' }, { name: 'Σάλτσα' }],
|
||||
translations: { en: { name: 'Skewer', quick: { 'Πίτα': 'Pitta' } } } })
|
||||
assert.equal(f.translations.en.name, 'Skewer')
|
||||
assert.equal(f.quick_options[0].tr.en, 'Pitta')
|
||||
const renamed = { ...f, quick_options: [{ ...f.quick_options[0], name: 'Πίτα αραβική' }, f.quick_options[1]] }
|
||||
assert.deepEqual(buildBody(renamed).translations, { en: { name: 'Skewer', quick: { 'Πίτα αραβική': 'Pitta' } } }) // kept by the new base name
|
||||
assert.deepEqual(buildBody({ ...f, translations: { en: { name: ' ', description: '' } }, quick_options: [] }).translations, {})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user