feat(connect): table bookings from the online ordering app; food fired to the kitchen before arrival
Plan phase 3S, step S.6. - Pull: "reservation" / "preorder" orders become Reservations waiting for an answer (status "requested"; services/online_reservations.py), with the food ordered ahead kept on the booking (items_json at the cloud's prices, the site's price check) — no order yet. Migration 0020 (reservations: online_order_cloud_id, online_ref, items_json, total, online_price_diff, fire_at, order_id, response_note). - Confirm → the food's fire time = booking time − fire minutes (setting); the fire worker (connect_orders, every 20 s) turns the food into an order at that time (needs an open business day; waits otherwise): kitchen tickets, KDS (reference and time). Early arrival fires at once. Seating moves the order to the table (refused if the table has an open order). Decline / cancel / no-show with a reason. Every step mirrored to the cloud. - Found: the KDS filter dropped every online order without an online status (SQL NULL in NOT(a AND b)) — made NULL-safe. - Counter: Online → Bookings (requests first, then upcoming), BookingPanel (confirm, decline with reasons, food and when it goes to the kitchen, seat at a free table, cancel, no-show); the Online badge and chime count booking requests. - Manager: Online ordering → Table bookings settings (on, food ahead, hours, slot, notice, days ahead, party size, fire minutes); the dashboard's reservations card confirms / declines online requests; the reservations router delegates online bookings' status steps. - Tests: tests/test_online_bookings.py (8), unit tests (terminal, manager), e2e: order app (book with food → the venue confirms), terminal (request → confirm → the two dishes reach the KDS at the fire time, not before → seated), manager (booking settings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// Online ordering settings (plan phase 3S, step S.4): which services the online ordering app
|
||||
// offers (takeaway, delivery), when (ordering hours per day, or any time), how long before
|
||||
// an order can be ready (preparation), the times offered (every N minutes, days ahead) and
|
||||
// "as soon as possible". The cloud enforces them at checkout. PUT /api/connect/fees/ordering.
|
||||
// Online ordering settings (plan phase 3S, steps S.4 and S.6): which services the online
|
||||
// ordering app offers (takeaway, delivery), when (ordering hours per day, or any time), how
|
||||
// long before an order can be ready (preparation), the times offered (every N minutes, days
|
||||
// ahead) and "as soon as possible"; and table bookings (a table only, or with food ordered
|
||||
// ahead): their own hours, time grid, notice, days ahead, party size, and when the kitchen gets
|
||||
// the food before the guests arrive. The cloud enforces them. PUT /api/connect/fees/ordering.
|
||||
import { useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Plus, X } from 'lucide-react'
|
||||
@@ -16,7 +18,7 @@ export default function OrderingSettings({ ordering, onSaved }) {
|
||||
const [form, setForm] = useState(() => orderingToForm(ordering))
|
||||
const [busy, setBusy] = useState(false)
|
||||
const set = (k, v) => setForm(f => ({ ...f, [k]: v }))
|
||||
const setDay = (d, ranges) => setForm(f => ({ ...f, days: f.days.map((r, i) => (i === d ? ranges : r)) }))
|
||||
const setRes = (k, v) => setForm(f => ({ ...f, res: { ...f.res, [k]: v } }))
|
||||
const toggleService = s => set('services', form.services.includes(s) ? form.services.filter(x => x !== s) : ['takeaway', 'delivery'].filter(x => x === s || form.services.includes(x)))
|
||||
|
||||
const save = async () => {
|
||||
@@ -44,37 +46,7 @@ export default function OrderingSettings({ ordering, onSaved }) {
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-2">
|
||||
<Switch checked={form.anyTime} onChange={v => set('anyTime', v)} label={t('ordering.anyTime')} description={t('ordering.anyTimeHint')} />
|
||||
{!form.anyTime && (
|
||||
<ul className="grid gap-1.5" data-testid="ordering-hours">
|
||||
{DAYS.map(d => (
|
||||
<li key={d} className="grid grid-cols-[6rem_1fr] gap-2 items-start">
|
||||
<span className="text-body text-ink pt-2">{t(`fees.dayLong.${d}`)}</span>
|
||||
<div className="grid gap-1.5">
|
||||
{form.days[d].length === 0 && <span className="text-label text-ink-3 pt-2">{t('ordering.closedDay')}</span>}
|
||||
{form.days[d].map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input type="time" size="sm" value={r.from} aria-label={t('fees.timeFrom')}
|
||||
onChange={e => setDay(d, form.days[d].map((x, j) => (j === i ? { ...x, from: e.target.value } : x)))} />
|
||||
<span className="text-ink-3">–</span>
|
||||
<Input type="time" size="sm" value={r.to} aria-label={t('fees.timeTo')}
|
||||
onChange={e => setDay(d, form.days[d].map((x, j) => (j === i ? { ...x, to: e.target.value } : x)))} />
|
||||
<IconButton size="sm" label={t('fees.delete')} onClick={() => setDay(d, form.days[d].filter((_, j) => j !== i))}><X size={16} /></IconButton>
|
||||
</div>
|
||||
))}
|
||||
{form.days[d].length < 4 && (
|
||||
<button type="button" className="justify-self-start text-label font-medium text-accent-ink flex items-center gap-1"
|
||||
onClick={() => setDay(d, [...form.days[d], { from: '12:00', to: '23:00' }])}>
|
||||
<Plus size={14} aria-hidden="true" />{t('ordering.addHours')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
<Hours anyTime={form.anyTime} days={form.days} onAnyTime={v => set('anyTime', v)} onDays={d => set('days', d)} testId="ordering-hours" />
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<Field label={t('ordering.prep')} hint={t('ordering.prepHint')}>
|
||||
@@ -92,7 +64,82 @@ export default function OrderingSettings({ ordering, onSaved }) {
|
||||
</Field>
|
||||
</div>
|
||||
<Switch checked={form.asap} onChange={v => set('asap', v)} label={t('ordering.asap')} description={t('ordering.asapHint')} />
|
||||
|
||||
<div className="grid gap-3 pt-4 border-t border-line" data-testid="booking-settings">
|
||||
<div className="grid gap-1">
|
||||
<h3 className="text-body-lg font-semibold text-ink">{t('booking.title')}</h3>
|
||||
<p className="text-label text-ink-2">{t('booking.intro')}</p>
|
||||
</div>
|
||||
<Switch checked={form.res.enabled} onChange={v => setRes('enabled', v)} label={t('booking.enabled')} description={t('booking.enabledHint')} data-testid="booking-enabled" />
|
||||
{form.res.enabled && (
|
||||
<>
|
||||
<Switch checked={form.res.with_food} onChange={v => setRes('with_food', v)} label={t('booking.withFood')} description={t('booking.withFoodHint')} data-testid="booking-food" />
|
||||
<Hours anyTime={form.res.anyTime} days={form.res.days} onAnyTime={v => setRes('anyTime', v)} onDays={d => setRes('days', d)}
|
||||
anyLabel={t('booking.anyTime')} anyHint={t('booking.anyTimeHint')} testId="booking-hours" />
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<Field label={t('ordering.slot')} hint={t('booking.slotHint')}>
|
||||
<Select value={form.res.slot_minutes} onChange={e => setRes('slot_minutes', e.target.value)}>
|
||||
{['15', '30', '60'].map(m => <option key={m} value={m}>{t('ordering.minutes', { n: m })}</option>)}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field label={t('booking.notice')} hint={t('booking.noticeHint')}>
|
||||
<Input inputMode="numeric" value={form.res.notice_minutes} onChange={e => setRes('notice_minutes', e.target.value)} />
|
||||
</Field>
|
||||
<Field label={t('booking.ahead')}>
|
||||
<Input inputMode="numeric" value={form.res.days_ahead} onChange={e => setRes('days_ahead', e.target.value)} data-testid="booking-ahead" />
|
||||
</Field>
|
||||
<Field label={t('booking.party')}>
|
||||
<Input inputMode="numeric" value={form.res.party_max} onChange={e => setRes('party_max', e.target.value)} data-testid="booking-party" />
|
||||
</Field>
|
||||
{form.res.with_food && (
|
||||
<Field label={t('booking.fire')} hint={t('booking.fireHint')}>
|
||||
<Input inputMode="numeric" value={form.res.fire_minutes} onChange={e => setRes('fire_minutes', e.target.value)} data-testid="booking-fire" />
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div><Button onClick={save} loading={busy} data-testid="ordering-save">{t('fees.save')}</Button></div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** Hours per day (several ranges, past midnight), or any time. */
|
||||
function Hours({ anyTime, days, onAnyTime, onDays, anyLabel, anyHint, testId }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const setDay = (d, ranges) => onDays(days.map((r, i) => (i === d ? ranges : r)))
|
||||
return (
|
||||
<div className="grid gap-2">
|
||||
<Switch checked={anyTime} onChange={onAnyTime} label={anyLabel ?? t('ordering.anyTime')} description={anyHint ?? t('ordering.anyTimeHint')} />
|
||||
{!anyTime && (
|
||||
<ul className="grid gap-1.5" data-testid={testId}>
|
||||
{DAYS.map(d => (
|
||||
<li key={d} className="grid grid-cols-[6rem_1fr] gap-2 items-start">
|
||||
<span className="text-body text-ink pt-2">{t(`fees.dayLong.${d}`)}</span>
|
||||
<div className="grid gap-1.5">
|
||||
{days[d].length === 0 && <span className="text-label text-ink-3 pt-2">{t('ordering.closedDay')}</span>}
|
||||
{days[d].map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2">
|
||||
<Input type="time" size="sm" value={r.from} aria-label={t('fees.timeFrom')}
|
||||
onChange={e => setDay(d, days[d].map((x, j) => (j === i ? { ...x, from: e.target.value } : x)))} />
|
||||
<span className="text-ink-3">–</span>
|
||||
<Input type="time" size="sm" value={r.to} aria-label={t('fees.timeTo')}
|
||||
onChange={e => setDay(d, days[d].map((x, j) => (j === i ? { ...x, to: e.target.value } : x)))} />
|
||||
<IconButton size="sm" label={t('fees.delete')} onClick={() => setDay(d, days[d].filter((_, j) => j !== i))}><X size={16} /></IconButton>
|
||||
</div>
|
||||
))}
|
||||
{days[d].length < 4 && (
|
||||
<button type="button" className="justify-self-start text-label font-medium text-accent-ink flex items-center gap-1"
|
||||
onClick={() => setDay(d, [...days[d], { from: '12:00', to: '23:00' }])}>
|
||||
<Plus size={14} aria-hidden="true" />{t('ordering.addHours')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user