feat(cloud): the online ordering app (takeaway, delivery) with hours, time slots and rate limits (platform-v2 3S, S.4)

- connect_frontend/order-app at /order/{site}: menu per service at that service's prices,
  extras, basket (kept per tab), checkout priced by the cloud (fee, area by list or
  postcode, minimum), name/phone/address/notes (remembered), as soon as possible or a time
  slot, tracking page with steps, lines and totals; en/el; tokens in index.css. Logic in
  src/logic.js, unit-tested; built and served by the connect image (npm test in the build).
- services/ordering.py: the venue's services, hours (past midnight), preparation, slot grid,
  days ahead, ASAP; takeaway/delivery orders checked (order.service_unavailable,
  order.closed, order.time_invalid) and need a phone; GET /api/orders/{site}/slots; the
  public menu carries the ordering summary.
- services/ratelimit.py: per-caller limits on quote, order and track (429 rate.limited).
- online_orders.requested_for (0003, unreleased) stored as UTC; every datetime sent with its
  offset (the database keeps no zone: a 12:00 Athens slot came back as 12:00 unzoned).
- Tracking returns what was ordered, the totals, the type and the time.
- Tests: test_ordering.py (5), checkout/fees updated; order-app unit (4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 13:39:00 +02:00
co-authored by Claude Opus 5.5
parent 9e8ec4c4e6
commit b25bfcda3e
30 changed files with 4424 additions and 15 deletions
@@ -0,0 +1,99 @@
// The customer's order tracking (plan phase 3S, step S.4): /order/{site}/track/{token}. The
// token is the order's private code (the address is the customer's to keep). Polls the cloud
// until the order is done or not accepted; shows the steps, what was ordered and for when.
import { useEffect, useState } from 'react'
import { Link, useLocation, useParams } from 'react-router-dom'
import { Check, X } from 'lucide-react'
import { track } from '../api'
import { useT } from '../i18n'
import { trackSteps } from '../logic'
const POLL_MS = 8000
export default function TrackPage() {
const { site, token } = useParams()
const { t, money, lang } = useT()
const placed = useLocation().state?.placed
const [order, setOrder] = useState(null)
const [missing, setMissing] = useState(false)
useEffect(() => {
let timer
let alive = true
const poll = async () => {
try {
const o = await track(token)
if (!alive) return
setOrder(o)
if (!trackSteps(o.order_type, o.status).done) timer = setTimeout(poll, POLL_MS)
} catch (err) {
if (!alive) return
if (err?.response?.status === 404) setMissing(true)
else timer = setTimeout(poll, POLL_MS) // offline for a moment: try again
}
}
poll()
return () => { alive = false; clearTimeout(timer) }
}, [token])
if (missing) return <Page><p className="p-6 text-center text-ink-2">{t('track.notFound')}</p></Page>
if (!order) return <Page><p className="p-6 text-center text-ink-2" role="status">{t('loading')}</p></Page>
const { steps, at } = trackSteps(order.order_type, order.status)
const rejected = order.status === 'rejected'
const when = order.requested_for
? new Intl.DateTimeFormat(lang === 'el' ? 'el-GR' : 'en-GB', { weekday: 'long', hour: '2-digit', minute: '2-digit' }).format(new Date(order.requested_for))
: null
return (
<Page>
<div className="p-4 grid gap-4" data-testid="track" data-status={order.status}>
{placed && <p className="p-3 rounded-control bg-success-soft text-success-ink font-medium">{t('track.placed')}</p>}
<header className="grid gap-1">
<h1 className="font-display text-2xl font-semibold" data-testid="track-ref">{t('track.title', { ref: order.public_ref })}</h1>
<p className="text-ink-2">{t(order.order_type === 'delivery' ? 'delivery' : 'takeaway')} · {order.requested_for ? t('track.for', { when }) : t('track.asap')}</p>
</header>
{rejected ? (
<div className="p-4 rounded-card bg-danger-soft text-danger-ink grid gap-1" role="status">
<p className="font-semibold flex items-center gap-2"><X size={18} aria-hidden="true" />{t('track.rejected')}</p>
{order.rejection_reason && <p>{t('track.reason', { reason: order.rejection_reason })}</p>}
</div>
) : (
<ol className="grid gap-0" aria-label={t('track.status.' + order.status)}>
{steps.map((s, i) => {
const done = i < at || order.status === 'delivered'
const now = i === at && order.status !== 'delivered'
return (
<li key={s} className="flex items-center gap-3 py-2" aria-current={now ? 'step' : undefined}>
<span className={`w-7 h-7 rounded-full flex items-center justify-center shrink-0 text-sm font-semibold
${done ? 'bg-accent text-accent-fg' : now ? 'bg-accent-soft text-accent-ink ring-2 ring-accent' : 'bg-surface-2 text-ink-3'}`}>
{done ? <Check size={15} aria-hidden="true" /> : i + 1}
</span>
<span className={done || now ? 'text-ink font-medium' : 'text-ink-3'}>{t(`track.status.${s}`)}</span>
</li>
)
})}
</ol>
)}
<section className="p-4 rounded-card bg-surface border border-line grid gap-1.5">
{(order.lines ?? []).map((l, i) => (
<div key={i} className="flex justify-between gap-3 text-ink-2">
<span>{l.quantity}× {l.name}{l.options?.length ? ` (${l.options.join(', ')})` : ''}</span>
<span>{money(l.unit_price * l.quantity)}</span>
</div>
))}
{order.delivery_fee > 0 && <div className="flex justify-between text-ink-2"><span>{t('fee')}</span><span>{money(order.delivery_fee)}</span></div>}
<div className="flex justify-between text-lg font-semibold pt-1 border-t border-line"><span>{t('total')}</span><span data-testid="track-total">{money(order.total)}</span></div>
</section>
{!trackSteps(order.order_type, order.status).done && <p className="text-sm text-ink-2">{t('track.keep')}</p>}
<Link to={`/${site}`} className="text-center text-accent-ink font-semibold">{t('track.newOrder')}</Link>
</div>
</Page>
)
}
function Page({ children }) {
return <div className="mx-auto max-w-lg min-h-dvh bg-canvas">{children}</div>
}