feat(manager): every settings tab on v2 (platform-v2 step 6.14a)

- Settings: tabs in the address (?tab=), Fiscal only with the fiscal app, Appearance only with the waiter app
- General: version / update / license / state / uptime, the local network (address by hand or found, the pairing QR),
  what is set up, export / import of the catalogue and the tables (a wrong file refused, two confirmations), support lock
- Sign-in & security: idle lock / sign-out (seconds..hours, warning when sign-out comes first), recovery codes
- Operation: role permissions, waiters' own shifts and takings, card payments, tables and orders, courses (add, rename,
  colour, order), quick notes, table flags (emoji, colour, white/black text, on/off), quick messages, send the QR menu now
- Appearance: the waiter app's table-card colours per state, light and dark, flash, colour picker with opacity, reset
- Fiscal: on/off, driver, folders with a reachability check, clerk / card terminal numbers, receipt end lines, VAT groups
- Development: pretend printing
- dropped: the v1 'automatic store schedule' switches (kept in the browser only, nothing read them) and the second time-zone card
- backend: JSON settings must be JSON (validation.setting_value); fiscal folders are plain paths (were typed json)
- venue colour data in sections/venueColours.js (guard DATA); store/tableColourStore and Settings/tabs deleted
- tests: settings.test.mjs (5), test_settings_json.py, e2e manager.mjs 'settings v2' (12 checks)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 19:41:14 +02:00
co-authored by Claude Opus 5.5
parent bde125bf09
commit f6fcfb7736
27 changed files with 1935 additions and 2819 deletions
@@ -0,0 +1,139 @@
// 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 max-w-3xl" 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>
)
}