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>
140 lines
8.1 KiB
React
140 lines
8.1 KiB
React
// Settings → Operation (plan step 6.14a; was the v1 OperationTab): what each role may do, what the
|
|
// waiters do by themselves (start / end their shift, see their takings), card payments, how tables
|
|
// and orders behave (closing, the kitchen screens' serve step, courses, quick notes for lines),
|
|
// table flags, quick messages to the staff, and sending the digital menu to the cloud now.
|
|
// Each part shows only with its app on. Dropped from v1: "automatic store schedule" (its switches
|
|
// were kept in the browser only and nothing ever read them).
|
|
import { useState } from 'react'
|
|
import { useMutation } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
import { ArrowDown, ArrowUp, Plus, RefreshCw, Trash2 } from 'lucide-react'
|
|
import { useModule } from '@xenia/access'
|
|
import { errorMessage } from '@xenia/api'
|
|
import { useTranslation } from '@xenia/i18n'
|
|
import { Button, IconButton, Input, Spinner, Switch } from '@xenia/ui'
|
|
import client from '../../../api/client'
|
|
import QuickMessages from './QuickMessages'
|
|
import RolePermissions from './RolePermissions'
|
|
import { SettingRow, SettingsCard } from './SettingsCard'
|
|
import TableFlags from './TableFlags'
|
|
import { addCourse, cleanNotes, move, nextColour, readJson } from './settingsLogic'
|
|
import { useSettings } from './useSettings'
|
|
import { COURSE_COLOURS } from './venueColours'
|
|
|
|
export default function OperationSettings() {
|
|
const ordering = useModule('ordering')
|
|
const chat = useModule('chat')
|
|
const qrMenu = useModule('connect_menu')
|
|
return (
|
|
<div className="grid gap-5" data-testid="settings-operation">
|
|
<RolePermissions />
|
|
{ordering && <OrderingSettings />}
|
|
{ordering && <TableFlags />}
|
|
{chat && <QuickMessages />}
|
|
{qrMenu && <MenuSync />}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function Toggle({ s, k, fallback = 'false', label, hint }) {
|
|
return (
|
|
<SettingRow label={label} hint={hint}>
|
|
<Switch checked={s.get(k, fallback) === 'true'} disabled={s.saving} onChange={v => s.save(k, v)} aria-label={label} data-testid={`setting-${k}`} />
|
|
</SettingRow>
|
|
)
|
|
}
|
|
|
|
function OrderingSettings() {
|
|
const { t } = useTranslation('manager')
|
|
const s = useSettings()
|
|
if (s.loading) return <div className="py-6 flex justify-center"><Spinner /></div>
|
|
const o = k => t(`settings.ops.${k}`)
|
|
return (<>
|
|
<SettingsCard title={o('staffTitle')} description={o('staffIntro')} testId="settings-staff">
|
|
<Toggle s={s} k="shifts.waiter_self_start" fallback="true" label={o('selfStart')} hint={o('selfStartHint')} />
|
|
<Toggle s={s} k="shifts.waiter_self_end" fallback="true" label={o('selfEnd')} hint={o('selfEndHint')} />
|
|
<Toggle s={s} k="shifts.hide_revenue_from_waiters" label={o('hideTakings')} hint={o('hideTakingsHint')} />
|
|
</SettingsCard>
|
|
<SettingsCard title={o('paymentsTitle')} testId="settings-payments">
|
|
<Toggle s={s} k="payments.card_enabled" label={o('card')} hint={o('cardHint')} />
|
|
</SettingsCard>
|
|
<SettingsCard title={o('ordersTitle')} description={o('ordersIntro')} testId="settings-orders">
|
|
<Toggle s={s} k="orders.auto_close_on_full_payment" label={o('autoClose')} hint={o('autoCloseHint')} />
|
|
<Toggle s={s} k="orders.close_with_unpaid" label={t('settings.operation.closeUnpaid')} hint={t('settings.operation.closeUnpaidHint')} />
|
|
<Toggle s={s} k="orders.bypass_kds_serve" label={o('bypassKds')} hint={o('bypassKdsHint')} />
|
|
<Toggle s={s} k="orders.courses_enabled" label={o('courses')} hint={o('coursesHint')} />
|
|
{s.get('orders.courses_enabled') === 'true' && <Courses s={s} />}
|
|
<QuickNotes s={s} />
|
|
</SettingsCard>
|
|
</>)
|
|
}
|
|
|
|
/** orders.courses: [{ id, name, color }] in the order they are served. */
|
|
function Courses({ s }) {
|
|
const { t } = useTranslation('manager')
|
|
const saved = readJson(s.get('orders.courses', '[]'), [])
|
|
const [names, setNames] = useState({}) // typed names not saved yet, by id
|
|
const save = next => s.save('orders.courses', JSON.stringify(next))
|
|
return (
|
|
<div className="px-5 py-3 grid gap-2" data-testid="settings-courses">
|
|
{saved.map((c, i) => (
|
|
<div key={c.id} className="flex items-center gap-2" data-testid="course-row">
|
|
<button type="button" className="w-6 h-6 rounded-full shrink-0 border border-line" style={{ background: c.color }}
|
|
title={t('settings.ops.courseColour')} aria-label={t('settings.ops.courseColour')} onClick={() => save(saved.map(x => (x.id === c.id ? { ...x, color: nextColour(COURSE_COLOURS, x.color) } : x)))} />
|
|
<Input value={names[c.id] ?? c.name} aria-label={t('settings.ops.courseName')} onChange={e => setNames(n => ({ ...n, [c.id]: e.target.value }))}
|
|
onBlur={() => { const v = (names[c.id] ?? c.name).trim(); if (v && v !== c.name) save(saved.map(x => (x.id === c.id ? { ...x, name: v } : x))); setNames(n => { const { [c.id]: _, ...rest } = n; return rest }) }} />
|
|
<IconButton size="sm" variant="ghost" label={t('settings.ops.up')} disabled={i === 0} onClick={() => save(move(saved, i, i - 1))}><ArrowUp size={14} /></IconButton>
|
|
<IconButton size="sm" variant="ghost" label={t('settings.ops.down')} disabled={i === saved.length - 1} onClick={() => save(move(saved, i, i + 1))}><ArrowDown size={14} /></IconButton>
|
|
<IconButton size="sm" variant="ghost" label={t('settings.ops.remove', { name: c.name })} onClick={() => save(saved.filter(x => x.id !== c.id))}><Trash2 size={14} /></IconButton>
|
|
</div>
|
|
))}
|
|
<Button size="sm" variant="secondary" icon={<Plus size={14} />} className="justify-self-start" data-testid="course-add"
|
|
onClick={() => save(addCourse(saved, COURSE_COLOURS, id => t('settings.ops.courseN', { n: id })))}>{t('settings.ops.addCourse')}</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/** orders.quick_notes: the notes a waiter can add to a line with one tap. */
|
|
function QuickNotes({ s }) {
|
|
const { t } = useTranslation('manager')
|
|
const notes = readJson(s.get('orders.quick_notes', '[]'), [])
|
|
const [typed, setTyped] = useState('')
|
|
const [edits, setEdits] = useState({})
|
|
const save = next => s.save('orders.quick_notes', JSON.stringify(cleanNotes(next)))
|
|
const add = () => { if (typed.trim()) { save([...notes, typed]); setTyped('') } }
|
|
return (
|
|
<div className="px-5 py-3 grid gap-2" data-testid="settings-quick-notes">
|
|
<span className="text-body font-medium text-ink">{t('settings.ops.quickNotes')}</span>
|
|
<span className="text-label text-ink-2 -mt-1">{t('settings.ops.quickNotesHint')}</span>
|
|
{notes.map((n, i) => (
|
|
<div key={`${i}-${n}`} className="flex items-center gap-2">
|
|
<Input value={edits[i] ?? n} aria-label={t('settings.ops.quickNote')} onChange={e => setEdits(x => ({ ...x, [i]: e.target.value }))}
|
|
onBlur={() => { if (edits[i] != null && edits[i] !== n) save(notes.map((x, j) => (j === i ? edits[i] : x))); setEdits({}) }} />
|
|
<IconButton size="sm" variant="ghost" label={t('settings.ops.remove', { name: n })} onClick={() => save(notes.filter((_, j) => j !== i))}><Trash2 size={14} /></IconButton>
|
|
</div>
|
|
))}
|
|
<div className="flex items-center gap-2">
|
|
<Input value={typed} placeholder={t('settings.ops.newQuickNote')} aria-label={t('settings.ops.newQuickNote')} onChange={e => setTyped(e.target.value)}
|
|
onKeyDown={e => { if (e.key === 'Enter') add() }} data-testid="quick-note-new" />
|
|
<Button size="sm" variant="secondary" icon={<Plus size={14} />} disabled={!typed.trim()} onClick={add} data-testid="quick-note-add">{t('settings.ops.add')}</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function MenuSync() {
|
|
const { t } = useTranslation('manager')
|
|
const sync = useMutation({
|
|
mutationFn: () => client.post('/api/system/sync-menu'),
|
|
onSuccess: () => toast.success(t('settings.ops.synced')),
|
|
onError: err => toast.error(errorMessage(err, t)),
|
|
})
|
|
return (
|
|
<SettingsCard title={t('settings.ops.menuTitle')} description={t('settings.ops.menuIntro')}>
|
|
<SettingRow label={t('settings.ops.syncNow')} hint={t('settings.ops.syncNowHint')}>
|
|
<Button size="sm" variant="secondary" icon={<RefreshCw size={14} />} loading={sync.isPending} onClick={() => sync.mutate()}>{t('settings.ops.sync')}</Button>
|
|
</SettingRow>
|
|
</SettingsCard>
|
|
)
|
|
}
|