feat(manager): the overview, online orders and the day summary on v2 (platform-v2 step 6.2)
- DashboardPage (2.8k lines) → src/pages/overview/: OverviewPage + cards (shifts, tables, pending prints, notes, bookings, messages) and dialogs (order at a glance, shift review / end with the cash handover, day summary with cash count and checks); arithmetic in overviewLogic.js (tests/overview.test.mjs). Data via useLiveQuery: orders and tables live, day and shifts every 15 s. Bookings typed in venue time; decline reason in a dialog. - OnlineOrdersPage → src/pages/online/ on react-query + live events; unused API helpers dropped. - WorkdaySummaryModal → overview/DaySummaryDialog + DaySummaryTabs. - Every text in manager.json (en + el, 342 keys); tokens only; v2.json adds overview, hooks. - Backend: business day open/close answer only with codes (license.locked, license.expired, business_day.orders_open); XeniaError's v1 `detail` removed. - @xenia/i18n: formatDateTime with Intl options threw "unknown date style" (fixed, tested). - e2e manager.mjs: open the day, a shift (start, stats, end short), a live table, a booking, day stats, Greek, close the day (forced), online orders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
// A waiter's shift, from the overview's shift list (plan step 6.2): its money (what should be in
|
||||
// the drawer: the starting cash + cash taken), the cash / card split, sales per hour and counts,
|
||||
// and every line of the shift with who ordered and who took the money (filters). In "close"
|
||||
// mode it ends the shift: notes, then the cash the waiter hands over, compared with what was
|
||||
// expected (short / over / even), then "End the shift".
|
||||
import { useState } from 'react'
|
||||
import { useTranslation, useFormat, parseNumber } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, Input, Spinner, Textarea, cx } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import { ITEM_KINDS, cashCheck, hourBuckets, itemKind, itemShown, quickAmounts, shiftCounts, shiftMoney, shiftPairs } from './overviewLogic'
|
||||
import { Avatar, Figure, HourBars, Money, Pill, SplitBar } from './parts'
|
||||
import { SOFT } from './tones'
|
||||
import { useDuration, useHourOf } from './hooks'
|
||||
|
||||
const KIND_TONE = { both: 'success', paid: 'info', ordered: 'warning', unpaid: 'warning', cancelled: 'danger', anomaly: 'danger' }
|
||||
const CHECK_TONE = { even: 'success', over: 'success', short: 'danger' }
|
||||
|
||||
export default function ShiftDialog({ shift, mode, onClose, onConfirm, busy }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatTime, formatMoney } = useFormat()
|
||||
const since = useDuration()
|
||||
const hourOf = useHourOf()
|
||||
const [screen, setScreen] = useState('overview') // overview | lines
|
||||
const [step, setStep] = useState(1) // close mode: 1 review + notes, 2 cash handover
|
||||
const [notes, setNotes] = useState('')
|
||||
const [counted, setCounted] = useState('')
|
||||
const [kind, setKind] = useState('all')
|
||||
const [payment, setPayment] = useState('any')
|
||||
|
||||
const { data: summary, isPending } = useLiveQuery({
|
||||
queryKey: ['shift-summary', shift.id],
|
||||
queryFn: () => client.get(`/api/shifts/${shift.id}/summary`).then(r => r.data),
|
||||
events: ['order_paid', 'order_updated'],
|
||||
})
|
||||
const data = summary || shift
|
||||
const money = shiftMoney(data)
|
||||
const counts = shiftCounts(summary)
|
||||
const countedValue = counted === '' ? null : parseNumber(counted)
|
||||
const check = cashCheck(countedValue, money.expected)
|
||||
const waiterId = shift.waiter_id ?? summary?.waiter_id
|
||||
const closing = mode === 'close'
|
||||
|
||||
const footer = !closing ? (<>
|
||||
<span className="flex-1 text-caption text-ink-3">{t('overview.shift.live')}</span>
|
||||
<Button variant="secondary" onClick={onClose}>{t('overview.close')}</Button>
|
||||
</>) : step === 1 ? (<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||
<span className="flex-1 text-caption text-ink-3">{t('overview.shift.checkFirst')}</span>
|
||||
<Button onClick={() => { setScreen('overview'); setStep(2) }} data-testid="shift-next">{t('overview.shift.toHandover')}</Button>
|
||||
</>) : (<>
|
||||
<Button variant="secondary" onClick={() => setStep(1)}>{t('overview.back')}</Button>
|
||||
<span className="flex-1" />
|
||||
<Button variant="danger" loading={busy} data-testid="shift-end-confirm"
|
||||
onClick={() => onConfirm(notes, countedValue != null && Number.isFinite(countedValue) ? countedValue : null)}>{t('overview.shift.endNow')}</Button>
|
||||
</>)
|
||||
|
||||
return (
|
||||
<Dialog open size="lg" onClose={onClose} footer={footer}
|
||||
title={<span className="flex items-center gap-3">
|
||||
<Avatar name={shift.waiter_name} url={shift.avatar_url} size="lg" />
|
||||
<span className="grid">
|
||||
<span className="flex items-center gap-2">{shift.waiter_name}
|
||||
<Pill tone={closing ? 'warning' : 'success'}>{closing ? t('overview.shift.closing') : t('overview.shift.running')}</Pill>
|
||||
</span>
|
||||
<span className="text-caption font-normal text-ink-3">{t('overview.shift.number', { id: shift.id })}</span>
|
||||
</span>
|
||||
</span>}>
|
||||
<div className="grid gap-4" data-testid="shift-dialog">
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<Figure label={t('overview.shift.start')}>{formatTime(shift.started_at)}</Figure>
|
||||
<Figure label={t('overview.shift.length')}>{since(shift.started_at)}</Figure>
|
||||
<span className="flex-1" />
|
||||
<div className="flex gap-1" role="tablist">
|
||||
{['overview', 'lines'].map(s => (
|
||||
<Button key={s} size="sm" variant={screen === s ? 'primary' : 'secondary'} role="tab" aria-selected={screen === s}
|
||||
onClick={() => setScreen(s)} data-testid={`shift-tab-${s}`}>{t(`overview.shift.tab.${s}`)}</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{screen === 'overview' && (<>
|
||||
<div className={cx('rounded-card border p-4 flex flex-wrap items-center justify-between gap-3', SOFT.success, 'border-success')}>
|
||||
<div className="grid">
|
||||
<span className="text-caption font-semibold uppercase tracking-wide">{t('overview.shift.expected')}</span>
|
||||
<Money value={money.expected} className="text-display font-bold text-ink" data-testid="shift-expected" />
|
||||
</div>
|
||||
<div className="text-label text-right">
|
||||
{t('overview.shift.startCash')} <Money value={money.start} className="font-semibold text-ink" /><br />
|
||||
+ {t('overview.shift.cashSales')} <Money value={money.cash} className="font-semibold text-ink" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<Figure label={t('overview.shift.startCash')} sub={t('overview.shift.startCashHint')}><Money value={money.start} /></Figure>
|
||||
<Figure label={t('overview.shift.cashSales')} sub={t('overview.shift.cashSalesHint')}><Money value={money.cash} /></Figure>
|
||||
<Figure label={t('overview.shift.turnover')} sub={t('overview.shift.turnoverHint')}><Money value={money.total} /></Figure>
|
||||
</div>
|
||||
{money.total > 0 && <SplitBar parts={[
|
||||
{ key: 'cash', tone: 'success', label: t('overview.pay.cash'), value: money.cash },
|
||||
{ key: 'card', tone: 'info', label: t('overview.pay.card'), value: money.card },
|
||||
]} />}
|
||||
{summary && shiftPairs(summary).length > 0 && (
|
||||
<div className="grid gap-2">
|
||||
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t('overview.shift.perHour')}</span>
|
||||
<HourBars buckets={hourBuckets(shiftPairs(summary), hourOf, { from: 24, to: -1 })} height="h-16" />
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-4 gap-3 rounded-card border border-line p-3">
|
||||
<Figure label={t('overview.shift.items')}>{counts.items}</Figure>
|
||||
<Figure label={t('overview.shift.tables')}>{counts.tables}</Figure>
|
||||
<Figure label={t('overview.shift.orders')}>{counts.orders}</Figure>
|
||||
<Figure label={t('overview.shift.pay')} sub={data.hourly_rate_snapshot ? t('overview.shift.perHourRate', { rate: formatMoney(data.hourly_rate_snapshot) }) : null}>
|
||||
{data.shift_pay != null ? <Money value={data.shift_pay} /> : '—'}
|
||||
</Figure>
|
||||
</div>
|
||||
|
||||
{closing && step === 1 && (
|
||||
<Field label={t('overview.shift.notes')} hint={t('overview.shift.notesHint')}>
|
||||
<Textarea rows={2} value={notes} onChange={e => setNotes(e.target.value)} />
|
||||
</Field>
|
||||
)}
|
||||
{closing && step === 2 && (
|
||||
<div className="grid gap-3">
|
||||
<h3 className="text-title font-semibold text-ink">{t('overview.shift.handover')}</h3>
|
||||
<Field label={t('overview.shift.counted')} hint={t('overview.shift.countedHint')}>
|
||||
<Input inputMode="decimal" autoFocus value={counted} onChange={e => setCounted(e.target.value)}
|
||||
placeholder={String(money.expected.toFixed(2))} data-testid="shift-counted" />
|
||||
</Field>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{quickAmounts(money.expected).map(v => (
|
||||
<Button key={v} size="sm" variant="secondary" onClick={() => setCounted(v.toFixed(2))}>
|
||||
{v === money.expected ? <>{t('overview.shift.exact')} <Money value={v} /></> : <Money value={v} />}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
{check && (
|
||||
<div className={cx('rounded-card border p-3 flex items-center justify-between gap-3', SOFT[CHECK_TONE[check.state]])} data-testid="shift-check" data-state={check.state}>
|
||||
<span className="font-semibold">{t(`overview.cash.${check.state}`)}</span>
|
||||
<Money value={check.diff} className="text-title font-bold" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>)}
|
||||
|
||||
{screen === 'lines' && (
|
||||
<div className="grid gap-3">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{['all', ...ITEM_KINDS].map(k => (
|
||||
<Button key={k} size="sm" variant={kind === k ? 'primary' : 'secondary'} onClick={() => setKind(k)}>{t(`overview.shift.kind.${k}`)}</Button>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{['any', 'cash', 'card'].map(p => (
|
||||
<Button key={p} size="sm" variant={payment === p ? 'primary' : 'ghost'} onClick={() => setPayment(p)}>{t(`overview.pay.${p}`)}</Button>
|
||||
))}
|
||||
</div>
|
||||
{isPending && <div className="py-8 flex justify-center"><Spinner /></div>}
|
||||
{summary && summary.orders.length === 0 && <p className="text-label text-ink-3 text-center py-6">{t('overview.shift.noLines')}</p>}
|
||||
{summary?.orders.map(o => <OrderLines key={o.order_id} order={o} waiterId={waiterId} kind={kind} payment={payment} />)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{isPending && screen === 'overview' && <span className="sr-only">{t('overview.loading')}</span>}
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
function OrderLines({ order, waiterId, kind, payment }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatTime } = useFormat()
|
||||
const items = order.items.filter(i => itemShown(i, waiterId, kind, payment))
|
||||
if (items.length === 0) return null
|
||||
const paid = items.filter(i => i.status === 'paid').reduce((s, i) => s + i.subtotal, 0)
|
||||
return (
|
||||
<div className="rounded-card border border-line overflow-hidden">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 px-3 py-2 bg-surface-2 text-label">
|
||||
<span className="font-semibold text-ink">{t('overview.shift.order', { id: order.order_id })}{order.table_name && <span className="font-normal text-ink-3"> · {order.table_name}</span>}</span>
|
||||
<span className="flex items-center gap-3">
|
||||
{order.opener_name && <span className="text-ink-2">{t('overview.shift.openedBy', { name: order.opener_name })}{order.opened_at && ` · ${formatTime(order.opened_at)}`}</span>}
|
||||
{paid > 0 && <Money value={paid} className="font-semibold text-success-ink" />}
|
||||
</span>
|
||||
</div>
|
||||
<ul className="divide-y divide-line">
|
||||
{items.map(item => {
|
||||
const k = itemKind(item, waiterId)
|
||||
const cancelled = item.status === 'cancelled'
|
||||
return (
|
||||
<li key={item.id} className="px-3 py-2 grid gap-1" data-testid="shift-line" data-kind={k}>
|
||||
<div className="flex items-baseline justify-between gap-2">
|
||||
<span className={cx('text-body font-semibold', cancelled ? 'text-danger-ink' : 'text-ink')}>{item.product_name} <span className="font-normal text-ink-3">×{item.quantity}</span></span>
|
||||
<Money value={item.subtotal} className={cx('font-semibold', cancelled && 'line-through text-danger-ink')} />
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-caption text-ink-2">
|
||||
<span>{t('overview.shift.orderedBy', { name: item.added_by_name ?? '—' })}</span>
|
||||
{!cancelled && <span>{t('overview.shift.paidTo', { name: item.paid_by_name ?? '—' })}</span>}
|
||||
{!cancelled && item.payment_method && <Pill tone={item.payment_method === 'card' ? 'info' : 'success'}>{t(`overview.pay.${item.payment_method}`, { defaultValue: item.payment_method })}</Pill>}
|
||||
<Pill tone={KIND_TONE[k]}>{t(`overview.shift.kind.${k}`)}</Pill>
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user