feat: online ordering settings (services, hours, preparation, slots) and the order app e2e (platform-v2 3S, S.4)

- connect_orders.ordering setting; GET/PUT /api/connect/fees/ordering (validated:
  services, hours per day incl. past midnight, preparation, slot minutes, days ahead,
  ASAP); pushed to the cloud with the menu (snapshot `ordering`).
- Manager: the Online ordering page gains "Services and hours" (OrderingSettings.jsx; logic
  in feesLogic.js, unit-tested); nav label "Online ordering".
- tests/e2e/order_app.mjs: a real cloud + the built order app in a phone-sized browser:
  takeaway and delivery placed, priced by the cloud (fee by area, minimum refused), the
  site moves the delivery to delivered and the page follows; a rejection with its reason;
  Greek. In run-all, with the order app's unit tests.
- Tests: backend +1 (406), manager unit +1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 13:39:13 +02:00
co-authored by Claude Opus 5.5
parent df27133af9
commit 8ea44d71aa
12 changed files with 507 additions and 11 deletions
@@ -0,0 +1,98 @@
// 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.
import { useState } from 'react'
import toast from 'react-hot-toast'
import { Plus, X } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, IconButton, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { DAYS, orderingBody, orderingToForm } from './feesLogic'
export default function OrderingSettings({ ordering, onSaved }) {
const { t } = useTranslation('manager')
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 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 () => {
setBusy(true)
try {
const { data } = await client.put('/api/connect/fees/ordering', orderingBody(form))
setForm(orderingToForm(data))
toast.success(t('fees.saved'))
onSaved?.()
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (
<section className="p-4 rounded-card border border-line bg-surface grid gap-4" aria-labelledby="ordering-h" data-testid="ordering-settings">
<div className="grid gap-1">
<h2 id="ordering-h" className="text-title font-semibold text-ink">{t('ordering.title')}</h2>
<p className="text-label text-ink-2">{t('ordering.intro')}</p>
</div>
<div className="grid gap-2 sm:grid-cols-2">
{['takeaway', 'delivery'].map(s => (
<Switch key={s} checked={form.services.includes(s)} onChange={() => toggleService(s)}
label={t(`ordering.service.${s}`)} description={t(`ordering.serviceHint.${s}`)} data-testid={`ordering-${s}`} />
))}
</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>
<div className="grid gap-3 sm:grid-cols-3">
<Field label={t('ordering.prep')} hint={t('ordering.prepHint')}>
<Input inputMode="numeric" value={form.prep_minutes} onChange={e => set('prep_minutes', e.target.value)} />
</Field>
<Field label={t('ordering.slot')} hint={t('ordering.slotHint')}>
<Select value={form.slot_minutes} onChange={e => set('slot_minutes', e.target.value)}>
{['10', '15', '20', '30', '60'].map(m => <option key={m} value={m}>{t('ordering.minutes', { n: m })}</option>)}
</Select>
</Field>
<Field label={t('ordering.ahead')}>
<Select value={form.days_ahead} onChange={e => set('days_ahead', e.target.value)}>
{['0', '1', '2', '3', '7'].map(n => <option key={n} value={n}>{t(`ordering.aheadN.${n}`)}</option>)}
</Select>
</Field>
</div>
<Switch checked={form.asap} onChange={v => set('asap', v)} label={t('ordering.asap')} description={t('ordering.asapHint')} />
<div><Button onClick={save} loading={busy} data-testid="ordering-save">{t('fees.save')}</Button></div>
</section>
)
}