// 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' 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 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 () => { 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 (

{t('ordering.title')}

{t('ordering.intro')}

{['takeaway', 'delivery'].map(s => ( toggleService(s)} label={t(`ordering.service.${s}`)} description={t(`ordering.serviceHint.${s}`)} data-testid={`ordering-${s}`} /> ))}
set('anyTime', v)} onDays={d => set('days', d)} testId="ordering-hours" />
set('prep_minutes', e.target.value)} />
set('asap', v)} label={t('ordering.asap')} description={t('ordering.asapHint')} />

{t('booking.title')}

{t('booking.intro')}

setRes('enabled', v)} label={t('booking.enabled')} description={t('booking.enabledHint')} data-testid="booking-enabled" /> {form.res.enabled && ( <> setRes('with_food', v)} label={t('booking.withFood')} description={t('booking.withFoodHint')} data-testid="booking-food" /> setRes('anyTime', v)} onDays={d => setRes('days', d)} anyLabel={t('booking.anyTime')} anyHint={t('booking.anyTimeHint')} testId="booking-hours" />
setRes('notice_minutes', e.target.value)} /> setRes('days_ahead', e.target.value)} data-testid="booking-ahead" /> setRes('party_max', e.target.value)} data-testid="booking-party" /> {form.res.with_food && ( setRes('fire_minutes', e.target.value)} data-testid="booking-fire" /> )}
)}
) } /** 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 (
{!anyTime && ( )}
) }