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:
@@ -1396,13 +1396,14 @@ function RevenueChart({ orders }) {
|
||||
// ─── Reservations ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_META = {
|
||||
requested: { label: 'Αίτημα online', bg: '#fff7ed', color: '#c2410c' }, // phase 3S, S.6: to confirm or decline
|
||||
pending: { label: 'Αναμονή', bg: '#f0f4ff', color: '#3758c9' },
|
||||
arrived: { label: 'Έφτασε', bg: '#eef7f0', color: '#1f7042' },
|
||||
cancelled: { label: 'Ακυρώθηκε', bg: '#fef2f2', color: '#dc2626' },
|
||||
no_show: { label: 'Δεν ήρθε', bg: '#fff7ed', color: '#c2410c' },
|
||||
}
|
||||
|
||||
function ReservationRow({ res, tables, onStatusChange, onEdit }) {
|
||||
function ReservationRow({ res, tables, onStatusChange, onEdit, onAnswer }) {
|
||||
const meta = STATUS_META[res.status] || STATUS_META.pending
|
||||
const time = new Date(res.reserved_for).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
|
||||
const dateStr = new Date(res.reserved_for).toLocaleDateString('el-GR', { day: 'numeric', month: 'short' })
|
||||
@@ -1449,6 +1450,20 @@ function ReservationRow({ res, tables, onStatusChange, onEdit }) {
|
||||
background: 'white', cursor: 'pointer', fontSize: 12,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>✏️</button>
|
||||
{res.status === 'requested' && (
|
||||
<>
|
||||
<button onClick={() => onAnswer(res.id, 'confirm')} title="Επιβεβαίωση" data-testid="booking-confirm" style={{
|
||||
width: 26, height: 26, borderRadius: 6, border: '1px solid #bbf7d0',
|
||||
background: '#eef7f0', cursor: 'pointer', fontSize: 12,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>✓</button>
|
||||
<button onClick={() => onAnswer(res.id, 'decline')} title="Απόρριψη" style={{
|
||||
width: 26, height: 26, borderRadius: 6, border: '1px solid #fecaca',
|
||||
background: '#fef2f2', cursor: 'pointer', fontSize: 12,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>✖</button>
|
||||
</>
|
||||
)}
|
||||
{res.status === 'pending' && (
|
||||
<button onClick={() => onStatusChange(res.id, 'arrived')} title="Έφτασε" style={{
|
||||
width: 26, height: 26, borderRadius: 6, border: '1px solid #bbf7d0',
|
||||
@@ -1488,6 +1503,19 @@ function ReservationsCard({ tables, onNew }) {
|
||||
},
|
||||
onError: () => toast.error('Σφάλμα ενημέρωσης'),
|
||||
})
|
||||
// online booking requests (phase 3S, S.6): the customer sees the answer (and the reason)
|
||||
const answerMut = useMutation({
|
||||
mutationFn: ({ id, action, reason }) => client.post(`/api/connect/bookings/${id}/${action}`, action === 'decline' ? { reason } : {}),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['reservations'] }),
|
||||
onError: () => toast.error('Σφάλμα ενημέρωσης'),
|
||||
})
|
||||
const answer = (id, action) => {
|
||||
if (action === 'decline') {
|
||||
const reason = window.prompt('Λόγος (τον βλέπει ο πελάτης):', 'Δεν υπάρχει διαθεσιμότητα εκείνη την ώρα')
|
||||
if (reason === null) return
|
||||
answerMut.mutate({ id, action, reason: reason.trim() || null })
|
||||
} else answerMut.mutate({ id, action })
|
||||
}
|
||||
|
||||
const tabStyle = (active) => ({
|
||||
height: 30, padding: '0 14px', borderRadius: 8, border: 'none',
|
||||
@@ -1534,6 +1562,7 @@ function ReservationsCard({ tables, onNew }) {
|
||||
tables={tables}
|
||||
onStatusChange={(id, s) => statusMut.mutate({ id, status: s })}
|
||||
onEdit={setEditTarget}
|
||||
onAnswer={answer}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -104,28 +104,48 @@ export function previewBody(form) {
|
||||
}
|
||||
|
||||
/** Online ordering settings (S.4) → the form: hours as editable rows per day. */
|
||||
const toDays = hours => DAYS.map(d => (hours?.[String(d)] ?? []).map(([from, to]) => ({ from, to })))
|
||||
function toHours(anyTime, days) {
|
||||
const hours = {}
|
||||
if (!anyTime) {
|
||||
days.forEach((ranges, d) => {
|
||||
const clean = ranges.filter(r => r.from && r.to && r.from !== r.to).map(r => [r.from, r.to])
|
||||
if (clean.length) hours[String(d)] = clean
|
||||
})
|
||||
}
|
||||
return hours
|
||||
}
|
||||
const int = (v, dflt) => (Number.isFinite(Number(v)) && String(v).trim() !== '' ? Math.round(Number(v)) : dflt)
|
||||
|
||||
/** Table bookings online (S.6): the defaults the backend has. */
|
||||
export const RES_DEFAULTS = { enabled: false, with_food: false, hours: {}, slot_minutes: 30, days_ahead: 30, notice_minutes: 60, party_max: 10, fire_minutes: 20 }
|
||||
|
||||
export function orderingToForm(o) {
|
||||
const hours = o?.hours ?? {}
|
||||
const r = { ...RES_DEFAULTS, ...(o?.reservations ?? {}) }
|
||||
return {
|
||||
services: o?.services ?? [], anyTime: Object.keys(hours).length === 0,
|
||||
days: DAYS.map(d => (hours[String(d)] ?? []).map(([from, to]) => ({ from, to }))),
|
||||
days: toDays(hours),
|
||||
prep_minutes: String(o?.prep_minutes ?? 20), slot_minutes: String(o?.slot_minutes ?? 15),
|
||||
days_ahead: String(o?.days_ahead ?? 0), asap: o?.asap ?? true,
|
||||
res: {
|
||||
enabled: !!r.enabled, with_food: !!r.with_food, anyTime: Object.keys(r.hours ?? {}).length === 0, days: toDays(r.hours),
|
||||
slot_minutes: String(r.slot_minutes), days_ahead: String(r.days_ahead), notice_minutes: String(r.notice_minutes),
|
||||
party_max: String(r.party_max), fire_minutes: String(r.fire_minutes),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** The form → PUT /api/connect/fees/ordering. A day without ranges is closed (unless any time). */
|
||||
export function orderingBody(form) {
|
||||
const hours = {}
|
||||
if (!form.anyTime) {
|
||||
form.days.forEach((ranges, d) => {
|
||||
const clean = ranges.filter(r => r.from && r.to && r.from !== r.to).map(r => [r.from, r.to])
|
||||
if (clean.length) hours[String(d)] = clean
|
||||
})
|
||||
}
|
||||
const int = (v, dflt) => (Number.isFinite(Number(v)) && String(v).trim() !== '' ? Math.round(Number(v)) : dflt)
|
||||
const r = form.res ?? orderingToForm(null).res
|
||||
return {
|
||||
services: form.services, hours, prep_minutes: int(form.prep_minutes, 20), slot_minutes: int(form.slot_minutes, 15),
|
||||
services: form.services, hours: toHours(form.anyTime, form.days), prep_minutes: int(form.prep_minutes, 20), slot_minutes: int(form.slot_minutes, 15),
|
||||
days_ahead: int(form.days_ahead, 0), asap: !!form.asap,
|
||||
reservations: {
|
||||
enabled: !!r.enabled, with_food: !!r.enabled && !!r.with_food, hours: toHours(r.anyTime, r.days),
|
||||
slot_minutes: int(r.slot_minutes, 30), days_ahead: int(r.days_ahead, 30), notice_minutes: int(r.notice_minutes, 60),
|
||||
party_max: int(r.party_max, 10), fire_minutes: int(r.fire_minutes, 20),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,15 +51,27 @@ test('moving rules and the test form', () => {
|
||||
})
|
||||
|
||||
test('online ordering settings: hours per day, any time, numbers', async () => {
|
||||
const { orderingBody, orderingToForm } = await import('../src/pages/online/feesLogic.js')
|
||||
const saved = { services: ['delivery'], hours: { 5: [['20:00', '02:00']] }, prep_minutes: 30, slot_minutes: 15, days_ahead: 1, asap: false }
|
||||
const { RES_DEFAULTS, orderingBody, orderingToForm } = await import('../src/pages/online/feesLogic.js')
|
||||
const saved = { services: ['delivery'], hours: { 5: [['20:00', '02:00']] }, prep_minutes: 30, slot_minutes: 15, days_ahead: 1, asap: false,
|
||||
reservations: RES_DEFAULTS }
|
||||
const form = orderingToForm(saved)
|
||||
assert.equal(form.anyTime, false)
|
||||
assert.deepEqual(form.days[5], [{ from: '20:00', to: '02:00' }])
|
||||
assert.deepEqual(orderingBody(form), saved)
|
||||
assert.deepEqual(orderingBody({ ...form, anyTime: true }).hours, {})
|
||||
const blank = orderingToForm(null)
|
||||
assert.deepEqual(orderingBody({ ...blank, prep_minutes: '' }), { services: [], hours: {}, prep_minutes: 20, slot_minutes: 15, days_ahead: 0, asap: true })
|
||||
assert.deepEqual(orderingBody({ ...blank, prep_minutes: '' }), { services: [], hours: {}, prep_minutes: 20, slot_minutes: 15, days_ahead: 0, asap: true, reservations: RES_DEFAULTS })
|
||||
form.days[0] = [{ from: '12:00', to: '12:00' }, { from: '', to: '15:00' }]
|
||||
assert.equal(orderingBody(form).hours['0'], undefined)
|
||||
})
|
||||
|
||||
test('table bookings online: settings round trip (S.6)', async () => {
|
||||
const { orderingBody, orderingToForm } = await import('../src/pages/online/feesLogic.js')
|
||||
const reservations = { enabled: true, with_food: true, hours: { 4: [['19:00', '23:30']] }, slot_minutes: 15, days_ahead: 14, notice_minutes: 90, party_max: 8, fire_minutes: 25 }
|
||||
const form = orderingToForm({ services: [], hours: {}, reservations })
|
||||
assert.equal(form.res.anyTime, false)
|
||||
assert.deepEqual(orderingBody(form).reservations, reservations)
|
||||
assert.deepEqual(orderingBody({ ...form, res: { ...form.res, enabled: false } }).reservations.with_food, false)
|
||||
assert.deepEqual(orderingBody({ ...form, res: { ...form.res, anyTime: true, party_max: '' } }).reservations,
|
||||
{ ...reservations, hours: {}, party_max: 10 })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user