|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
import { useState, useEffect, useRef, useMemo } from 'react'
|
|
|
|
|
import { useParams, useNavigate } from 'react-router-dom'
|
|
|
|
|
import { useParams, useNavigate, useSearchParams } from 'react-router-dom'
|
|
|
|
|
import {
|
|
|
|
|
Search, Leaf, X, Plus, ShoppingBag,
|
|
|
|
|
ChevronLeft, ArrowRight, Send, Loader2, Info,
|
|
|
|
@@ -33,8 +33,10 @@ const I18N = {
|
|
|
|
|
orderChanged: 'Something on the menu changed since you opened it. Please reload the page and check your order.',
|
|
|
|
|
orderFailed: 'The order could not be sent. Please try again.',
|
|
|
|
|
orderPlaced: 'Order placed!', orderPlacedSub: 'Your order has been sent to the kitchen.',
|
|
|
|
|
newOrder: 'Back to menu', table: 'Table no.', name: 'Your name',
|
|
|
|
|
namePh: 'e.g. Alex', tablePh: 'e.g. 12', orderSummary: 'Order summary',
|
|
|
|
|
newOrder: 'Back to menu', table: 'Table', name: 'Your name (optional)',
|
|
|
|
|
namePh: 'e.g. Alex', orderSummary: 'Order summary',
|
|
|
|
|
atTable: 'Table {table}: order from your phone', tableInvalid: 'This QR code is no longer valid. Please ask the staff.',
|
|
|
|
|
orderingOff: 'Ordering from the table is not available right now. Please ask the staff.',
|
|
|
|
|
contains: 'Contains', ingredients: 'Ingredients', noResults: 'No dishes found',
|
|
|
|
|
noResultsSub: 'Try a different search.',
|
|
|
|
|
popular: 'Popular', chefs: "Chef's pick", off: 'OFF',
|
|
|
|
@@ -49,8 +51,10 @@ const I18N = {
|
|
|
|
|
orderChanged: 'Κάτι άλλαξε στο μενού από τότε που το άνοιξες. Ανανέωσε τη σελίδα και έλεγξε την παραγγελία σου.',
|
|
|
|
|
orderFailed: 'Η παραγγελία δεν στάλθηκε. Δοκίμασε ξανά.',
|
|
|
|
|
orderPlaced: 'Η παραγγελία στάλθηκε!', orderPlacedSub: 'Η παραγγελία σου εστάλη στην κουζίνα.',
|
|
|
|
|
newOrder: 'Πίσω στο μενού', table: 'Τραπέζι', name: 'Το όνομά σου',
|
|
|
|
|
namePh: 'π.χ. Αλέξης', tablePh: 'π.χ. 12', orderSummary: 'Σύνοψη παραγγελίας',
|
|
|
|
|
newOrder: 'Πίσω στο μενού', table: 'Τραπέζι', name: 'Το όνομά σου (προαιρετικά)',
|
|
|
|
|
namePh: 'π.χ. Αλέξης', orderSummary: 'Σύνοψη παραγγελίας',
|
|
|
|
|
atTable: 'Τραπέζι {table}: παραγγείλτε από το κινητό σας', tableInvalid: 'Αυτό το QR δεν ισχύει πλέον. Ρωτήστε το προσωπικό.',
|
|
|
|
|
orderingOff: 'Η παραγγελία από το τραπέζι δεν είναι διαθέσιμη τώρα. Ρωτήστε το προσωπικό.',
|
|
|
|
|
contains: 'Περιέχει', ingredients: 'Συστατικά', noResults: 'Δεν βρέθηκαν πιάτα',
|
|
|
|
|
noResultsSub: 'Δοκίμασε διαφορετική αναζήτηση.',
|
|
|
|
|
popular: 'Δημοφιλές', chefs: 'Επιλογή Σεφ', off: 'ΕΚΠΤΩΣΗ',
|
|
|
|
@@ -66,19 +70,24 @@ function resolveImageUrl(url) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Normalise a backend product to the shape the UI expects ──────────────────
|
|
|
|
|
// The QR menu sells at the sales point qr_table (phase 3S): its price from `prices`; menus
|
|
|
|
|
// pushed before S.2 had digital_price.
|
|
|
|
|
const QR_POINT = 'qr_table'
|
|
|
|
|
|
|
|
|
|
function normaliseProduct(p, catId) {
|
|
|
|
|
return {
|
|
|
|
|
...p,
|
|
|
|
|
digital_price: undefined, digital_discount: undefined,
|
|
|
|
|
id: String(p.id),
|
|
|
|
|
cat: catId,
|
|
|
|
|
name: p.digital_name || p.name || '',
|
|
|
|
|
desc: p.digital_description || p.description || '',
|
|
|
|
|
price: p.digital_price ?? p.base_price ?? 0,
|
|
|
|
|
price: p.prices ? (p.prices[QR_POINT] ?? 0) : (p.digital_price ?? p.base_price ?? 0),
|
|
|
|
|
badge: p.digital_badge || p.badge || null,
|
|
|
|
|
tags: p.digital_tags || p.tags || [],
|
|
|
|
|
allergens: p.allergens || [],
|
|
|
|
|
ingredients: p.ingredients || null,
|
|
|
|
|
discountPct: p.digital_discount || p.discountPct || 0,
|
|
|
|
|
discountPct: 0,
|
|
|
|
|
image_url: resolveImageUrl(p.digital_image_url || p.image_url || null),
|
|
|
|
|
digital_available: p.digital_available !== false,
|
|
|
|
|
}
|
|
|
|
@@ -92,9 +101,9 @@ function normaliseCategories(rawCats) {
|
|
|
|
|
id,
|
|
|
|
|
hue: cat.hue ?? CATEGORY_HUES[idx % CATEGORY_HUES.length],
|
|
|
|
|
GlyphIcon: GLYPH_BY_ID[id] ?? GLYPH_FALLBACK[idx % GLYPH_FALLBACK.length],
|
|
|
|
|
products: (cat.products || []).map(p => normaliseProduct(p, id)),
|
|
|
|
|
products: (cat.products || []).filter(p => !p.sold_at || p.sold_at.includes(QR_POINT)).map(p => normaliseProduct(p, id)),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).filter(c => c.products.length > 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Bottom Sheet shell ────────────────────────────────────────────────────────
|
|
|
|
@@ -291,6 +300,7 @@ function ProductCard({ product, category, lang, t, onOpen, onAdd, qty, viewOnly
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
onClick={unavailable ? undefined : () => onOpen(product)}
|
|
|
|
|
data-testid="menu-product" data-product={product.id}
|
|
|
|
|
className={`group overflow-hidden rounded-[20px] bg-[#fcfbf7] ring-1 ring-[#e7e1d1] shadow-card transition hover:shadow-card-hover active:scale-[0.992] ${unavailable ? 'opacity-50' : 'cursor-pointer'}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-stretch gap-3.5 p-3.5">
|
|
|
|
@@ -327,6 +337,7 @@ function ProductCard({ product, category, lang, t, onOpen, onAdd, qty, viewOnly
|
|
|
|
|
<button
|
|
|
|
|
onClick={e => { e.stopPropagation(); if (!unavailable) onAdd(product) }}
|
|
|
|
|
aria-label={t.add}
|
|
|
|
|
data-testid="menu-add"
|
|
|
|
|
className="flex h-8 items-center gap-1 rounded-full bg-[#2d3b2d] pl-2.5 pr-3 text-[12px] font-semibold text-[#f0e9d6] shadow-sm transition active:scale-95 hover:bg-[#26331f]"
|
|
|
|
|
>
|
|
|
|
|
<Plus className="h-4 w-4" strokeWidth={2.4} />
|
|
|
|
@@ -573,8 +584,8 @@ function SearchOverlay({ open, onClose, categories, lang, t, onOpen, onAdd, cart
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Cart Flow (bottom sheet) ──────────────────────────────────────────────────
|
|
|
|
|
function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenProduct, siteSlug, navigate }) {
|
|
|
|
|
const [form, setForm] = useState({ name: '', table: '' })
|
|
|
|
|
function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenProduct, siteSlug, navigate, table, tableToken }) {
|
|
|
|
|
const [form, setForm] = useState({ name: '' })
|
|
|
|
|
const [sending, setSending] = useState(false)
|
|
|
|
|
const [sendError, setSendError] = useState('')
|
|
|
|
|
|
|
|
|
@@ -601,29 +612,26 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
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',
|
|
|
|
|
customer_name: form.name.trim(),
|
|
|
|
|
customer_table: form.table.trim(),
|
|
|
|
|
table_token: tableToken,
|
|
|
|
|
customer_name: form.name.trim() || `${t.table} ${table?.label ?? ''}`.trim(),
|
|
|
|
|
items: lines.map(l => ({
|
|
|
|
|
product_id: l.product.id,
|
|
|
|
|
name: typeof l.product.name === 'object' ? l.product.name.en : l.product.name,
|
|
|
|
|
product_id: Number(l.product.id),
|
|
|
|
|
quantity: l.qty,
|
|
|
|
|
unit_price: discountedPrice(l.product),
|
|
|
|
|
})),
|
|
|
|
|
subtotal: Math.round(total * 100) / 100,
|
|
|
|
|
total: Math.round(total * 100) / 100,
|
|
|
|
|
lang,
|
|
|
|
|
placed_at: new Date().toISOString(),
|
|
|
|
|
})
|
|
|
|
|
setCart({})
|
|
|
|
|
setForm({ name: '', table: '' })
|
|
|
|
|
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 : t.orderFailed)
|
|
|
|
|
? t.orderChanged : code === 'order.table_invalid' ? t.tableInvalid : code === 'order.service_unavailable' ? t.orderingOff : t.orderFailed)
|
|
|
|
|
setSending(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -679,6 +687,7 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setStage('checkout')}
|
|
|
|
|
data-testid="cart-continue"
|
|
|
|
|
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-[#2d3b2d] text-[15px] font-semibold text-[#f0e9d6] transition active:scale-[0.98]"
|
|
|
|
|
>
|
|
|
|
|
{t.continue}<ArrowRight className="h-4 w-4" strokeWidth={2.2} />
|
|
|
|
@@ -692,7 +701,7 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
|
|
|
|
|
// Checkout view
|
|
|
|
|
if (stage === 'checkout') {
|
|
|
|
|
const valid = form.name.trim() && form.table.trim()
|
|
|
|
|
const valid = lines.length > 0
|
|
|
|
|
return (
|
|
|
|
|
<Sheet open onClose={close}>
|
|
|
|
|
<SheetHandle />
|
|
|
|
@@ -706,7 +715,8 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
<h2 className="font-display text-[22px] font-semibold text-[#2d3b2d]">{t.placeOrder}</h2>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="max-h-[62vh] overflow-y-auto px-5 pb-2 pt-3">
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
|
|
|
<div className="grid gap-3">
|
|
|
|
|
<p className="text-[14px] font-semibold text-[#2d3b2d]" data-testid="checkout-table">{t.table} {table?.label}</p>
|
|
|
|
|
<label className="block">
|
|
|
|
|
<span className="text-[11px] font-semibold uppercase tracking-[0.12em] text-[#9a917a]">{t.name}</span>
|
|
|
|
|
<input
|
|
|
|
@@ -716,16 +726,6 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
className="mt-1.5 w-full rounded-xl bg-white px-3.5 py-3 text-[15px] text-[#2d3b2d] outline-none ring-1 ring-[#e8e1d1] focus:ring-2 focus:ring-[#9caf88]"
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
<label className="block">
|
|
|
|
|
<span className="text-[11px] font-semibold uppercase tracking-[0.12em] text-[#9a917a]">{t.table}</span>
|
|
|
|
|
<input
|
|
|
|
|
value={form.table}
|
|
|
|
|
onChange={e => setForm(f => ({ ...f, table: e.target.value }))}
|
|
|
|
|
placeholder={t.tablePh}
|
|
|
|
|
inputMode="numeric"
|
|
|
|
|
className="mt-1.5 w-full rounded-xl bg-white px-3.5 py-3 text-[15px] text-[#2d3b2d] outline-none ring-1 ring-[#e8e1d1] focus:ring-2 focus:ring-[#9caf88]"
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mt-5 text-[11px] font-semibold uppercase tracking-[0.12em] text-[#9a917a]">{t.orderSummary}</div>
|
|
|
|
@@ -754,6 +754,7 @@ function CartFlow({ stage, setStage, cart, setCart, categories, lang, t, onOpenP
|
|
|
|
|
<button
|
|
|
|
|
disabled={!valid || sending}
|
|
|
|
|
onClick={submit}
|
|
|
|
|
data-testid="place-order"
|
|
|
|
|
className={`flex h-12 w-full items-center justify-center gap-2 rounded-full text-[15px] font-semibold transition active:scale-[0.98] ${
|
|
|
|
|
valid && !sending ? 'bg-[#2d3b2d] text-[#f0e9d6]' : 'bg-[#d8d2c1] text-[#a39c87] cursor-not-allowed'
|
|
|
|
|
}`}
|
|
|
|
@@ -790,6 +791,7 @@ function CartButton({ count, total, t, onClick }) {
|
|
|
|
|
<div className="pointer-events-none fixed inset-x-0 bottom-0 z-40 mx-auto w-full sm:max-w-[960px] px-4 pb-4">
|
|
|
|
|
<button
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
data-testid="cart-button"
|
|
|
|
|
className={`pointer-events-auto flex h-14 w-full items-center justify-between rounded-full bg-[#2d3b2d] px-5 text-[#f0e9d6] shadow-cart transition active:scale-[0.98] ${bump ? 'animate-pop' : ''}`}
|
|
|
|
|
>
|
|
|
|
|
<span className="flex items-center gap-2.5">
|
|
|
|
@@ -808,9 +810,22 @@ function CartButton({ count, total, t, onClick }) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── 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)
|
|
|
|
@@ -836,17 +851,20 @@ export default function MenuPage() {
|
|
|
|
|
useEffect(() => { try { localStorage.setItem('ot_cart', JSON.stringify(cart)) } catch {} }, [cart])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchMenu(siteSlug)
|
|
|
|
|
fetchMenu(siteSlug, tableToken)
|
|
|
|
|
.then(data => {
|
|
|
|
|
const cats = normaliseCategories(data.categories || [])
|
|
|
|
|
setCategories(cats)
|
|
|
|
|
setRestaurant(data.restaurant ?? null)
|
|
|
|
|
setViewOnly(data.menu_mode === 'view_only')
|
|
|
|
|
// 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])
|
|
|
|
|
}, [siteSlug, tableToken])
|
|
|
|
|
|
|
|
|
|
const sectionRefs = useRef({})
|
|
|
|
|
const clickLock = useRef(false)
|
|
|
|
@@ -924,6 +942,13 @@ export default function MenuPage() {
|
|
|
|
|
lang={lang}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{(table && !viewOnly) || tableInvalid ? (
|
|
|
|
|
<p data-testid={tableInvalid ? 'table-invalid' : 'table-banner'}
|
|
|
|
|
className={`mx-4 mt-3 rounded-xl px-4 py-2.5 text-[13.5px] font-medium ${tableInvalid ? 'bg-[#f7e6dc] text-[#9b4a22]' : 'bg-[#e7ede7] text-[#2d3b2d]'}`}>
|
|
|
|
|
{tableInvalid ? t.tableInvalid : t.atTable.replace('{table}', table.label)}
|
|
|
|
|
</p>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<main className="pb-32">
|
|
|
|
|
{categories.map(cat => (
|
|
|
|
|
<Section
|
|
|
|
@@ -987,6 +1012,8 @@ export default function MenuPage() {
|
|
|
|
|
onOpenProduct={openProduct}
|
|
|
|
|
siteSlug={siteSlug}
|
|
|
|
|
navigate={navigate}
|
|
|
|
|
table={table}
|
|
|
|
|
tableToken={tableToken}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|