feat(menu-app): the QR menu on the customer apps' look, two languages, allergens (platform-v2 step 6.5)

- connect_frontend/menu-app rebuilt like the order app: the same tokens (index.css,
  tailwind.config.js), texts in i18n.js (en, el; the old 'ot_lang' choice carries over), pure
  logic in src/logic.js with tests (menuFor in the guest's language, QR prices, search in either
  language, cart, order body, refusals). MenuPage (menu, search, dish sheet, cart, checkout at
  the table) and ConfirmPage; App.jsx, components/primitives and OrderConfirm removed;
  react-hot-toast dropped.
- Allergens on every dish (contains on the card; contains / may contain on the dish sheet) and
  in the order app's cards too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 11:27:05 +02:00
co-authored by Claude Opus 5.5
parent 9f9b882806
commit e55157fa86
19 changed files with 746 additions and 1448 deletions
+10
View File
@@ -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: 'Σύνολο',
+9
View File
@@ -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
@@ -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 }) {
<div className="flex-1 min-w-0 grid gap-1 content-start">
<h3 className="font-semibold text-ink leading-snug">{productName(product)}</h3>
{text && <p className="text-sm text-ink-2 line-clamp-2">{text}</p>}
<AllergenLine product={product} />
<div className="flex items-center justify-between gap-2 mt-1">
<span className="font-semibold text-ink" data-testid="price">{money(product.price)}</span>
{!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 (
<p className="text-xs" data-testid="allergens">
{a.contains.length > 0 && <span className="text-warning-ink">{t('contains')}: {a.contains.map(k => t(`allergen.${k}`)).join(', ')}</span>}
{a.contains.length > 0 && a.may_contain.length > 0 && ' · '}
{a.may_contain.length > 0 && <span className="text-ink-3">{t('mayContain')}: {a.may_contain.map(k => t(`allergen.${k}`)).join(', ')}</span>}
</p>
)
}
function ExtrasSheet({ product, onClose, onAdd }) {
const { t, money } = useT()
const [chosen, setChosen] = useState([])
@@ -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: [] })
})