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,91 @@
|
||||
// The day summary (plan step 6.2), opened from the overview as "Day stats" (to look) or "Close
|
||||
// the day" (adds the cash count and the checks). Closing: count the drawer (optional), then
|
||||
// the checks: tables still open (with unpaid lines or not) and shifts still running. With open
|
||||
// tables the close is forced: they are closed, unpaid amounts are lost, running shifts end.
|
||||
import { useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Spinner, cx } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||
import { CashTab, ChecksTab, MoneyTab, PrintersTab, StaffTab, ZonesTab } from './DaySummaryTabs'
|
||||
import { Pill } from './parts'
|
||||
|
||||
export default function DaySummaryDialog({ dayId, closing = false, onClose, onClosed }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatDateTime } = useFormat()
|
||||
const [tab, setTab] = useState('money')
|
||||
const [counted, setCounted] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const { data, isPending, error } = useLiveQuery({
|
||||
queryKey: ['day-summary', dayId ?? 'current'],
|
||||
queryFn: () => client.get('/api/business-day/summary', { params: dayId ? { day_id: dayId } : {} }).then(r => r.data),
|
||||
events: closing ? ['order_updated', 'order_paid', 'order_closed'] : [],
|
||||
refetchInterval: closing ? 15_000 : false,
|
||||
})
|
||||
const countedValue = counted.trim() === '' ? null : parseNumber(counted)
|
||||
|
||||
async function closeDay() {
|
||||
setBusy(true)
|
||||
try {
|
||||
const body = { force: data.checks.open_orders > 0 }
|
||||
if (countedValue != null && Number.isFinite(countedValue)) body.store_closing_cash = countedValue
|
||||
await client.post('/api/business-day/close', body)
|
||||
onClosed?.()
|
||||
} catch (err) {
|
||||
if (err.xenia?.code === 'business_day.orders_open') setTab('checks')
|
||||
toast.error(errorMessage(err, t))
|
||||
} finally { setBusy(false) }
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
{ id: 'money', label: t('overview.day.tab.money') },
|
||||
{ id: 'staff', label: t('overview.day.tab.staff'), badge: data?.waiters?.length },
|
||||
{ id: 'zones', label: t('overview.day.tab.zones'), badge: data?.zones?.length },
|
||||
{ id: 'printers', label: t('overview.day.tab.printers'), badge: data?.printers?.length },
|
||||
...(closing ? [
|
||||
{ id: 'cash', label: t('overview.day.tab.cash') },
|
||||
{ id: 'checks', label: t('overview.day.tab.checks'), badge: data?.checks ? data.checks.open_orders + data.checks.active_shifts : null, warn: data?.checks?.with_unpaid_items > 0 },
|
||||
] : []),
|
||||
]
|
||||
|
||||
const footer = closing && data && tab !== 'checks' && (<>
|
||||
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||
{tab !== 'cash'
|
||||
? <Button onClick={() => setTab('cash')} data-testid="day-to-cash">{t('overview.day.toCash')}</Button>
|
||||
: <Button onClick={() => setTab('checks')} data-testid="day-to-checks">{t('overview.day.toChecks')}</Button>}
|
||||
</>)
|
||||
|
||||
return (
|
||||
<Dialog open size="lg" onClose={onClose} footer={footer || undefined}
|
||||
title={closing ? t('overview.day.closeTitle') : t('overview.day.statsTitle')}
|
||||
description={data && <span className="inline-flex items-center gap-2">
|
||||
<Pill tone={data.status === 'open' ? 'success' : 'neutral'}>{data.status === 'open' ? t('overview.day.open') : t('overview.day.closedState')}</Pill>
|
||||
{t('overview.day.openedAt', { time: formatDateTime(data.opened_at, 'datetimeShort') })}
|
||||
</span>}>
|
||||
<div className="grid gap-4" data-testid="day-summary">
|
||||
<div className="flex gap-1 overflow-x-auto border-b border-line -mx-1 px-1" role="tablist">
|
||||
{tabs.map(tb => (
|
||||
<button key={tb.id} type="button" role="tab" aria-selected={tab === tb.id} onClick={() => setTab(tb.id)} data-testid={`day-tab-${tb.id}`}
|
||||
className={cx('flex items-center gap-1.5 px-3 py-2 -mb-px border-b-2 text-label whitespace-nowrap transition-colors duration-fast',
|
||||
tab === tb.id ? 'border-accent text-ink font-semibold' : 'border-transparent text-ink-2 hover:text-ink')}>
|
||||
{tb.label}
|
||||
{tb.badge != null && <span className={cx('min-w-5 px-1 rounded-full text-caption font-bold tabular-nums', tb.warn ? 'bg-danger-soft text-danger-ink' : 'bg-surface-2 text-ink-2')}>{tb.badge}</span>}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{isPending && <div className="py-10 flex justify-center"><Spinner /></div>}
|
||||
{error && <EmptyState compact title={errorMessage(error, t)} />}
|
||||
{data && (<>
|
||||
{tab === 'money' && <MoneyTab data={data} />}
|
||||
{tab === 'staff' && <StaffTab data={data} />}
|
||||
{tab === 'zones' && <ZonesTab data={data} />}
|
||||
{tab === 'printers' && <PrintersTab data={data} />}
|
||||
{tab === 'cash' && <CashTab data={data} counted={counted} onCounted={setCounted} value={countedValue} />}
|
||||
{tab === 'checks' && <ChecksTab data={data} open={data.status === 'open'} closing={busy} onClose={closeDay} />}
|
||||
</>)}
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user