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,168 @@
// Settings → General (plan step 6.14a; was the v1 AppInfoTab): the system (version and whether an
// update is out, license, running or locked, how long it has been up), the local network the
// phones use (the server's address, changed by hand or found by itself; the pairing QR), what the
// venue has set up, exporting / importing the catalogue and the tables, and the support account's
// lock / unlock. The time zone is in "Venue & language" (it was here twice).
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { QRCodeSVG } from 'qrcode.react'
import { Lock, LockOpen, QrCode, RefreshCw } from 'lucide-react'
import { useAccess } from '@xenia/access'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, Input, Spinner } from '@xenia/ui'
import client from '../../../api/client'
import { useLiveQuery } from '../../../live/useLiveQuery'
import { Pill } from '../../overview/parts'
import DataTransfer from './DataTransfer'
import { SettingRow, SettingsCard } from './SettingsCard'
import { lanAddress, uptime, waiterPairUrl } from './settingsLogic'
export default function SystemSettings() {
const { t } = useTranslation('manager')
const fmt = useFormat()
const qc = useQueryClient()
const { user } = useAccess()
const [qr, setQr] = useState(null)
const { data: status, isPending } = useLiveQuery({ queryKey: ['system-status'], queryFn: () => client.get('/api/system/status').then(r => r.data), refetchInterval: 30_000 })
const { data: stats } = useLiveQuery({ queryKey: ['system-stats'], queryFn: () => client.get('/api/system/stats').then(r => r.data), staleTime: 60_000 })
const refresh = useMutation({
mutationFn: () => client.post('/api/system/sync-license').catch(() => null), // the cloud may be away: still refresh what we know
onSettled: () => { qc.invalidateQueries({ queryKey: ['system-status'] }); qc.invalidateQueries({ queryKey: ['license-status'] }) },
})
const lock = useMutation({
mutationFn: on => client.post(on ? '/api/system/lock' : '/api/system/unlock'),
onSuccess: (_r, on) => { toast.success(t(on ? 'settings.system.locked' : 'settings.system.unlocked')); qc.invalidateQueries({ queryKey: ['system-status'] }) },
onError: err => toast.error(errorMessage(err, t)),
})
if (isPending) return <div className="py-8 flex justify-center"><Spinner /></div>
const up = uptime(status?.uptime_seconds)
const state = status?.locked ? ['danger', 'locked'] : status?.lock_pending ? ['warning', 'lockPending'] : ['success', 'running']
const latest = status?.latest_version
const counts = ['categories', 'products', 'tables', 'table_groups', 'managers', 'waiters']
return (
<div className="grid gap-5 max-w-3xl" data-testid="settings-system">
<SettingsCard title={t('settings.system.title')}>
<SettingRow label={t('settings.system.version')}>
<span className="flex flex-wrap items-center gap-2 text-body font-semibold text-ink" data-testid="system-version">
{status?.version ?? '—'}
{latest && latest !== status?.version && <Pill tone="info">{t('settings.system.update', { version: latest })}</Pill>}
{latest && latest === status?.version && <Pill tone="success">{t('settings.system.upToDate')}</Pill>}
</span>
</SettingRow>
<SettingRow label={t('settings.system.license')} hint={status?.expires_at ? t('settings.system.expires', { date: fmt.formatDate(status.expires_at) }) : undefined}>
<Pill tone={status?.licensed ? 'success' : 'danger'}>{t(status?.licensed ? 'settings.system.licensed' : 'settings.system.unlicensed')}</Pill>
</SettingRow>
<SettingRow label={t('settings.system.state')}>
<Pill tone={state[0]}>{t(`settings.system.states.${state[1]}`)}</Pill>
</SettingRow>
<SettingRow label={t('settings.system.uptime')}>
<span className="flex items-center gap-2 text-body text-ink">
{t('settings.system.uptimeValue', { days: up.days, h: up.h, m: up.m })}
<Button size="sm" variant="ghost" icon={<RefreshCw size={14} />} loading={refresh.isPending} onClick={() => refresh.mutate()}>{t('settings.system.refresh')}</Button>
</span>
</SettingRow>
{status?.waiter_domain && (
<SettingRow label={t('settings.system.oldDomain')} hint={t('settings.system.oldDomainHint')}>
<span className="flex items-center gap-2 text-label font-mono break-all">{status.waiter_domain}
<Button size="sm" variant="secondary" icon={<QrCode size={14} />} onClick={() => setQr({ url: status.waiter_domain })}>{t('settings.system.qr')}</Button>
</span>
</SettingRow>
)}
</SettingsCard>
<LanAccess status={status} onQr={setQr} />
<SettingsCard title={t('settings.system.setUp')} testId="system-stats">
<div className="grid grid-cols-2 sm:grid-cols-3 gap-3 p-5">
{counts.map(k => (
<div key={k} className="rounded-card bg-surface-2 p-3 grid">
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t(`settings.system.counts.${k}`)}</span>
<span className="text-title font-semibold tabular-nums text-ink">{stats?.[k] ?? '—'}</span>
</div>
))}
</div>
</SettingsCard>
<DataTransfer />
{user?.role === 'superadmin' && (
<SettingsCard title={t('settings.system.support')} description={t('settings.system.supportHint')}>
<div className="flex gap-2 p-5">
<Button variant="secondary" icon={<LockOpen size={15} />} loading={lock.isPending && lock.variables === false} onClick={() => lock.mutate(false)}>{t('settings.system.unlock')}</Button>
<Button variant="danger" icon={<Lock size={15} />} loading={lock.isPending && lock.variables === true} onClick={() => lock.mutate(true)}>{t('settings.system.lock')}</Button>
</div>
</SettingsCard>
)}
{qr && (
<Dialog open size="sm" onClose={() => setQr(null)} title={t('settings.system.qrTitle')} description={qr.caption}
footer={<Button variant="secondary" onClick={() => setQr(null)}>{t('settings.back')}</Button>}>
<div className="grid justify-items-center gap-3" data-testid="system-qr">
<div className="p-3 rounded-card bg-surface border border-line"><QRCodeSVG value={qr.url} size={220} /></div>
<p className="text-caption font-mono text-ink-2 break-all text-center">{qr.url}</p>
</div>
</Dialog>
)}
</div>
)
}
/** The server's address on the venue's Wi-Fi: what the phones and the QR use (services/lan_ip.py). */
function LanAccess({ status, onQr }) {
const { t } = useTranslation('manager')
const qc = useQueryClient()
const info = status?.lan_ip_info
const { ip, source } = lanAddress(status, window.location.hostname)
const [editing, setEditing] = useState(null) // the typed address while editing
const save = useMutation({
mutationFn: value => client.put('/api/system/lan-ip-override', { ip: value }).then(r => r.data),
onSuccess: (_r, value) => { toast.success(t(value ? 'settings.lan.saved' : 'settings.lan.automatic')); setEditing(null); qc.invalidateQueries({ queryKey: ['system-status'] }) },
onError: err => toast.error(errorMessage(err, t)),
})
return (
<SettingsCard title={t('settings.lan.title')} description={t('settings.lan.intro')} testId="settings-lan">
{info?.mismatch && (
<div className="m-5 mb-0 rounded-card bg-warning-soft text-warning-ink p-3 text-label grid gap-2" role="alert">
<span>{t('settings.lan.mismatch', { ip, detected: info.detected })}</span>
<Button size="sm" variant="secondary" className="justify-self-start" loading={save.isPending} onClick={() => save.mutate(null)}>
{t('settings.lan.useDetected', { ip: info.detected })}
</Button>
</div>
)}
<SettingRow label={t('settings.lan.address')} hint={!ip ? t('settings.lan.unknown') : info && info.detection !== 'ok' && editing == null ? t(`settings.lan.detection.${info.detection}`, { defaultValue: '' }) : undefined}>
{editing != null ? (
<span className="grid gap-2">
<Input value={editing} autoFocus className="font-mono" placeholder={info?.detected || '192.168.1.50'} onChange={e => setEditing(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && editing.trim()) save.mutate(editing.trim()); if (e.key === 'Escape') setEditing(null) }} data-testid="lan-ip" />
<span className="flex flex-wrap gap-1">
<Button size="sm" loading={save.isPending} disabled={!editing.trim()} onClick={() => save.mutate(editing.trim())}>{t('settings.save')}</Button>
{info?.override && <Button size="sm" variant="secondary" onClick={() => save.mutate(null)}>{t('settings.lan.auto')}</Button>}
<Button size="sm" variant="ghost" onClick={() => setEditing(null)}>{t('settings.back')}</Button>
</span>
</span>
) : (
<span className="flex flex-wrap items-center gap-2">
<span className="font-mono text-body text-ink">{ip ?? '—'}</span>
{source && <Pill>{t(`settings.lan.source.${source}`)}</Pill>}
<Button size="sm" variant="secondary" onClick={() => setEditing(info?.override || ip || '')} data-testid="lan-change">{t('settings.lan.change')}</Button>
</span>
)}
</SettingRow>
{ip && (<>
<SettingRow label={t('settings.lan.waiters')} hint={t('settings.lan.waitersHint')}>
<span className="flex flex-wrap items-center gap-2">
<span className="font-mono text-label text-ink break-all">http://{ip}</span>
<Button size="sm" variant="secondary" icon={<QrCode size={14} />} data-testid="lan-qr"
onClick={() => onQr({ url: waiterPairUrl(ip, status?.site_id, status?.tls?.spki_sha256), caption: t('settings.lan.qrCaption') })}>{t('settings.system.qr')}</Button>
</span>
</SettingRow>
<SettingRow label={t('settings.lan.manager')}>
<span className="font-mono text-label text-ink break-all">http://{ip}/manager</span>
</SettingRow>
</>)}
</SettingsCard>
)
}