feat: tables and orders in the manager on v2 (platform-v2 step 6.9)
- manager: new pages/orders/ (Tables page cards + quick actions, order page with
lines, multi-select pay/discount/cancel/tab, staff + customer, price changes,
history, the menu + cart beside it); a free table opens a new order on first
Send; v1 TablesPage, OrderDetailPage, DesktopOrderingTab, ManagerOrderDrawer
and PaymentMethodModal removed
- ordering by line id like the phones: GET /api/orders/menu (the counter's
product shape, in-store prices); the product dialog, cart rules and quote hook
move to packages/ordering (@xenia/ordering), shared by counter, menu tablet,
manager
- close follows orders.close_with_unpaid (pay first, or write off after saying
so) on the order page and the overview's quick view; paying asks cash or card
- a confirmed booking can keep its table ahead (manager, phones, counter):
POST /api/connect/bookings/{id}/table, reservations create/PATCH; refused with
reservation.table_kept within 2 h of another booking
- tests: test_manager_ordering.py, online bookings +2, manager orders.test.mjs,
@xenia/ordering, e2e manager.mjs (take, change, pay-first close, RESERVED)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import { lineTotal, orderTotal } from './overviewLogic'
|
||||
import { Money, Pill } from './parts'
|
||||
import { useDuration } from './hooks'
|
||||
import PayDialog from '../orders/PayDialog'
|
||||
import { closeStep, selectedAmount, unpaidIds, venueRules } from '../orders/orderLogic'
|
||||
|
||||
const ORDER_EVENTS = ['order_updated', 'order_paid', 'order_closed', 'order_refunded']
|
||||
const STATUS_TONE = { open: 'success', partially_paid: 'info', paid: 'accent', closed: 'neutral', cancelled: 'danger' }
|
||||
@@ -27,6 +29,9 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
const [confirm, setConfirm] = useState(null) // { kind: 'cancelItem', itemId } | { kind: 'cancelOrder' } | { kind: 'close' }
|
||||
const [printCancel, setPrintCancel] = useState(null) // the same, after "yes": ask about the ticket
|
||||
const [printerId, setPrinterId] = useState('')
|
||||
const [paying, setPaying] = useState(null) // { ids, thenClose } (6.9: cash or card, the venue's close rule)
|
||||
const { data: settings } = useLiveQuery({ queryKey: ['settings'], queryFn: () => client.get('/api/settings/').then(r => r.data), staleTime: 60_000 })
|
||||
const venue = venueRules(settings)
|
||||
|
||||
const { data: order, isPending } = useLiveQuery({
|
||||
queryKey: ['order', orderId],
|
||||
@@ -52,7 +57,12 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
onSuccess: () => { toast.success(done); refresh(); after?.() },
|
||||
onError: err => toast.error(errorMessage(err, t)),
|
||||
})
|
||||
const pay = useMutation(run(ids => client.post(`/api/orders/${orderId}/pay`, { item_ids: ids }), t('overview.order.paidDone')))
|
||||
const pay = ids => setPaying({ ids })
|
||||
const startClose = () => {
|
||||
const step = closeStep(order, venue.closeWithUnpaid)
|
||||
if (step === 'payFirst') setPaying({ ids: unpaidIds(order), thenClose: true })
|
||||
else setConfirm({ kind: step === 'writeOff' ? 'writeOff' : 'close' })
|
||||
}
|
||||
const cancelItem = useMutation(run(({ itemId, print }) => client.delete(`/api/orders/${orderId}/items/${itemId}`, { params: { print_cancellation: print } }), t('overview.order.lineCancelled')))
|
||||
const cancelOrder = useMutation(run(({ print }) => client.delete(`/api/orders/${orderId}`, { params: { print_cancellation: print } }), t('overview.order.cancelled'), onClose))
|
||||
const close = useMutation(run(() => client.post(`/api/orders/${orderId}/close`), t('overview.order.closed'), onClose))
|
||||
@@ -64,7 +74,7 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
const confirmed = () => {
|
||||
const c = confirm
|
||||
setConfirm(null)
|
||||
if (c.kind === 'close') close.mutate()
|
||||
if (c.kind === 'close' || c.kind === 'writeOff') close.mutate()
|
||||
else setPrintCancel(c)
|
||||
}
|
||||
const cancelWith = printIt => {
|
||||
@@ -83,8 +93,8 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
</span>}
|
||||
description={order ? t('overview.order.sub', { id: order.id, time: formatTime(order.opened_at), since: since(order.opened_at) }) : undefined}
|
||||
footer={order && <div className="flex flex-wrap items-center gap-2 w-full">
|
||||
{isOpen && active.length > 0 && <Button onClick={() => pay.mutate(active.map(i => i.id))} loading={pay.isPending} data-testid="order-pay-all">{t('overview.order.payAll')}</Button>}
|
||||
{isOpen && <Button variant="secondary" onClick={() => setConfirm({ kind: 'close' })}>{t('overview.order.close')}</Button>}
|
||||
{isOpen && active.length > 0 && <Button onClick={() => pay(active.map(i => i.id))} data-testid="order-pay-all">{t('overview.order.payAll')}</Button>}
|
||||
{isOpen && <Button variant="secondary" onClick={startClose} data-testid="order-close">{t('overview.order.close')}</Button>}
|
||||
{isOpen && <Button variant="danger" onClick={() => setConfirm({ kind: 'cancelOrder' })}>{t('overview.order.cancel')}</Button>}
|
||||
<span className="flex-1" />
|
||||
{printers.length > 0 && (
|
||||
@@ -125,7 +135,7 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
</div>
|
||||
<Money value={lineTotal(item)} className={cx('text-body font-semibold min-w-16 text-right', item.price_adjustment ? 'text-info-ink' : 'text-ink')} />
|
||||
{isOpen && item.status === 'active' && (<>
|
||||
<Button size="sm" variant="secondary" onClick={() => pay.mutate([item.id])}>{t('overview.order.pay')}</Button>
|
||||
<Button size="sm" variant="secondary" onClick={() => pay([item.id])}>{t('overview.order.pay')}</Button>
|
||||
<IconButton size="sm" variant="ghost" label={t('overview.order.cancelLine')} onClick={() => setConfirm({ kind: 'cancelItem', itemId: item.id })}><X size={16} /></IconButton>
|
||||
</>)}
|
||||
</div>
|
||||
@@ -146,16 +156,28 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
|
||||
)}
|
||||
|
||||
{confirm && (
|
||||
<Dialog open size="sm" onClose={() => setConfirm(null)} title={t(`overview.order.confirm.${confirm.kind}`)}
|
||||
<Dialog open size="sm" onClose={() => setConfirm(null)} title={confirm.kind === 'writeOff' ? t('orders.writeOffTitle') : t(`overview.order.confirm.${confirm.kind}`)}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={() => setConfirm(null)}>{t('overview.back')}</Button>
|
||||
<Button variant={confirm.kind === 'close' ? 'primary' : 'danger'} onClick={confirmed} data-testid="order-confirm">
|
||||
{confirm.kind === 'close' ? t('overview.order.close') : t('overview.order.cancel')}
|
||||
{confirm.kind === 'close' ? t('overview.order.close') : confirm.kind === 'writeOff' ? t('orders.writeOff') : t('overview.order.cancel')}
|
||||
</Button>
|
||||
</>}>
|
||||
{confirm.kind === 'cancelOrder' && <p>{t('overview.order.confirm.cancelOrderBody')}</p>}
|
||||
{confirm.kind === 'writeOff' && <p>{t('orders.writeOffBody', { count: unpaidIds(order).length, amount: formatMoney(selectedAmount(order, unpaidIds(order))) })}</p>}
|
||||
</Dialog>
|
||||
)}
|
||||
{paying && order && (
|
||||
<PayDialog orderId={orderId} itemIds={paying.ids} amount={selectedAmount(order, paying.ids)} card={venue.card} thenClose={!!paying.thenClose}
|
||||
onClose={() => setPaying(null)}
|
||||
onDone={() => {
|
||||
toast.success(paying.thenClose ? t('overview.order.closed') : t('overview.order.paidDone'))
|
||||
const closed = paying.thenClose
|
||||
setPaying(null)
|
||||
refresh()
|
||||
if (closed) onClose()
|
||||
}} />
|
||||
)}
|
||||
{printCancel && (
|
||||
<Dialog open size="sm" onClose={() => setPrintCancel(null)} title={t('overview.order.printCancel')}
|
||||
footer={<>
|
||||
|
||||
Reference in New Issue
Block a user