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:
@@ -0,0 +1,74 @@
|
||||
// Booking a table (plan phase 3S, step S.6): how many people, which day, what time, and
|
||||
// (when the venue allows it) food ordered ahead to be ready on arrival. The days come with the
|
||||
// menu (ordering.reservations.days); the times of a day from the cloud, in venue time.
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Minus, Plus, Users } from 'lucide-react'
|
||||
import { fetchBookingSlots } from '../api'
|
||||
import { useT } from '../i18n'
|
||||
import { slotDays } from '../logic'
|
||||
|
||||
export default function BookingPicker({ site, res, timeZone, booking, setBooking }) {
|
||||
const { t, lang } = useT()
|
||||
const [slots, setSlots] = useState(null)
|
||||
const set = patch => setBooking(b => ({ ...b, ...patch }))
|
||||
const day = booking.day ?? res.days[0] ?? null
|
||||
|
||||
useEffect(() => {
|
||||
if (!day) return undefined
|
||||
let alive = true
|
||||
setSlots(null)
|
||||
fetchBookingSlots(site, day).then(d => alive && setSlots(d.slots)).catch(() => alive && setSlots([]))
|
||||
return () => { alive = false }
|
||||
}, [site, day])
|
||||
|
||||
const times = useMemo(() => slotDays(slots ?? [], timeZone)[0]?.times ?? [], [slots, timeZone])
|
||||
const today = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date())
|
||||
const dayLabel = iso => {
|
||||
const d = new Date(`${iso}T12:00:00Z`)
|
||||
const diff = Math.round((d - new Date(`${today}T12:00:00Z`)) / 86_400_000)
|
||||
if (diff === 0) return t('today')
|
||||
if (diff === 1) return t('tomorrow')
|
||||
return new Intl.DateTimeFormat(lang === 'el' ? 'el-GR' : 'en-GB', { weekday: 'short', day: 'numeric', month: 'short', timeZone: 'UTC' }).format(d)
|
||||
}
|
||||
const chip = on => `shrink-0 px-3.5 h-10 rounded-full text-sm font-semibold ${on ? 'bg-accent text-accent-fg' : 'bg-surface-2 text-ink-2'}`
|
||||
|
||||
if (!res.days.length) return <p className="p-3 rounded-control bg-warning-soft text-warning-ink text-sm" data-testid="no-booking">{t('book.none')}</p>
|
||||
|
||||
return (
|
||||
<div className="grid gap-3" data-testid="booking">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="flex-1 flex items-center gap-2 font-medium text-ink"><Users size={18} aria-hidden="true" />{t('book.party')}</span>
|
||||
<button type="button" aria-label="−" onClick={() => set({ party: Math.max(1, booking.party - 1) })}
|
||||
className="w-10 h-10 rounded-full bg-surface-2 flex items-center justify-center"><Minus size={16} /></button>
|
||||
<span className="w-8 text-center text-lg font-semibold" data-testid="party">{booking.party}</span>
|
||||
<button type="button" aria-label="+" onClick={() => set({ party: Math.min(res.party_max, booking.party + 1) })}
|
||||
className="w-10 h-10 rounded-full bg-accent text-accent-fg flex items-center justify-center"><Plus size={16} /></button>
|
||||
</div>
|
||||
<div className="flex gap-2 overflow-x-auto pb-1" role="radiogroup" aria-label={t('book.day')}>
|
||||
{res.days.map(d => (
|
||||
<button key={d} type="button" role="radio" aria-checked={d === day} className={chip(d === day)} data-testid="book-day" data-day={d}
|
||||
onClick={() => set({ day: d, when: null })}>{dayLabel(d)}</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-4 gap-2" role="radiogroup" aria-label={t('book.time')} data-testid="book-times">
|
||||
{slots === null && <p className="col-span-4 text-sm text-ink-2" role="status">{t('loading')}</p>}
|
||||
{slots !== null && times.length === 0 && <p className="col-span-4 text-sm text-ink-2">{t('book.noTimes')}</p>}
|
||||
{times.map(s => (
|
||||
<button key={s.iso} type="button" role="radio" aria-checked={booking.when === s.iso} data-testid="book-time"
|
||||
onClick={() => set({ day, when: s.iso })}
|
||||
className={`h-10 rounded-control text-sm font-semibold ${booking.when === s.iso ? 'bg-accent text-accent-fg' : 'bg-surface border border-line text-ink'}`}>{s.label}</button>
|
||||
))}
|
||||
</div>
|
||||
{res.with_food && (
|
||||
<label className="flex items-start gap-3 p-3 rounded-control bg-surface-2 cursor-pointer">
|
||||
<input type="checkbox" checked={booking.food} onChange={e => set({ food: e.target.checked })} data-testid="book-food"
|
||||
className="mt-0.5 w-5 h-5 accent-[rgb(var(--o-accent))]" />
|
||||
<span className="grid gap-0.5">
|
||||
<span className="font-semibold text-ink">{t('book.food')}</span>
|
||||
<span className="text-sm text-ink-2">{t('book.foodHint')}</span>
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user