Files
xenia-pos-local/manager_dashboard/src/pages/overview/DaySummaryDialog.jsx
T
bonaminandClaude Opus 5.5 6f4ab23582 feat(manager): design pass 1 — every page on <Page>, shared toolbars, fees under Online orders, QR codes under Tables, day stats reworked
From the owner's page-by-page review (2026-11-20):
- every page root is <Page> (scrolls, fills 1080p, 16:9 centred on
  ultrawides); not yet: products, management/tables, stock (next pass)
- /dashboard: more padding in cards (p-card), quieter secondary text,
  11px uppercase labels everywhere (text-overline)
- day stats: xl dialog, "● Day running · Opened …" as text, the six
  figures in equal boxes, "On tabs" in the payments bar, shared Tabs
- /tables: Segmented List / Map / QR codes (?view=; /online/qr redirects),
  filter chips + zones multi-select at one height, the card itself opens
  the table (button removed), cards ~20% wider
- /online-orders: shared Tabs with Settings (= the old /online/fees page,
  which redirects to ?tab=settings); orders fill the width
- contacts, customers, expenses: PageHeader + Toolbar + SearchInput +
  multi-select Dropdowns (kinds; statuses, categories); table cells
  vertically centred; the Spent tip opens on hover
- filterCards / filterContacts / filterExpenses take several values
  (unit tests added)
- docs/DESIGN.md: the design language (CS-20 in the pack README)
- tests/e2e/manager_layout.mjs: the page rule at 1920x1080 and 3440x1440;
  manager.mjs and manager_look.mjs follow the moved pages

Verified: manager build + lint (0 errors), unit tests (manager 99, ui 24,
i18n 31, api 25, access 8), i18n guard, manager_layout.mjs all passed,
manager.mjs 228 checks all passed. Not checked: the waiter app and the
terminal by eye (they only get the muted ink-2 token).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 11:23:30 +02:00

85 lines
4.6 KiB
React

// 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, Tabs } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { CashTab, ChecksTab, MoneyTab, PrintersTab, StaffTab, ZonesTab } from './DaySummaryTabs'
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'), testId: 'day-tab-money' },
{ id: 'staff', label: t('overview.day.tab.staff'), badge: data?.waiters?.length, testId: 'day-tab-staff' },
{ id: 'zones', label: t('overview.day.tab.zones'), badge: data?.zones?.length, testId: 'day-tab-zones' },
{ id: 'printers', label: t('overview.day.tab.printers'), badge: data?.printers?.length, testId: 'day-tab-printers' },
...(closing ? [
{ id: 'cash', label: t('overview.day.tab.cash'), testId: '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, testId: 'day-tab-checks' },
] : []),
]
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="xl" onClose={onClose} footer={footer || undefined}
title={closing ? t('overview.day.closeTitle') : t('overview.day.statsTitle')}
description={data && <span className="inline-flex flex-wrap items-center gap-x-1.5 text-label" data-testid="day-status">
{data.status === 'open'
? <span className="inline-flex items-center gap-1.5 font-semibold text-success-ink"><span className="w-2 h-2 rounded-full bg-success" aria-hidden="true" />{t('overview.day.open')}</span>
: <span>{t('overview.day.closedState')}</span>}
<span aria-hidden="true">·</span>
<span>{t('overview.day.openedAt', { time: formatDateTime(data.opened_at, 'datetimeShort') })}</span>
</span>}>
<div className="grid gap-4" data-testid="day-summary">
<Tabs tabs={tabs} value={tab} onChange={setTab} />
{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>
)
}