// 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 { Lock, LockOpen, QrCode as QrIcon, RefreshCw } from 'lucide-react' import { useAccess } from '@xenia/access' import { errorMessage } from '@xenia/api' import { useFormat, useTranslation } from '@xenia/i18n' import { Button, Columns, Dialog, Input, Spinner } from '@xenia/ui' import { QrCode } from '@xenia/ui/qr' 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
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 ( {status?.version ?? '—'} {latest && latest !== status?.version && {t('settings.system.update', { version: latest })}} {latest && latest === status?.version && {t('settings.system.upToDate')}} {t(status?.licensed ? 'settings.system.licensed' : 'settings.system.unlicensed')} {t(`settings.system.states.${state[1]}`)} {t('settings.system.uptimeValue', { days: up.days, h: up.h, m: up.m })} {status?.waiter_domain && ( {status.waiter_domain} )}
{counts.map(k => (
{t(`settings.system.counts.${k}`)} {stats?.[k] ?? '—'}
))}
{user?.role === 'superadmin' && (
)} {qr && ( setQr(null)} title={t('settings.system.qrTitle')} description={qr.caption} footer={}>

{qr.url}

)}
) } /** 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 ( {info?.mismatch && (
{t('settings.lan.mismatch', { ip, detected: info.detected })}
)} {editing != null ? ( 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" /> {info?.override && } ) : ( {ip ?? '—'} {source && {t(`settings.lan.source.${source}`)}} )} {ip && (<> http://{ip} http://{ip}/manager )}
) }