Plan phase 3S, step S.7.
- services/qr.py: the snapshot's `qr` {ordering, tables: [{id, label, token_hash}]} (sha256
of each table's token; the cloud never holds the tokens). A table order (dine_in) needs
the venue's ordering on, the site's menu_mode "order" and a valid table token: otherwise
order.service_unavailable / 403 order.table_invalid (a forged, old or typed-in table is
refused). The order keeps the table's id and label (online_orders.table_id, migration 0006).
- Public menu: ?t=<token> → `table` {id, label} or `table_invalid`; `table_ordering`; `qr`
never leaves the cloud.
- Heartbeat returns `apps_url` (new setting PUBLIC_APPS_URL: where /menu/ and /order/ are
served) so sites can print table QR codes that open the right address.
- Menu app: the table from its QR code (kept for the visit), a "Table 5" banner, ordering
only at a real table (otherwise read-only, with a notice for an invalid code); checkout
without a typed table number; prices are the QR menu's (sales point qr_table — it showed
in-store prices since S.1 removed digital_price) and only products sold there; the
confirmation page for table orders (in the kitchen); the delivery/takeaway leftovers
removed (they have their own app since S.4); test ids for e2e.
- Tests: tests/test_qr.py (3); test_checkout's typed-table case moved there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
8.0 KiB
React
208 lines
8.0 KiB
React
import {
|
||
Leaf, Sprout, Wheat, Flame, Star, ChefHat,
|
||
Minus, Plus,
|
||
} from 'lucide-react'
|
||
|
||
// ── Money helpers ────────────────────────────────────────────────────────────
|
||
export function eur(n) {
|
||
return '€' + Number(n).toFixed(2)
|
||
}
|
||
|
||
// The price is the QR menu's (sales point qr_table, set in normaliseProduct): since phase 3S
|
||
// discounts are price rules already in it, so there is no separate discount to show.
|
||
export function discountedPrice(product) {
|
||
return product.price ?? 0
|
||
}
|
||
|
||
export function basePrice(product) {
|
||
return product.price ?? 0
|
||
}
|
||
|
||
export function hasDiscount() {
|
||
return false
|
||
}
|
||
|
||
export function discountPct() {
|
||
return 0
|
||
}
|
||
|
||
// ── Placeholder gradient art ─────────────────────────────────────────────────
|
||
export function DishArt({ product, category, size = 'card' }) {
|
||
const hue = category?.hue ?? 40
|
||
const GlyphIcon = category?.GlyphIcon ?? null
|
||
const id = product?.id ?? 'x'
|
||
let seed = 0
|
||
for (let i = 0; i < id.length; i++) seed += id.charCodeAt(i)
|
||
const lift = (seed % 5) - 2
|
||
const c1 = `hsl(${hue} 34% ${90 + lift}%)`
|
||
const c2 = `hsl(${hue} 30% ${80 + lift}%)`
|
||
const glyphColor = `hsl(${hue} 32% 42%)`
|
||
const firstName = product?.digital_name || product?.name || '?'
|
||
const letter = typeof firstName === 'object' ? (firstName.en?.[0] ?? '?') : (firstName[0] ?? '?')
|
||
|
||
const sizeClass =
|
||
size === 'hero'
|
||
? 'self-stretch min-h-[100px] w-[100px]'
|
||
: size === 'sm'
|
||
? 'h-16 w-16'
|
||
: 'h-[92px] w-[92px]'
|
||
const iconClass = size === 'sm' ? 'h-7 w-7' : 'h-9 w-9'
|
||
|
||
return (
|
||
<div
|
||
className={`relative flex ${sizeClass} shrink-0 items-center justify-center overflow-hidden rounded-[13px]`}
|
||
style={{ background: `linear-gradient(135deg, ${c1}, ${c2})` }}
|
||
>
|
||
<span
|
||
className="absolute -right-2 -top-3 font-display text-[56px] leading-none opacity-[0.14] select-none"
|
||
style={{ color: glyphColor }}
|
||
>
|
||
{letter}
|
||
</span>
|
||
{GlyphIcon && (
|
||
<GlyphIcon
|
||
className={iconClass}
|
||
style={{ color: glyphColor, opacity: 0.62 }}
|
||
strokeWidth={1.4}
|
||
/>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── Badge (Popular / Chef's pick) ────────────────────────────────────────────
|
||
export function Badge({ kind, t }) {
|
||
if (kind === 'popular') {
|
||
return (
|
||
<span className="inline-flex items-center gap-1 rounded-full bg-[#f4ecd8] px-2 py-[3px] text-[10px] font-semibold uppercase tracking-[0.08em] text-[#a9842f] ring-1 ring-inset ring-[#e4d4a8]">
|
||
<Flame className="h-3 w-3" strokeWidth={2.2} />
|
||
{t?.popular ?? 'Popular'}
|
||
</span>
|
||
)
|
||
}
|
||
if (kind === 'chefs') {
|
||
return (
|
||
<span className="inline-flex items-center gap-1 rounded-full bg-[#2d3b2d] px-2 py-[3px] text-[10px] font-semibold uppercase tracking-[0.08em] text-[#f0e9d6]">
|
||
<ChefHat className="h-3 w-3" strokeWidth={2} />
|
||
{t?.chefs ?? "Chef's pick"}
|
||
</span>
|
||
)
|
||
}
|
||
return null
|
||
}
|
||
|
||
// ── Dietary chips (with text labels) ────────────────────────────────────────
|
||
const DIET_STYLE = {
|
||
vegan: { Icon: Leaf, fg: '#3f7d4e', bg: '#e7f1e7', ring: '#c9e2cb' },
|
||
vegetarian: { Icon: Sprout, fg: '#5d7a37', bg: '#eef2e0', ring: '#d8e2bd' },
|
||
'gluten-free': { Icon: Wheat, fg: '#a9842f', bg: '#f5edd8', ring: '#e6d6a6' },
|
||
spicy: { Icon: Flame, fg: '#c2602f', bg: '#f7e6dc', ring: '#eccab3' },
|
||
}
|
||
|
||
export function DietChip({ tag, t }) {
|
||
const s = DIET_STYLE[tag]
|
||
if (!s) return null
|
||
const { Icon } = s
|
||
const label = t?.dietary?.[tag] ?? tag
|
||
return (
|
||
<span
|
||
className="inline-flex items-center gap-1 rounded-full px-[7px] py-[2px] text-[10px] font-medium ring-1 ring-inset"
|
||
style={{ color: s.fg, background: s.bg, borderColor: s.ring }}
|
||
>
|
||
<Icon className="h-[11px] w-[11px]" strokeWidth={2} />
|
||
{label}
|
||
</span>
|
||
)
|
||
}
|
||
|
||
// ── Compact tag icon badges (card title row) ─────────────────────────────────
|
||
const TAG_BADGE = {
|
||
vegan: { Icon: Leaf, fg: '#3f7d4e', bg: '#e7f1e7', ring: '#bcdcc0' },
|
||
vegetarian: { Icon: Sprout, fg: '#5d7a37', bg: '#eef2e0', ring: '#cfe0b0' },
|
||
'gluten-free': { Icon: Wheat, fg: '#9a7726', bg: '#f6edd6', ring: '#e6d49e' },
|
||
spicy: { Icon: Flame, fg: '#c2602f', bg: '#f8e6da', ring: '#eec4ac' },
|
||
}
|
||
const PRIORITY_BADGE = {
|
||
popular: { Icon: Star, fg: '#a9842f', bg: '#f6edd6', ring: '#e6d49e' },
|
||
chefs: { Icon: ChefHat, fg: '#f0e9d6', bg: '#2d3b2d', ring: '#2d3b2d' },
|
||
}
|
||
|
||
export function TagIcons({ product }) {
|
||
const items = []
|
||
const badge = product.badge ?? product.digital_badge
|
||
if (badge && PRIORITY_BADGE[badge]) items.push(PRIORITY_BADGE[badge])
|
||
const tags = product.tags ?? product.digital_tags ?? []
|
||
tags.forEach(tag => { if (TAG_BADGE[tag]) items.push(TAG_BADGE[tag]) })
|
||
const shown = items.slice(0, 3)
|
||
if (!shown.length) return null
|
||
return (
|
||
<div className="flex shrink-0 items-center gap-1 pt-[3px]">
|
||
{shown.map((s, i) => {
|
||
const { Icon } = s
|
||
return (
|
||
<span
|
||
key={i}
|
||
className="flex h-[19px] w-[19px] items-center justify-center rounded-full ring-1 ring-inset"
|
||
style={{ color: s.fg, background: s.bg, borderColor: s.ring }}
|
||
>
|
||
<Icon className="h-[11px] w-[11px]" strokeWidth={2.2} />
|
||
</span>
|
||
)
|
||
})}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── Price display ─────────────────────────────────────────────────────────────
|
||
export function Price({ product, large }) {
|
||
const base = basePrice(product)
|
||
const now = discountedPrice(product)
|
||
const discounted = hasDiscount(product)
|
||
return (
|
||
<div className="flex items-baseline gap-1.5">
|
||
{discounted && (
|
||
<span className="font-display text-[13px] text-[#b3aa97] line-through">{eur(base)}</span>
|
||
)}
|
||
<span
|
||
className={`font-display ${large ? 'text-[18px]' : 'text-[16px]'} font-semibold ${discounted ? 'text-[#c2602f]' : 'text-[#2d3b2d]'}`}
|
||
>
|
||
{eur(now)}
|
||
</span>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── Discount flag ─────────────────────────────────────────────────────────────
|
||
export function DiscountFlag({ product, t }) {
|
||
const pct = discountPct(product)
|
||
if (!pct) return null
|
||
return (
|
||
<span className="inline-flex items-center rounded-md bg-[#c2602f] px-1.5 py-[2px] font-sans text-[10px] font-bold tracking-[0.05em] text-white">
|
||
−{pct}% {t?.off ?? 'OFF'}
|
||
</span>
|
||
)
|
||
}
|
||
|
||
// ── Quantity stepper ─────────────────────────────────────────────────────────
|
||
export function Stepper({ qty, onInc, onDec }) {
|
||
return (
|
||
<div className="flex items-center gap-3 rounded-full bg-[#f3efe5] p-1 ring-1 ring-inset ring-[#e8e1d1]">
|
||
<button
|
||
onClick={onDec}
|
||
className="flex h-7 w-7 items-center justify-center rounded-full bg-white text-[#2d3b2d] shadow-sm ring-1 ring-[#e8e1d1] transition active:scale-90"
|
||
>
|
||
<Minus className="h-3.5 w-3.5" strokeWidth={2.5} />
|
||
</button>
|
||
<span className="min-w-[16px] text-center font-display text-[16px] font-semibold tabular-nums text-[#2d3b2d]">
|
||
{qty}
|
||
</span>
|
||
<button
|
||
onClick={onInc}
|
||
className="flex h-7 w-7 items-center justify-center rounded-full bg-[#2d3b2d] text-white shadow-sm transition active:scale-90"
|
||
>
|
||
<Plus className="h-3.5 w-3.5" strokeWidth={2.5} />
|
||
</button>
|
||
</div>
|
||
)
|
||
}
|