// A menu board's settings (plan step 5.6b): which products (everything, whole categories that stay // up to date, single products, minus hidden ones), the board's own order of categories and products // (arrows on what the board shows), badges, prices of a sales point, photos / descriptions, sold-out // style, columns and pages, the look, and the widgets. `slide.menu` is the server's resolution of // the draft (the editor asks for it as you change things). // 2026-11-21 (owner review): sections with titles; what each line shows in fewer rows (the four // switches on one); the layout: columns, how wide the list is and where it sits (left / centre / // right), products per page, seconds per page. // Owner review 2 (2026-11-21): a product hidden from the board stays in the list, greyed, with a red // crossed eye (a green eye on the ones shown): a click shows / hides it; seconds per page explained; // the text's look on one row. `board` mode: the same editor for a menu widget's list (no background, // widgets, width or place; its own products per page). // Owner review 3 (2026-11-21): the look part by part (MenuLook: headings, names, prices, dots, // spacing, photos); a pencil beside each category and product on the board gives it a name for // this board only (the catalogue keeps its own: the waiters' names stay as they are). import { useEffect, useMemo, useState } from 'react' import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, Pencil, RotateCcw, X } from 'lucide-react' import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access' import { useFormat, useTranslation } from '@xenia/i18n' import { Dropdown, Field, IconButton, Input, Segmented, Select, Switch } from '@xenia/ui' import client from '../../api/client' import { BADGES, boardOrder, moveGroup, moveItem, toggled } from './signageLogic' import MenuLook from './MenuLook' import { BackgroundField, Range, Section } from './SignageFields' import WidgetsEditor from './WidgetsEditor' let catalogue = null // categories and products, read once for every menu editor on the page function useCatalogue() { const [data, setData] = useState(catalogue || { cats: [], products: [] }) useEffect(() => { if (catalogue) return Promise.all([client.get('/api/products/categories'), client.get('/api/products/')]).then(([c, p]) => { catalogue = { cats: c.data, products: p.data.filter(x => x.lifecycle_status === 'active' && !x.is_service_item) } setData(catalogue) }).catch(() => {}) }, []) return data } export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [], widget = null, onWidget, extras, board = false, testid = 'signage-menu-editor' }) { const { t } = useTranslation('manager') const { formatMoney } = useFormat() const c = slide.content || {} const setC = patch => onChange({ ...slide, content: { ...c, ...patch } }) const { cats, products } = useCatalogue() const [q, setQ] = useState('') const byId = useMemo(() => Object.fromEntries(products.map(p => [p.id, p])), [products]) const top = cats.filter(x => !x.parent_id) const subsOf = id => cats.filter(x => x.parent_id === id) const groups = slide.menu?.groups || [] const listed = new Set(groups.flatMap(g => g.items.map(i => i.id))) const found = q.trim().length < 1 ? [] : products.filter(p => p.name.toLowerCase().includes(q.trim().toLowerCase()) && !listed.has(p.id)).slice(0, 8) const reorder = next => setC(boardOrder(next)) const badges = c.badges || {} const digits = v => Number(String(v).replace(/\D/g, '')) const hidden = new Set(c.exclude_ids || []) // this board's own names: empty = the catalogue's again const rename = (key, id, name) => { const next = { ...(c[key] || {}) } if (name && name.trim()) next[String(id)] = name.trim() else delete next[String(id)] setC({ [key]: next }) } return (
{/* what it lists */}
setC({ title: e.target.value })} data-testid="signage-menu-title" /> setC({ select: v })} data-testid="signage-menu-select" options={[{ value: 'all', label: t('signage.menu.all') }, { value: 'custom', label: t('signage.menu.custom') }]} />
{c.select !== 'all' && <>
{t('signage.menu.categories')}

{t('signage.menu.categoriesHint')}

{top.flatMap(cat => [cat, ...subsOf(cat.id)]).map(cat => { const on = (c.category_ids || []).includes(cat.id) return ( ) })}
{t('signage.menu.products')} {(c.product_ids || []).length > 0 && (
{(c.product_ids || []).map(id => ( {byId[id]?.name ?? `#${id}`} setC({ product_ids: (c.product_ids || []).filter(x => x !== id), exclude_ids: (c.exclude_ids || []).filter(x => x !== id) })}> ))}
)} setQ(e.target.value)} placeholder={t('signage.menu.searchProduct')} aria-label={t('signage.menu.searchProduct')} data-testid="signage-menu-search" /> {found.length > 0 && (
    {found.map(p => (
  • ))}
)}
}
{/* the board's own order, badges, hiding (hidden ones stay here, greyed) */}

{t('signage.menu.orderHint')}

{groups.map((g, gi) => (
{g.category && (
rename('category_names', g.category.id, v)} className="text-label font-semibold text-ink" testid="signage-category-name" /> reorder(moveGroup(groups, gi, -1))} data-testid="signage-group-up"> reorder(moveGroup(groups, gi, 1))}>
)}
    {g.items.map((it, ii) => { const off = it.hidden || hidden.has(it.id) return (
  • rename('names', it.id, v)} testid="signage-item-name" className={`text-label ${off ? 'text-ink-3 opacity-70' : it.available ? 'text-ink' : 'text-ink-3 line-through'}`} /> {off && {t('signage.menu.hiddenTag')}} {it.price != null && {formatMoney(it.price)}} { const n = digits(e.target.value); setC({ page_size: n ? Math.min(60, Math.max(3, n)) : null }) }} data-testid="signage-menu-per-page" /> setC({ page_seconds: Math.min(120, Math.max(3, digits(e.target.value) || 3)) })} />
{!board && <> setC({ background })} media={media} onMedia={onMedia} misfit={misfit.includes(c.background?.media_id)} /> setC({ widgets })} media={media} onMedia={onMedia} selected={widget} onSelect={onWidget} extras={extras} /> }
) } /** * A category's or product's name on the board, with a pencil (shown on hover or focus) to give it a * name for this board only; the catalogue's name shows under it then, with a button to go back to it. */ function OwnName({ name, original, onSave, className = '', testid }) { const { t } = useTranslation('manager') const [edit, setEdit] = useState(null) if (edit != null) { const done = () => { onSave(edit); setEdit(null) } return ( setEdit(e.target.value)} onBlur={done} onKeyDown={e => { if (e.key === 'Enter') done(); if (e.key === 'Escape') setEdit(null) }} /> ) } return ( {name} {original && {t('signage.menu.catalogueNameIs', { name: original })}} setEdit(name)} data-testid={`${testid}-edit`} className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0"> {original && ( onSave('')} data-testid={`${testid}-reset`} className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0"> )} ) }