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,87 @@
|
||||
// The waiters on shift now (plan step 6.2): since when, what they took in, a break in progress;
|
||||
// message one of them, look at their shift, or end it. "Start" puts a waiter without a shift
|
||||
// on one (with the cash they start with) while the day is open.
|
||||
import { useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { BarChart3, Coffee, MessageSquare, Plus } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, cx } from '@xenia/ui'
|
||||
import { Avatar, Card, Money, Pill } from './parts'
|
||||
import { useDuration } from './hooks'
|
||||
|
||||
export default function ShiftsCard({ shifts, idle, dayOpen, hidden, onStart, onEnd, onStats, onMessage, canMessage }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatTime } = useFormat()
|
||||
const since = useDuration()
|
||||
const [starting, setStarting] = useState(false)
|
||||
|
||||
return (
|
||||
<Card title={t('overview.shifts.title')} testId="shifts-card"
|
||||
action={dayOpen && idle.length > 0 && <Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={() => setStarting(true)} data-testid="shift-start">{t('overview.shifts.start')}</Button>}>
|
||||
<div className="p-3 grid gap-2">
|
||||
{shifts.length === 0 ? <EmptyState compact title={t('overview.shifts.none')} /> : shifts.map(s => {
|
||||
const onBreak = Array.isArray(s.breaks) ? s.breaks.find(b => !b.ended_at) : null
|
||||
return (
|
||||
<div key={s.id} className={cx('flex items-center gap-3 p-2.5 rounded-card border', onBreak ? 'border-warning bg-warning-soft' : 'border-line bg-surface-2')} data-testid="shift-row">
|
||||
<Avatar name={s.waiter_name} url={s.avatar_url} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-body font-semibold text-ink">{s.waiter_name}</span>
|
||||
{onBreak && <Pill tone="warning"><Coffee size={12} aria-hidden="true" />{t('overview.shifts.onBreak', { since: since(onBreak.started_at) })}</Pill>}
|
||||
</div>
|
||||
<div className="text-caption text-ink-2">
|
||||
{t('overview.shifts.since', { time: formatTime(s.started_at), length: since(s.started_at) })}
|
||||
{s.total_collected > 0 && <> · <Money value={s.total_collected} hidden={hidden} className="font-semibold text-success-ink" /></>}
|
||||
</div>
|
||||
</div>
|
||||
{canMessage && <IconButton size="sm" variant="secondary" label={t('overview.shifts.message')} onClick={() => onMessage(s)}><MessageSquare size={16} /></IconButton>}
|
||||
<IconButton size="sm" variant="secondary" label={t('overview.shifts.stats')} onClick={() => onStats(s)} data-testid="shift-stats"><BarChart3 size={16} /></IconButton>
|
||||
<Button size="sm" variant="danger" onClick={() => onEnd(s)} data-testid="shift-end">{t('overview.shifts.end')}</Button>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{starting && <StartShiftDialog waiters={idle} onClose={() => setStarting(false)} onStart={onStart} />}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
function StartShiftDialog({ waiters, onClose, onStart }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [waiterId, setWaiterId] = useState('')
|
||||
const [cash, setCash] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
async function submit() {
|
||||
if (!waiterId) { setError(t('overview.shifts.pickWaiter')); return }
|
||||
const amount = cash.trim() === '' ? null : parseNumber(cash)
|
||||
if (amount != null && !Number.isFinite(amount)) { setError(t('overview.shifts.badAmount')); return }
|
||||
setBusy(true)
|
||||
try {
|
||||
await onStart(Number(waiterId), amount)
|
||||
onClose()
|
||||
} catch (err) {
|
||||
toast.error(errorMessage(err, t))
|
||||
} finally { setBusy(false) }
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open size="sm" onClose={onClose} title={t('overview.shifts.startTitle')}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||
<Button onClick={submit} loading={busy} data-testid="shift-start-confirm">{t('overview.shifts.startNow')}</Button>
|
||||
</>}>
|
||||
<div className="grid gap-3">
|
||||
<Field label={t('overview.shifts.waiter')} error={error && !waiterId ? error : undefined}>
|
||||
<Select value={waiterId} onChange={e => { setWaiterId(e.target.value); setError(null) }} placeholder={t('overview.shifts.pick')}
|
||||
options={waiters.map(w => ({ value: String(w.id), label: w.full_name || w.username }))} data-testid="shift-start-waiter" />
|
||||
</Field>
|
||||
<Field label={t('overview.shifts.startCash')} hint={t('overview.shifts.startCashHint')} error={error && waiterId ? error : undefined}>
|
||||
<Input inputMode="decimal" value={cash} onChange={e => { setCash(e.target.value); setError(null) }} placeholder="0" />
|
||||
</Field>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user