setQ(e.target.value)}
- placeholder={t.searchPlaceholder}
- className="w-full bg-transparent text-[15px] text-[#2d3b2d] outline-none placeholder:text-[#b3aa90]"
- />
- {q && (
-
+
+
+
+ setQ(e.target.value)} placeholder={t('search')} aria-label={t('search')} data-testid="search-input"
+ className="flex-1 bg-transparent outline-none text-ink placeholder:text-ink-3" />
-
+
-
-
- {q && results.length === 0 && (
-
-
-
{t.noResults}
-
{t.noResultsSub}
-
- )}
- {results.length > 0 && (
-
- {results.map(p => {
- const cat = categories.find(c => c.id === p.cat)
- return (
-
{ onClose(); onOpen(prod) }}
- onAdd={onAdd}
- qty={cart[p.id] || 0}
- viewOnly={viewOnly}
- />
- )
- })}
-
- )}
- {!q && (
-
-
-
{t.searchPlaceholder}
-
+
+ {q.trim() && found.length === 0 && (
+
{t('noResults')}
{t('noResultsBody')}
)}
+ {found.map(p =>
onOpen(p)} onAdd={() => onAdd(p)} onRemove={() => onRemove(p)} />)}
)
}
-// ── Cart Flow (bottom sheet) ──────────────────────────────────────────────────
-function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenProduct, siteSlug, navigate, table, tableToken }) {
- const [form, setForm] = useState({ name: '' })
+function CartSheet({ stage, setStage, lines, table, onAdd, onRemove, onSend }) {
+ const { t, money } = useT()
+ const [name, setName] = useState('')
const [sending, setSending] = useState(false)
- const [sendError, setSendError] = useState('')
-
- const allProducts = useMemo(() => categories.flatMap(c => c.products), [categories])
-
- const lines = useMemo(() =>
- Object.entries(cart)
- .map(([id, qty]) => ({ product: allProducts.find(p => p.id === id), qty }))
- .filter(l => l.product && l.qty > 0),
- [cart, allProducts]
- )
- const total = lines.reduce((s, l) => s + discountedPrice(l.product) * l.qty, 0)
-
- const inc = p => setCart(c => ({ ...c, [p.id]: (c[p.id] || 0) + 1 }))
- const dec = p => setCart(c => {
- const n = (c[p.id] || 0) - 1
- const next = { ...c }
- if (n <= 0) delete next[p.id]; else next[p.id] = n
- return next
- })
-
- const submit = async () => {
- setSending(true)
- setSendError('')
- try {
- const result = await submitOrder(siteSlug, {
- // the table comes from its QR code (S.7): the cloud checks the token, never a typed number
- order_type: 'dine_in',
- table_token: tableToken,
- customer_name: form.name.trim() || `${t.table} ${table?.label ?? ''}`.trim(),
- items: lines.map(l => ({
- product_id: Number(l.product.id),
- quantity: l.qty,
- unit_price: discountedPrice(l.product),
- })),
- total: Math.round(total * 100) / 100,
- })
- setCart({})
- setForm({ name: '' })
- setStage(null)
- // the cloud prices the order itself (phase 3S, S.2); the tracking link is the order's token
- navigate(`/${siteSlug}/confirm/${result.tracking_token ?? result.public_ref}`)
- } catch (err) {
- const code = err?.response?.data?.detail?.code
- setSendError(code === 'order.price_changed' || code === 'order.item_unavailable' || code === 'order.option_unavailable'
- ? t.orderChanged : code === 'order.table_invalid' ? t.tableInvalid : code === 'order.service_unavailable' ? t.orderingOff : t.orderFailed)
- setSending(false)
- }
- }
-
+ const [problem, setProblem] = useState(null)
+ const total = cartTotal(lines)
const close = () => setStage(null)
-
- // Cart view
- if (stage === 'cart') {
- return (
-
-
-
-
{t.yourOrder}
-
-
- {lines.length === 0 ? (
-
-
-
{t.emptyCart}
-
{t.emptyCartSub}
-
- ) : (
- <>
-
-
- {lines.map(l => {
- const cat = categories.find(c => c.id === l.product.cat)
- const pname = typeof l.product.name === 'object' ? (l.product.name[lang] ?? l.product.name.en) : l.product.name
- return (
-
-
-
-
{ close(); onOpenProduct(l.product) }}
- className="cursor-pointer font-display text-[16px] font-semibold leading-tight text-[#2d3b2d]"
- >
- {pname}
-
-
{eur(discountedPrice(l.product))}
-
-
inc(l.product)} onDec={() => dec(l.product)} />
-
- )
- })}
-
-
-
-
- {t.total}
- {eur(total)}
-
-
-
- >
- )}
-
- )
+ const send = async () => {
+ setSending(true)
+ setProblem(null)
+ try { await onSend(name) } catch (err) { setProblem(refusalKey(err?.response?.data?.detail?.code ?? err?.response?.data?.error?.code)); setSending(false) }
}
-
- // Checkout view
- if (stage === 'checkout') {
- const valid = lines.length > 0
- return (
-
-
-
-
-
{t.placeOrder}
-
-
-
-
{t.table} {table?.label}
-
-
-
-
{t.orderSummary}
-
- {lines.map((l, i) => {
- const pname = typeof l.product.name === 'object' ? (l.product.name[lang] ?? l.product.name.en) : l.product.name
- return (
-
0 ? 'border-t border-[#f0ebdd]' : ''}`}>
-
- {l.qty}× {pname}
-
-
- {eur(discountedPrice(l.product) * l.qty)}
-
-
- )
- })}
-
-
-
-
- {t.total}
- {eur(total)}
-
- {sendError &&
{sendError}
}
-
-
-
- )
- }
-
- return null
-}
-
-// ── Floating Cart Button ──────────────────────────────────────────────────────
-function CartButton({ count, total, t, onClick }) {
- const [bump, setBump] = useState(false)
- const prev = useRef(count)
- useEffect(() => {
- if (count !== prev.current && count > 0) {
- setBump(true)
- const tm = setTimeout(() => setBump(false), 320)
- prev.current = count
- return () => clearTimeout(tm)
- }
- prev.current = count
- }, [count])
-
- if (count === 0) return null
return (
-
-
-
- )
-}
-
-// ── Main MenuPage ─────────────────────────────────────────────────────────────
-const TABLE_KEY = site => `xenia-qr-table:${site}`
-
-export default function MenuPage() {
- const { siteSlug } = useParams()
- const navigate = useNavigate()
- const [params] = useSearchParams()
- // the table's QR code carries its token (?t=…); kept for this visit so a reload keeps the table
- const [tableToken] = useState(() => {
- const fromUrl = params.get('t')
- try {
- if (fromUrl) sessionStorage.setItem(TABLE_KEY(siteSlug), fromUrl)
- return fromUrl || sessionStorage.getItem(TABLE_KEY(siteSlug)) || null
- } catch { return fromUrl }
- })
- const [table, setTable] = useState(null)
- const [tableInvalid, setTableInvalid] = useState(false)
-
- const [categories, setCategories] = useState([])
- const [restaurant, setRestaurant] = useState(null)
- const [viewOnly, setViewOnly] = useState(false)
- const [error, setError] = useState(null)
- const [loading, setLoading] = useState(true)
-
- const [lang, setLang] = useState(() => {
- try { return localStorage.getItem('ot_lang') || 'en' } catch { return 'en' }
- })
- const [cart, setCart] = useState(() => {
- try { return JSON.parse(localStorage.getItem('ot_cart')) || {} } catch { return {} }
- })
- const [active, setActive] = useState(null)
- const [activeProduct, setActiveProduct] = useState(null)
- const [activeProductCat, setActiveProductCat] = useState(null)
- const [searchOpen, setSearchOpen] = useState(false)
- const [stage, setStage] = useState(null)
-
- const t = I18N[lang] ?? I18N.en
-
- useEffect(() => { try { localStorage.setItem('ot_lang', lang) } catch {} }, [lang])
- useEffect(() => { try { localStorage.setItem('ot_cart', JSON.stringify(cart)) } catch {} }, [cart])
-
- useEffect(() => {
- fetchMenu(siteSlug, tableToken)
- .then(data => {
- const cats = normaliseCategories(data.categories || [])
- setCategories(cats)
- setRestaurant(data.restaurant ?? null)
- // ordering only at a real table, when the venue allows it (S.7); otherwise a menu to read
- setTable(data.table ?? null)
- setTableInvalid(!!data.table_invalid)
- setViewOnly(!(data.table_ordering && data.table))
- if (cats.length) setActive(cats[0].id)
- })
- .catch(() => setError('Menu not available. Please try again.'))
- .finally(() => setLoading(false))
- }, [siteSlug, tableToken])
-
- const sectionRefs = useRef({})
- const clickLock = useRef(false)
-
- // Scroll-spy
- useEffect(() => {
- const onScroll = () => {
- if (clickLock.current) return
- let current = categories[0]?.id
- for (const c of categories) {
- const el = sectionRefs.current[c.id]
- if (el && el.getBoundingClientRect().top <= 90) current = c.id
- }
- if (current) setActive(a => a === current ? a : current)
- }
- window.addEventListener('scroll', onScroll, { passive: true })
- onScroll()
- return () => window.removeEventListener('scroll', onScroll)
- }, [categories])
-
- const pick = id => {
- const el = sectionRefs.current[id]
- if (!el) return
- setActive(id)
- clickLock.current = true
- const top = el.getBoundingClientRect().top + window.scrollY - 64
- window.scrollTo({ top, behavior: 'smooth' })
- setTimeout(() => { clickLock.current = false }, 700)
- }
-
- const addToCart = p => setCart(c => ({ ...c, [p.id]: (c[p.id] || 0) + 1 }))
- const incCart = p => setCart(c => ({ ...c, [p.id]: (c[p.id] || 0) + 1 }))
- const decCart = p => setCart(c => {
- const n = (c[p.id] || 0) - 1
- const next = { ...c }
- if (n <= 0) delete next[p.id]; else next[p.id] = n
- return next
- })
-
- const openProduct = p => {
- setActiveProduct(p)
- setActiveProductCat(categories.find(c => c.id === p.cat) ?? null)
- }
-
- const count = Object.values(cart).reduce((s, q) => s + q, 0)
- const total = useMemo(() => {
- const allProducts = categories.flatMap(c => c.products)
- return Object.entries(cart).reduce((s, [id, q]) => {
- const p = allProducts.find(x => x.id === id)
- return p ? s + discountedPrice(p) * q : s
- }, 0)
- }, [cart, categories])
-
- if (loading) return (
-
- )
-
- if (error) return (
-
- )
-
- return (
-
-
-
setSearchOpen(true)}
- lang={lang}
- />
-
- {(table && !viewOnly) || tableInvalid ? (
-
- {tableInvalid ? t.tableInvalid : t.atTable.replace('{table}', table.label)}
-
- ) : null}
-
-
- {categories.map(cat => (
- { sectionRefs.current[cat.id] = el }}
- viewOnly={viewOnly}
- />
- ))}
-
-
-
-
- {!viewOnly && setStage('cart')} />}
-
- setActiveProduct(null)}
- onAdd={addToCart}
- qty={activeProduct ? (cart[activeProduct.id] || 0) : 0}
- onInc={incCart}
- onDec={decCart}
- viewOnly={viewOnly}
- />
-
- setSearchOpen(false)}
- categories={categories}
- lang={lang}
- t={t}
- onOpen={openProduct}
- onAdd={addToCart}
- cart={cart}
- viewOnly={viewOnly}
- />
-
- {!viewOnly && (
-
- )}
-
+
+
+ {stage === 'checkout' && }
+
{stage === 'cart' ? t('yourOrder') : t('checkout')}
+
+
+ {lines.length === 0 ? (
+ {t('empty')}
{t('emptyBody')}
+ ) : stage === 'cart' ? (<>
+
+ {lines.map(l => (
+ -
+ {l.product.name}
+ onAdd(l.product)} onRemove={() => onRemove(l.product)} />
+
+ ))}
+
+ {t('total')}
+
+ >) : (<>
+ {t('table')} {table?.label}
+
+
+
{t('summary')}
+ {lines.map(l => (
+
{l.qty}× {l.product.name}
+ ))}
+
+ {t('payNote')}
+ {problem && {t(problem)}
}
+
+ >)}
+
)
}
diff --git a/connect_frontend/menu-app/src/pages/OrderConfirm.jsx b/connect_frontend/menu-app/src/pages/OrderConfirm.jsx
deleted file mode 100644
index a103b6c..0000000
--- a/connect_frontend/menu-app/src/pages/OrderConfirm.jsx
+++ /dev/null
@@ -1,115 +0,0 @@
-import { useEffect, useState } from 'react'
-import { useParams } from 'react-router-dom'
-import { Check, Clock, X, Leaf } from 'lucide-react'
-import { fetchOrderStatus } from '../api'
-
-// A table order from the QR menu (phase 3S, S.7): sent → in the kitchen (or not taken).
-// Takeaway and delivery have their own app since S.4 (/order/), so their steps are gone here.
-const STATUS_CONFIG = {
- pending_acceptance: { label: 'Sending your order to the kitchen…', Icon: Clock, color: '#c9a24b', bg: '#f6edd6' },
- accepted: { label: 'Your order is in the kitchen', Icon: Check, color: '#3f7d4e', bg: '#e7f1e7' },
- rejected: { label: 'Order not taken', Icon: X, color: '#c2602f', bg: '#f7e6dc' },
-}
-
-const TERMINAL = new Set(['accepted', 'rejected', 'delivered', 'preparing', 'ready'])
-const POLL_MS = 10_000
-
-export default function OrderConfirm() {
- const { ref } = useParams()
- const [orderStatus, setOrderStatus] = useState(null)
- const [rejectionReason, setRejectionReason] = useState(null)
- const [publicRef, setPublicRef] = useState(null) // the link carries a token (S.2); show the order number
- const [error, setError] = useState(false)
-
- useEffect(() => {
- let timer
-
- async function poll() {
- try {
- const data = await fetchOrderStatus(ref)
- setOrderStatus(data.status)
- setPublicRef(data.public_ref)
- setRejectionReason(data.rejection_reason)
- if (!TERMINAL.has(data.status)) {
- timer = setTimeout(poll, POLL_MS)
- }
- } catch {
- setError(true)
- }
- }
-
- poll()
- return () => clearTimeout(timer)
- }, [ref])
-
- const cfg = STATUS_CONFIG[orderStatus] ?? (TERMINAL.has(orderStatus) ? STATUS_CONFIG.accepted : STATUS_CONFIG.pending_acceptance)
- const { label, Icon, color, bg } = cfg
-
- return (
-
-
- {/* Ornament top */}
-
-
-
-
-
-
- {/* Status icon */}
-
-
-
-
- {/* Ref number */}
-
- {publicRef ?? ''}
-
-
- {/* Status label */}
-
- {error ? 'Could not load status' : label}
-
-
- {/* Rejection reason */}
- {rejectionReason && (
-
- Reason: {rejectionReason}
-
- )}
-
- {/* Subtext */}
- {TERMINAL.has(orderStatus) && orderStatus !== 'rejected' && (
-
- Thank you! Your waiter will bring it to your table. Enjoy your meal.
-
- )}
- {orderStatus === 'rejected' && (
-
- We're sorry we couldn't take your order this time. Please try again or speak to staff.
-
- )}
- {!TERMINAL.has(orderStatus) && !error && (
-
- We'll update this page automatically. Keep it open.
-
- )}
-
- {/* Spinner */}
- {!TERMINAL.has(orderStatus) && !error && (
-
- )}
-
- {/* Ornament bottom */}
-
-
-
-
-
-
- )
-}
diff --git a/connect_frontend/menu-app/tailwind.config.js b/connect_frontend/menu-app/tailwind.config.js
index 394fdab..6b3fc4c 100644
--- a/connect_frontend/menu-app/tailwind.config.js
+++ b/connect_frontend/menu-app/tailwind.config.js
@@ -1,51 +1,29 @@
+// The QR menu (plan step 6.5) on the customer apps' look: the same tokens as the order app.
/** @type {import('tailwindcss').Config} */
+// Colours are tokens (CSS variables in src/index.css), never literals in components: one
+// place to restyle the app, the same token names as the venue apps' @xenia/ui.
+const c = name => `rgb(var(--o-${name}) /
)`
+
export default {
content: ['./index.html', './src/**/*.{js,jsx}'],
theme: {
extend: {
fontFamily: {
- display: ['Bricolage Grotesque', 'Noto Sans', 'system-ui', 'sans-serif'],
sans: ['Hanken Grotesk', 'Noto Sans', 'system-ui', 'sans-serif'],
+ display: ['Bricolage Grotesque', 'Noto Sans', 'system-ui', 'sans-serif'],
},
colors: {
- brand: {
- dark: '#2d3b2d',
- hover: '#26331f',
- },
- cream: '#faf7f0',
- card: '#fcfbf7',
- gold: '#c9a24b',
- terracotta: '#c2602f',
- sage: '#9caf88',
- success: '#3f7d4e',
- },
- borderRadius: {
- card: '20px',
- section: '22px',
- sheet: '24px',
- },
- boxShadow: {
- card: '0 5px 16px -10px rgba(45,42,31,0.45)',
- 'card-hover': '0 10px 24px -12px rgba(45,42,31,0.5)',
- cart: '0 12px 28px -8px rgba(45,59,45,0.55)',
- },
- keyframes: {
- fade: { from: { opacity: 0 }, to: { opacity: 1 } },
- slideup: {
- from: { transform: 'translateY(100%)' },
- to: { transform: 'translateY(0)' },
- },
- pop: {
- '0%': { transform: 'scale(1)' },
- '50%': { transform: 'scale(1.06)' },
- '100%': { transform: 'scale(1)' },
- },
- },
- animation: {
- fade: 'fade 0.2s ease',
- slideup: 'slideup 0.28s cubic-bezier(0.22,1,0.36,1)',
- pop: 'pop 0.32s ease',
+ canvas: c('canvas'),
+ surface: { DEFAULT: c('surface'), 2: c('surface-2') },
+ line: c('line'),
+ ink: { DEFAULT: c('ink'), 2: c('ink-2'), 3: c('ink-3') },
+ accent: { DEFAULT: c('accent'), fg: c('accent-fg'), soft: c('accent-soft'), ink: c('accent-ink') },
+ success: { DEFAULT: c('success'), soft: c('success-soft'), ink: c('success-ink') },
+ warning: { soft: c('warning-soft'), ink: c('warning-ink') },
+ danger: { soft: c('danger-soft'), ink: c('danger-ink') },
},
+ borderRadius: { card: '18px', control: '12px' },
+ boxShadow: { card: '0 6px 18px -12px rgb(var(--o-shadow) / 0.45)', bar: '0 12px 28px -10px rgb(var(--o-shadow) / 0.6)' },
},
},
plugins: [],
diff --git a/connect_frontend/menu-app/tests/logic.test.mjs b/connect_frontend/menu-app/tests/logic.test.mjs
new file mode 100644
index 0000000..1bd0ae3
--- /dev/null
+++ b/connect_frontend/menu-app/tests/logic.test.mjs
@@ -0,0 +1,61 @@
+// The QR menu's logic (plan step 6.5).
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { allergenList, cartCount, cartLines, cartTotal, fold, menuFor, orderBody, refusalKey, search, setQty } from '../src/logic.js'
+
+const data = { categories: [
+ { id: 1, name: 'Ψητά', names: { el: 'Ψητά', en: 'Grill' }, products: [
+ { id: 5, name: 'Σουβλάκι', names: { el: 'Σουβλάκι', en: 'Pork skewer' }, descriptions: { el: 'Με πίτα', en: 'With pitta' },
+ prices: { qr_table: 3.5, online_delivery: 4 }, sold_at: ['qr_table', 'online_delivery'], allergens: { gluten: 'contains', sesame: 'may_contain' } },
+ { id: 6, name: 'Μπριζόλα', prices: { qr_table: 12 }, sold_at: ['qr_table'], digital_available: false },
+ { id: 7, name: 'Delivery only', prices: { online_delivery: 9 }, sold_at: ['online_delivery'] },
+ ] },
+ { id: 2, name: 'Ορεκτικά', products: [{ id: 5, name: 'Σουβλάκι', names: { el: 'Σουβλάκι', en: 'Pork skewer' }, prices: { qr_table: 3.5 }, sold_at: ['qr_table'] }] },
+ { id: 3, name: 'Empty', products: [{ id: 7, name: 'x', prices: {}, sold_at: ['online_takeaway'] }] },
+] }
+
+test('the menu in the guest\'s language, the QR menu\'s prices, only what it sells', () => {
+ const en = menuFor(data, 'en')
+ assert.deepEqual(en.map(c => c.name), ['Grill', 'Ορεκτικά']) // a category without a translation: as typed
+ const souv = en[0].products[0]
+ assert.equal(souv.name, 'Pork skewer')
+ assert.equal(souv.description, 'With pitta')
+ assert.equal(souv.price, 3.5)
+ assert.equal(en[0].products.length, 2) // the delivery-only dish isn't here
+ assert.equal(en[0].products[1].available, false)
+ assert.equal(en[1].products[0].repeat, true) // listed twice: search shows it once
+ assert.equal(menuFor(data, 'el')[0].products[0].name, 'Σουβλάκι')
+})
+
+test('allergens: contains first, then may contain; older array data still read', () => {
+ assert.deepEqual(allergenList({ sesame: 'may_contain', milk: 'contains', pollen: 'contains' }), [{ key: 'milk', level: 'contains' }, { key: 'sesame', level: 'may_contain' }])
+ assert.deepEqual(allergenList(['gluten', 'dairy']), [{ key: 'gluten', level: 'contains' }])
+ assert.deepEqual(allergenList(null), [])
+})
+
+test('search: either language, no accents, each dish once', () => {
+ const en = menuFor(data, 'en')
+ assert.deepEqual(search(en, 'σουβλακι').map(p => p.id), ['5'])
+ assert.deepEqual(search(en, 'pork').map(p => p.id), ['5'])
+ assert.deepEqual(search(en, 'pitta').map(p => p.id), ['5'])
+ assert.deepEqual(search(en, ''), [])
+ assert.equal(fold('Σουβλάκι'), 'σουβλακι')
+})
+
+test('the cart, its total and the order the cloud takes', () => {
+ const en = menuFor(data, 'en')
+ let cart = setQty({}, '5', 2)
+ cart = setQty(cart, '6', 1) // sold out: left out
+ cart = setQty(cart, '99', 1) // not on the menu any more
+ const lines = cartLines(cart, en)
+ assert.deepEqual(lines.map(l => [l.product.id, l.qty, l.total]), [['5', 2, 7]])
+ assert.equal(cartTotal(lines), 7)
+ assert.equal(cartCount(lines), 2)
+ assert.deepEqual(setQty({ 5: 1 }, '5', 0), {})
+ assert.deepEqual(orderBody(lines, { tableToken: 'tok', name: ' ', tableLabel: '5', tableWord: 'Table' }), {
+ order_type: 'dine_in', table_token: 'tok', customer_name: 'Table 5', items: [{ product_id: 5, quantity: 2, unit_price: 3.5 }], total: 7,
+ })
+ assert.equal(refusalKey('order.price_changed'), 'refused.changed')
+ assert.equal(refusalKey('order.table_invalid'), 'tableInvalid')
+ assert.equal(refusalKey('nope'), 'refused.failed')
+})
diff --git a/connect_frontend/order-app/src/i18n.js b/connect_frontend/order-app/src/i18n.js
index 76ec7a0..8c2ffe8 100644
--- a/connect_frontend/order-app/src/i18n.js
+++ b/connect_frontend/order-app/src/i18n.js
@@ -16,6 +16,11 @@ export const TEXTS = {
takeaway: 'Takeaway', delivery: 'Delivery', open: 'Open now', closed: 'Closed now',
closedBody: 'You can still order for a later time.', noOrdering: 'Online ordering is not available right now.',
loading: 'Loading the menu…', notFound: 'This venue was not found.', loadFailed: 'The menu could not be loaded. Check your connection and try again.',
+ contains: 'Contains', mayContain: 'May contain',
+ allergen: {
+ gluten: 'Gluten', crustaceans: 'Crustaceans', eggs: 'Eggs', fish: 'Fish', peanuts: 'Peanuts', soybeans: 'Soya', milk: 'Milk',
+ nuts: 'Nuts', celery: 'Celery', mustard: 'Mustard', sesame: 'Sesame', sulphites: 'Sulphites', lupin: 'Lupin', molluscs: 'Molluscs',
+ },
retry: 'Try again', add: 'Add', soldOut: 'Sold out', options: 'Extras', addToOrder: 'Add to order', cancel: 'Cancel',
viewOrder: 'View order', items_one: '{{count}} item', items_other: '{{count}} items',
yourOrder: 'Your order', empty: 'Your order is empty.', products: 'Products', fee: 'Delivery fee', total: 'Total',
@@ -65,6 +70,11 @@ export const TEXTS = {
takeaway: 'Παραλαβή', delivery: 'Διανομή', open: 'Ανοιχτά τώρα', closed: 'Κλειστά τώρα',
closedBody: 'Μπορείτε να παραγγείλετε για αργότερα.', noOrdering: 'Οι online παραγγελίες δεν είναι διαθέσιμες αυτή τη στιγμή.',
loading: 'Φόρτωση μενού…', notFound: 'Το κατάστημα δεν βρέθηκε.', loadFailed: 'Το μενού δεν φόρτωσε. Ελέγξτε τη σύνδεση και δοκιμάστε ξανά.',
+ contains: 'Περιέχει', mayContain: 'Μπορεί να περιέχει',
+ allergen: {
+ gluten: 'Γλουτένη', crustaceans: 'Καρκινοειδή', eggs: 'Αυγά', fish: 'Ψάρια', peanuts: 'Αράπικα φιστίκια', soybeans: 'Σόγια', milk: 'Γάλα',
+ nuts: 'Ξηροί καρποί', celery: 'Σέλινο', mustard: 'Μουστάρδα', sesame: 'Σουσάμι', sulphites: 'Θειώδη', lupin: 'Λούπινο', molluscs: 'Μαλάκια',
+ },
retry: 'Δοκιμάστε ξανά', add: 'Προσθήκη', soldOut: 'Εξαντλήθηκε', options: 'Έξτρα', addToOrder: 'Στην παραγγελία', cancel: 'Ακύρωση',
viewOrder: 'Η παραγγελία', items_one: '{{count}} τεμάχιο', items_other: '{{count}} τεμάχια',
yourOrder: 'Η παραγγελία σας', empty: 'Η παραγγελία σας είναι άδεια.', products: 'Προϊόντα', fee: 'Χρέωση διανομής', total: 'Σύνολο',
diff --git a/connect_frontend/order-app/src/logic.js b/connect_frontend/order-app/src/logic.js
index 8b9f165..34b3b73 100644
--- a/connect_frontend/order-app/src/logic.js
+++ b/connect_frontend/order-app/src/logic.js
@@ -31,6 +31,15 @@ export function menuFor(categories, service) {
export const productName = p => p.digital_name || p.name
+/** The 14 EU allergens (plan step 6.3), in the venue's order. */
+export const ALLERGENS = ['gluten', 'crustaceans', 'eggs', 'fish', 'peanuts', 'soybeans', 'milk', 'nuts', 'celery', 'mustard', 'sesame', 'sulphites', 'lupin', 'molluscs']
+
+/** A product's allergens by level: {contains: [keys], may_contain: [keys]}. */
+export function allergensOf(p) {
+ const m = p?.allergens && typeof p.allergens === 'object' && !Array.isArray(p.allergens) ? p.allergens : {}
+ return { contains: ALLERGENS.filter(k => m[k] === 'contains'), may_contain: ALLERGENS.filter(k => m[k] === 'may_contain') }
+}
+
/**
* The menu in the guest's language (plan step 6.4): the venue sends each product's, quick option's
* and category's `names` (and `descriptions`) per menu language, already falling back to the text
diff --git a/connect_frontend/order-app/src/pages/OrderPage.jsx b/connect_frontend/order-app/src/pages/OrderPage.jsx
index c735ec4..8b4257a 100644
--- a/connect_frontend/order-app/src/pages/OrderPage.jsx
+++ b/connect_frontend/order-app/src/pages/OrderPage.jsx
@@ -9,7 +9,7 @@ import { useNavigate, useParams } from 'react-router-dom'
import { Bike, CalendarDays, Clock, Minus, Plus, ShoppingBag, Store, X } from 'lucide-react'
import { fetchMenu, imageUrl } from '../api'
import { useT } from '../i18n'
-import { addToCart, cartCount, cartLines, localizeMenu, menuFor, productName, productText, SERVICES } from '../logic'
+import { addToCart, allergensOf, cartCount, cartLines, localizeMenu, menuFor, productName, productText, SERVICES } from '../logic'
import BookingPicker from './BookingPicker'
import Checkout from './Checkout'
@@ -201,6 +201,7 @@ function ProductCard({ product, qty, onAdd, onRemove }) {
{productName(product)}
{text &&
{text}
}
+
{money(product.price)}
{!product.available ? (
@@ -221,6 +222,20 @@ function ProductCard({ product, qty, onAdd, onRemove }) {
)
}
+/** What a dish contains and may contain (plan steps 6.3, 6.5). */
+function AllergenLine({ product }) {
+ const { t } = useT()
+ const a = allergensOf(product)
+ if (!a.contains.length && !a.may_contain.length) return null
+ return (
+
+ {a.contains.length > 0 && {t('contains')}: {a.contains.map(k => t(`allergen.${k}`)).join(', ')}}
+ {a.contains.length > 0 && a.may_contain.length > 0 && ' · '}
+ {a.may_contain.length > 0 && {t('mayContain')}: {a.may_contain.map(k => t(`allergen.${k}`)).join(', ')}}
+
+ )
+}
+
function ExtrasSheet({ product, onClose, onAdd }) {
const { t, money } = useT()
const [chosen, setChosen] = useState([])
diff --git a/connect_frontend/order-app/tests/logic.test.mjs b/connect_frontend/order-app/tests/logic.test.mjs
index ef56f75..802c2f5 100644
--- a/connect_frontend/order-app/tests/logic.test.mjs
+++ b/connect_frontend/order-app/tests/logic.test.mjs
@@ -2,7 +2,7 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import {
- localizeMenu, productName,
+ allergensOf, localizeMenu, productName,
addToCart, cartCount, cartLines, checkoutProblems, menuFor, orderBody, priceFor, refusal, setQty, slotDays, trackSteps,
} from '../src/logic.js'
@@ -96,3 +96,8 @@ test('the menu in the guest’s language (6.4): names, descriptions, extras; old
assert.equal(productName(en[0].products[1]), 'Old one')
assert.equal(productName(localizeMenu(cats, 'el')[0].products[0]), 'Σουβλάκι χοιρινό')
})
+
+test('a dish\'s allergens by level (6.3)', () => {
+ assert.deepEqual(allergensOf({ allergens: { sesame: 'may_contain', milk: 'contains', gluten: 'contains' } }), { contains: ['gluten', 'milk'], may_contain: ['sesame'] })
+ assert.deepEqual(allergensOf({ allergens: ['gluten'] }), { contains: [], may_contain: [] })
+})