Files
xenia-pos-local/packages/access/src/Allergens.jsx
T
bonaminandClaude Opus 5.5 5048f82a4c feat(manager): products and categories on v2, a product in several categories, allergens (platform-v2 step 6.3)
- Management/ProductsTab + ProductFormModal (3.1k lines) → src/pages/products/: category tree,
  list/grid, toolbar + filters (search folds accents and Latin letters), bulk actions, category
  dialogs; the editor in editor/ (details, sold at, cost, fiscal; the waiter's choices).
  Arithmetic in productsLogic.js / editor/formLogic.js (tests/products.test.mjs).
- Several categories per product with a main one (D-23): edited in the editor, "also in" on the
  rows, each category's list ordered on its own (drag or up/down → PUT /reorder with category_id);
  bulk "move to" / "also list in". The waiter's picker now shows a product in every category.
- Allergens: products.allergens (Alembic 0032, core/allergens.py: 14 EU, contains | may_contain,
  catalog.allergen), in the API, POS menu, menu tablet, catalogue bundles and the cloud snapshot
  (C-2); @xenia/access allergens.js + <Allergens> shown on the phone, the counter, the tablet.
- Bell: only the newest load sets the list (an older answer could hide a live notification).
- e2e: manager (two categories, order per category, allergens), terminal / menu tablet / waiter
  (allergens shown); media saves by test id.

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

34 lines
2.1 KiB
React

// A product's allergens for staff and guests (plan step 6.3): one small chip each, what it
// contains first (warning tone), then what it may contain (outlined), under a title. Styled with
// the @xenia/ui tokens inline, so every app (waiter, terminal, manager) shows it the same way.
// Nothing when none are declared, unless `showNone`.
import { useTranslation } from '@xenia/i18n'
import { allergenList } from './allergens.js'
const chip = level => ({
display: 'inline-flex', alignItems: 'center', gap: 4, padding: '2px 8px',
borderRadius: 999, fontSize: 'var(--x-text-caption)', fontWeight: 600, lineHeight: 1.6,
...(level === 'contains'
? { background: 'var(--x-warning-soft)', color: 'var(--x-warning-ink)', border: '1px solid transparent' }
: { background: 'transparent', color: 'var(--x-ink-2)', border: '1px dashed var(--x-line-strong)' }),
})
export function Allergens({ allergens, showNone = false, title = true, className, style }) {
const { t } = useTranslation('common')
const items = allergenList(allergens)
if (items.length === 0 && !showNone) return null
const groups = ['contains', 'may_contain'].map(level => [level, items.filter(i => i.level === level)]).filter(([, list]) => list.length)
return (
<div className={className} style={{ display: 'grid', gap: 6, ...style }} data-testid="allergens" data-count={items.length}>
{title && <div style={{ fontSize: 'var(--x-text-caption)', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.04em', color: 'var(--x-ink-3)' }}>{t('allergens.title')}</div>}
{items.length === 0 && <div style={{ fontSize: 'var(--x-text-label)', color: 'var(--x-ink-3)' }}>{t('allergens.none')}</div>}
{groups.map(([level, list]) => (
<div key={level} style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 4 }}>
<span style={{ fontSize: 'var(--x-text-caption)', color: 'var(--x-ink-2)', marginRight: 2 }}>{t(`allergens.level.${level}`)}:</span>
{list.map(i => <span key={i.key} style={chip(level)} data-allergen={i.key} data-level={level}>{t(`allergens.${i.key}`)}</span>)}
</div>
))}
</div>
)
}