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:
2026-11-18 09:01:51 +02:00
co-authored by Claude Opus 5.5
parent 2dc5da446e
commit 8a02173450
32 changed files with 3161 additions and 4126 deletions
@@ -0,0 +1,111 @@
// Messages to the staff's phones (plan step 6.2): the latest ones with who they went to and how
// many have read them; "New" writes one to everyone or to chosen waiters, optionally about some
// tables, from a quick template or typed. The shift list's message button opens the same
// dialog with that waiter chosen.
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { MessageSquare, Plus, Send } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Field, Textarea } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { messageAcks, messageTargets, tableName } from './overviewLogic'
import { Card, Pill } from './parts'
const useTemplates = () => useLiveQuery({
queryKey: ['quick-templates'], queryFn: () => client.get('/api/notifications/templates').then(r => r.data), staleTime: 60_000,
})
export default function MessagesCard({ staff, tables }) {
const { t } = useTranslation('manager')
const { formatTime } = useFormat()
const [composing, setComposing] = useState(false)
const { data: messages = [] } = useLiveQuery({
queryKey: ['messages-all'],
queryFn: () => client.get('/api/notifications/all', { params: { limit: 20 } }).then(r => r.data),
events: ['message_sent'],
refetchInterval: 30_000, // reads (acks) send no event
})
return (
<Card title={t('overview.messages.title')} testId="messages-card"
action={<Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={() => setComposing(true)} data-testid="message-new">{t('overview.messages.new')}</Button>}>
{messages.length === 0 ? <EmptyState compact icon={<MessageSquare size={24} />} title={t('overview.messages.none')} /> : (
<ul className="max-h-80 overflow-y-auto divide-y divide-line">
{messages.map(m => {
const to = messageTargets(m, staff)
const acks = messageAcks(m, staff.length)
return (
<li key={m.id} className="flex items-start gap-3 px-4 py-2.5" data-testid="message-row">
<span className="flex-1 min-w-0 grid">
<span className="text-body font-semibold text-ink">{m.body}</span>
<span className="text-caption text-ink-3">{t('overview.messages.to', { who: to ? to.join(', ') : t('overview.messages.everyone'), time: formatTime(m.created_at) })}</span>
</span>
<Pill tone={acks.all ? 'success' : 'warning'} title={t('overview.messages.readBy')}>{t('overview.messages.read', { read: acks.read, of: acks.of })}</Pill>
</li>
)
})}
</ul>
)}
{composing && <ComposeDialog staff={staff} tables={tables} onClose={() => setComposing(false)} />}
</Card>
)
}
/** Write a message; `to` preselects one waiter ({ id, name }) and hides the pickers. */
export function ComposeDialog({ staff = [], tables = [], to, onClose }) {
const { t } = useTranslation('manager')
const qc = useQueryClient()
const { data: templates = [] } = useTemplates()
const [waiters, setWaiters] = useState(to ? [to.id] : []) // [] = everyone
const [tableIds, setTableIds] = useState([])
const [body, setBody] = useState('')
const send = useMutation({
mutationFn: payload => client.post('/api/notifications/send', payload),
onSuccess: () => { toast.success(t('overview.messages.sent')); qc.invalidateQueries({ queryKey: ['messages-all'] }); onClose() },
onError: err => toast.error(errorMessage(err, t)),
})
const toggle = (list, set, id) => set(list.includes(id) ? list.filter(x => x !== id) : [...list, id])
const chip = on => (on ? 'primary' : 'secondary')
return (
<Dialog open onClose={onClose} title={to ? t('overview.messages.toOne', { name: to.name }) : t('overview.messages.newTitle')}
footer={<>
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
<Button icon={<Send size={16} />} disabled={!body.trim()} loading={send.isPending} data-testid="message-send"
onClick={() => send.mutate({ body: body.trim(), target_waiter_ids: waiters, table_ids: tableIds })}>{t('overview.messages.send')}</Button>
</>}>
<div className="grid gap-4">
{!to && (
<div className="grid gap-2">
<span className="text-label font-semibold text-ink-2">{t('overview.messages.recipients')} {waiters.length === 0 && <span className="text-accent-ink">{t('overview.messages.allOfThem')}</span>}</span>
<div className="flex flex-wrap gap-1.5">
{staff.map(w => <Button key={w.id} size="sm" variant={chip(waiters.includes(w.id))} onClick={() => toggle(waiters, setWaiters, w.id)}>{w.nickname || w.full_name || w.username}</Button>)}
</div>
</div>
)}
{!to && tables.length > 0 && (
<div className="grid gap-2">
<span className="text-label font-semibold text-ink-2">{t('overview.messages.tables')}</span>
<div className="flex flex-wrap gap-1.5 max-h-24 overflow-y-auto">
{tables.map(tb => <Button key={tb.id} size="sm" variant={chip(tableIds.includes(tb.id))} onClick={() => toggle(tableIds, setTableIds, tb.id)}>{tableName(tb)}</Button>)}
</div>
</div>
)}
{templates.length > 0 && (
<div className="grid gap-2">
<span className="text-label font-semibold text-ink-2">{t('overview.messages.quick')}</span>
<div className="flex flex-wrap gap-1.5">
{templates.map(tp => <Button key={tp.id} size="sm" variant={chip(body === tp.body)} onClick={() => setBody(tp.body)}>{tp.body}</Button>)}
</div>
</div>
)}
<Field label={t('overview.messages.text')}>
<Textarea rows={3} value={body} onChange={e => setBody(e.target.value)} data-testid="message-body" />
</Field>
</div>
</Dialog>
)
}