feat(cloud): table bookings online, with food ordered ahead
Plan phase 3S, step S.6.
- New order types "reservation" (a table only, no items) and "preorder" (a table with food,
priced at the online_preorder sales point); online_orders.party_size (migration 0005).
- services/ordering.py: the venue's booking settings (ordering.reservations in the snapshot):
hours (none = any time), time grid, notice, days ahead (≤ 90), party size; res_slots per
venue day, res_days, res_check (order.service_unavailable, order.party_invalid,
order.time_invalid). The public menu's ordering summary gains `reservations`
{enabled, with_food, party_max, days}; GET /api/orders/{site}/reservation-slots?day=.
- Bookings need a phone; a plain booking refuses items (order.items_not_allowed).
- Status steps for bookings: pending_acceptance → accepted | rejected; accepted → delivered
(arrived) | cancelled (by the venue); ordinary orders unchanged.
- Order app: "Book a table" (people, day, time, optional food at the pre-order prices),
booking summary at checkout, a booking tracking page (waiting, confirmed, welcome;
declined / cancelled with the reason). en/el.
- Tests: tests/test_reservations.py (3), order-app logic test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ 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'
|
||||
import { BOOKING_TYPES, trackSteps } from '../logic'
|
||||
|
||||
const POLL_MS = 8000
|
||||
|
||||
@@ -40,27 +40,34 @@ export default function TrackPage() {
|
||||
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 rejected = order.status === 'rejected' || order.status === 'cancelled'
|
||||
const booked = BOOKING_TYPES.includes(order.order_type) // a table booking (S.6)
|
||||
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))
|
||||
? new Intl.DateTimeFormat(lang === 'el' ? 'el-GR' : 'en-GB', booked
|
||||
? { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit', hour12: false }
|
||||
: { weekday: 'long', hour: '2-digit', minute: '2-digit' }).format(new Date(order.requested_for))
|
||||
: null
|
||||
const st = s => t(booked ? `track.booking.${s}` : `track.status.${s}`)
|
||||
|
||||
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>}
|
||||
{placed && <p className="p-3 rounded-control bg-success-soft text-success-ink font-medium">{t(booked ? 'track.booking.placed' : '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>
|
||||
<h1 className="font-display text-2xl font-semibold" data-testid="track-ref">{t(booked ? 'track.booking.title' : 'track.title', { ref: order.public_ref })}</h1>
|
||||
<p className="text-ink-2">
|
||||
{booked ? `${t('book.tableFor', { count: order.party_size ?? 1 })} · ${when}`
|
||||
: `${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>
|
||||
<p className="font-semibold flex items-center gap-2"><X size={18} aria-hidden="true" />{booked ? st(order.status) : 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)}>
|
||||
<ol className="grid gap-0" aria-label={st(order.status)}>
|
||||
{steps.map((s, i) => {
|
||||
const done = i < at || order.status === 'delivered'
|
||||
const now = i === at && order.status !== 'delivered'
|
||||
@@ -70,14 +77,14 @@ export default function TrackPage() {
|
||||
${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>
|
||||
<span className={done || now ? 'text-ink font-medium' : 'text-ink-3'}>{st(s)}</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ol>
|
||||
)}
|
||||
|
||||
<section className="p-4 rounded-card bg-surface border border-line grid gap-1.5">
|
||||
{(!booked || (order.lines ?? []).length > 0) && <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>
|
||||
@@ -86,7 +93,8 @@ export default function TrackPage() {
|
||||
))}
|
||||
{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>
|
||||
{booked && <p className="text-sm text-ink-2">{t('book.foodReady')}</p>}
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user