// One online order at the counter (plan step 3.3d): the right column in Online mode. It shows // the customer (phone, address, their note) and the items, and offers the next step only: // accept (kitchen tickets, KDS) or reject (with a reason the customer sees), start preparing, // ready or out for delivery, then finish: take what's unpaid (the counter's ordinary payment, // cash/card/split with the drawer) and mark it delivered. Someone else's change meanwhile is // refused by the backend and the order shows where it is now. // Phase 3S (S.5): the customer's time (or "as soon as possible"), the delivery area, the // delivery fee as its own line (paid with the items), and a warning when the venue's own // prices differ from what the customer was charged online (the customer pays what they saw). import { useState } from 'react' import { AlertTriangle, Ban, Banknote, Bike, Check, ChefHat, Clock, MapPin, MessageSquare, PackageCheck, Phone, ShoppingBag, Utensils } from 'lucide-react' import { errorMessage } from '@xenia/api' import { useFormat, useTranslation } from '@xenia/i18n' import { Button, Dialog, EmptyState, ReasonPicker, reasonText } from '@xenia/ui' import client from '../../api/client' import { diffRows, finishWord as finishOf, kindOf, nextStep } from './logic/online' import { itemPayments, orderLines, orderSums, qtyLabel } from './logic/tables' import PaymentDialog from './PaymentDialog' const REASONS = ['busy', 'unavailable', 'closing', 'area'] const STEP_ICON = { preparing: ChefHat, ready: PackageCheck, out_for_delivery: Bike } const KIND_ICON = { delivery: Bike, takeaway: ShoppingBag, dine_in: Utensils } export default function OnlinePanel({ order, onChanged }) { const { t } = useTranslation('terminal') const { formatMoney, formatTime } = useFormat() const [busy, setBusy] = useState(false) const [error, setError] = useState('') const [paying, setPaying] = useState(null) // rows being paid const [rejecting, setRejecting] = useState(false) if (!order) { return ( ) } const lines = orderLines(order) const sums = orderSums(lines) const step = nextStep(order) const kind = kindOf(order) const KindIcon = KIND_ICON[kind] const finishWord = finishOf(order) const run = async (fn) => { setBusy(true) setError('') try { return await fn() } catch (err) { setError(errorMessage(err, t)); onChanged(); return null } finally { setBusy(false) } } const post = (path, body) => client.post(`/api/connect/orders/${order.id}/${path}`, body) const accept = () => run(async () => { await post('accept'); onChanged(null, { list: 'in_progress' }) }) const advance = to => run(async () => { await post('status', { status: to }); onChanged() }) const payRows = lines.filter(l => !l.paid).map(l => ({ id: l.id, label: `${qtyLabel(l.quantity, l.unitType)} ${l.name}`, total: l.total })) const submitPay = async ({ method, payments, cashGiven }) => (await client.post(`/api/pos/orders/${order.id}/pay`, { payments: method === 'split' ? itemPayments(payments, paying) : [{ method, item_ids: paying.map(r => r.id) }], cash_given: cashGiven, })).data return ( ) } /** When the customer wants it: a time (with the day when it isn't today) or as soon as possible. */ function WhenChip({ when }) { const { t } = useTranslation('terminal') const { formatDate, formatDateTime, formatTime } = useFormat() const label = !when ? t('pos.online.asap') : t('pos.online.for', { when: formatDate(when) === formatDate(new Date()) ? formatTime(when) : formatDateTime(when, 'datetimeShort') }) return (
) } /** The venue's own prices differ from what the customer was charged (S.5): what differs, line by line. */ function PriceCheck({ diff }) { const { t } = useTranslation('terminal') const { formatMoney } = useFormat() const rows = diffRows(diff) if (!rows.length) return null const money = v => (v == null ? '—' : formatMoney(v)) return (

{t('pos.online.diff.body', { charged: formatMoney(diff.cloud_total), here: formatMoney(diff.site_total) })}

) } function Detail({ icon: Icon, children }) { return
} function RejectDialog({ busy, error, onClose, onReject }) { const { t } = useTranslation('terminal') const [choice, setChoice] = useState(null) const [other, setOther] = useState('') const options = REASONS.map(r => ({ value: r, label: t(`pos.online.reasons.${r}`) })) const reason = reasonText(choice, options, other) return ( }>

{t('pos.online.rejectBody')}

{error &&

{error}

}
) }