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>
112 lines
6.0 KiB
React
112 lines
6.0 KiB
React
// 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-card py-3" 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>
|
|
)
|
|
}
|