feat(manager): notification bell, sign-in/venue/print settings, log download (platform-v2 2.6f)

- Bell in the header: /api/platform/notifications with unread count, live via
  the new LiveProvider (one createLiveClient connection) on platform_notification
  and reconnect; mark read / all; warning+critical pop a toast.
- Settings: Sign-in card (manager/waiter/device modes, require username, one
  session per manager/waiter, username autofill) replaces the dead v1
  security.login_method card; new "Venue & language" tab (language, time zone);
  print alert threshold in Printing. Tab labels are i18n keys.
- Technical > Log files: list + download of the daily logs (owner-level).
  Backend: GET /api/system/logs, /api/system/logs/{date} (core.settings.manage),
  error system.log_not_found.
- Setup wizard asks staff language and time zone (setup/init stores them).
- @xenia/ui theme helpers (applyTheme, getStoredTheme); the manager stays light
  until phase 6 converts the older pages (owner decision 2026-11-14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 09:01:26 +02:00
co-authored by Claude Opus 5.5
parent 92bc1b0113
commit 2426ffddad
36 changed files with 995 additions and 92 deletions
@@ -1,4 +1,6 @@
import { useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import VenueSettings from './sections/VenueSettings'
import AppInfoTab from './tabs/AppInfoTab'
import ColoursTab from './tabs/ColoursTab'
import OperationTab from './tabs/OperationTab'
@@ -8,24 +10,19 @@ import DevelopmentTab from './tabs/DevelopmentTab'
import FiscalTab from './tabs/FiscalTab'
import { TabGroup } from '../../ui/Tabs'
const TABS = [
{ id: 'app-info', label: 'Γενικά' },
{ id: 'security', label: 'Ασφάλεια' },
{ id: 'operation', label: 'Λειτουργία' },
{ id: 'colours', label: 'Εμφάνιση' },
{ id: 'print-fonts', label: 'Εκτύπωση' },
{ id: 'fiscal', label: 'Ταμειακή' },
{ id: 'development', label: 'Developer' },
]
const TABS = ['app-info', 'venue', 'security', 'operation', 'colours', 'print-fonts', 'fiscal', 'development']
export default function SettingsPage() {
const { t } = useTranslation('manager')
const [activeTab, setActiveTab] = useState('app-info')
const tabs = TABS.map(id => ({ id, label: t(`settings.tabs.${id}`) }))
return (
<div className="flex flex-col h-full min-h-0">
<TabGroup tabs={TABS} active={activeTab} onChange={setActiveTab} />
<TabGroup tabs={tabs} active={activeTab} onChange={setActiveTab} />
<div className="flex-1 overflow-y-auto p-6">
{activeTab === 'app-info' && <AppInfoTab />}
{activeTab === 'venue' && <div className="max-w-3xl"><VenueSettings /></div>}
{activeTab === 'security' && <SecurityTab />}
{activeTab === 'operation' && <OperationTab />}
{activeTab === 'colours' && <ColoursTab />}
@@ -0,0 +1,31 @@
// print.alert_after_failures (plan step 2.6f, step 1.11): after how many failed attempts a
// kitchen/bar ticket that is still retrying raises a notification (the bell). 0 = only when
// it is finally given up (that one is always sent). Part of the ordering module.
import { useId } from 'react'
import { useModule } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import { Select } from '@xenia/ui'
import { SettingRow, SettingsCard } from './SettingsCard'
import { useSettings } from './useSettings'
const CHOICES = [0, 1, 2, 3, 5, 10]
export default function PrintAlertSetting() {
const { t } = useTranslation('manager')
const ordering = useModule('ordering')
const s = useSettings()
const id = useId()
if (!ordering || s.loading) return null
const value = s.get('print.alert_after_failures', '2')
const options = CHOICES.map(n => ({ value: String(n), label: n === 0 ? t('settings.print.never') : t('settings.print.after', { count: n }) }))
if (!options.some(o => o.value === value)) options.push({ value, label: t('settings.print.after', { count: Number(value) }) })
return (
<SettingsCard title={t('settings.print.title')} testId="settings-print-alert">
<SettingRow label={t('settings.print.alert')} htmlFor={id} hint={t('settings.print.alertHint')}>
<Select id={id} value={value} disabled={s.saving} data-testid="setting-print.alert_after_failures"
onChange={e => s.save('print.alert_after_failures', e.target.value)} options={options} />
</SettingRow>
</SettingsCard>
)
}
@@ -0,0 +1,33 @@
// A card of settings rows on the tokens (plan step 2.6f). Each row: label, optional help
// line and (i) tip, and its control on the right (stacked on narrow screens).
import { InfoTip } from '@xenia/ui'
export function SettingsCard({ title, description, children, testId }) {
return (
<section className="bg-surface border border-line rounded-card shadow-raised" data-testid={testId}>
<header className="px-5 pt-4 pb-3 border-b border-line">
<h2 className="text-body font-semibold text-ink">{title}</h2>
{description && <p className="text-label text-ink-2 mt-0.5">{description}</p>}
</header>
<div className="divide-y divide-line">{children}</div>
</section>
)
}
export function SettingRow({ label, hint, tip, children, warning, htmlFor }) {
return (
<div className="px-5 py-3.5">
<div className="flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-6">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1">
<label className="text-body font-medium text-ink" htmlFor={htmlFor}>{label}</label>
{tip && <InfoTip>{tip}</InfoTip>}
</div>
{hint && <p className="text-label text-ink-2 mt-0.5">{hint}</p>}
</div>
<div className="sm:w-64 shrink-0">{children}</div>
</div>
{warning && <p className="mt-2 rounded-control bg-warning-soft text-warning-ink text-label px-3 py-2" role="note">{warning}</p>}
</div>
)
}
@@ -0,0 +1,61 @@
// Sign-in settings (plan step 2.6f, APPS_PLATFORM D-8, D-9). Backend-only until now:
// auth.manager_login_mode, auth.waiter_login_mode, auth.waiter_require_username,
// auth.default_login_mode (paired devices; a device can choose its own on the Devices page),
// auth.single_session_manager / _waiter, and security.autofill_username (the sign-in page).
// Replaces the v1 "login method" card, whose setting (security.login_method) no longer exists.
import { useId } from 'react'
import { useTranslation } from '@xenia/i18n'
import { Select, Spinner, Switch } from '@xenia/ui'
import { SettingRow, SettingsCard } from './SettingsCard'
import { useSettings } from './useSettings'
const SESSION_RULES = ['off', 'refuse_new', 'end_old']
export default function SignInSettings() {
const { t } = useTranslation('manager')
const s = useSettings()
const idManager = useId()
const idWaiter = useId()
const idDevice = useId()
const idSingleManager = useId()
const idSingleWaiter = useId()
if (s.loading) return <div className="py-8 flex justify-center"><Spinner /></div>
const opts = (keys, prefix) => keys.map(k => ({ value: k, label: t(`${prefix}.${k}`) }))
const select = (key, fallback, options, id) => (
<Select id={id} value={s.get(key, fallback)} disabled={s.saving} onChange={e => s.save(key, e.target.value)}
options={options} data-testid={`setting-${key}`} />
)
const toggle = (key, fallback, label) => (
<Switch aria-label={label} checked={s.get(key, fallback) === 'true'} disabled={s.saving}
onChange={v => s.save(key, v ? 'true' : 'false')} data-testid={`setting-${key}`} />
)
const waiterMode = s.get('auth.waiter_login_mode', 'pin')
return (
<SettingsCard title={t('settings.signIn.title')} description={t('settings.signIn.intro')} testId="settings-sign-in">
<SettingRow label={t('settings.signIn.manager')} htmlFor={idManager} tip={t('settings.signIn.managerTip')}>
{select('auth.manager_login_mode', 'password', opts(['password', 'pin'], 'settings.mode'), idManager)}
</SettingRow>
<SettingRow label={t('settings.signIn.autofill')} hint={t('settings.signIn.autofillHint')}>
{toggle('security.autofill_username', 'true', t('settings.signIn.autofill'))}
</SettingRow>
<SettingRow label={t('settings.signIn.waiter')} htmlFor={idWaiter}
warning={waiterMode === 'tap' ? t('settings.signIn.waiterTapWarning') : undefined}>
{select('auth.waiter_login_mode', 'pin', opts(['pin', 'password', 'tap'], 'settings.mode'), idWaiter)}
</SettingRow>
<SettingRow label={t('settings.signIn.requireUsername')} hint={t('settings.signIn.requireUsernameHint')}>
{toggle('auth.waiter_require_username', 'false', t('settings.signIn.requireUsername'))}
</SettingRow>
<SettingRow label={t('settings.signIn.device')} htmlFor={idDevice} hint={t('settings.signIn.deviceHint')}>
{select('auth.default_login_mode', 'pin', opts(['pin', 'password', 'tap', 'none'], 'settings.mode'), idDevice)}
</SettingRow>
<SettingRow label={t('settings.signIn.singleManager')} htmlFor={idSingleManager} tip={t('settings.signIn.singleTip')}>
{select('auth.single_session_manager', 'off', opts(SESSION_RULES, 'settings.session'), idSingleManager)}
</SettingRow>
<SettingRow label={t('settings.signIn.singleWaiter')} htmlFor={idSingleWaiter}>
{select('auth.single_session_waiter', 'off', opts(SESSION_RULES, 'settings.session'), idSingleWaiter)}
</SettingRow>
</SettingsCard>
)
}
@@ -0,0 +1,38 @@
// Venue language and time zone (plan step 2.6f, D-11, D-12): venue.language is the
// language of staff without their own choice and of printed tickets/reports; venue.timezone
// is the zone every time is shown in (applies at once). Both reload bootstrap after saving.
import { useId, useMemo } from 'react'
import { useAccess } from '@xenia/access'
import { LANGUAGE_NAMES, useTranslation, useFormat } from '@xenia/i18n'
import { Select, Spinner } from '@xenia/ui'
import { SettingRow, SettingsCard } from './SettingsCard'
import { useSettings } from './useSettings'
import { timeZones } from './timeZones'
export default function VenueSettings() {
const { t } = useTranslation('manager')
const f = useFormat()
const { languages } = useAccess()
const s = useSettings()
const langId = useId()
const tzId = useId()
const tz = s.get('venue.timezone', 'Europe/Athens')
const zones = useMemo(() => timeZones(tz), [tz])
if (s.loading) return <div className="py-8 flex justify-center"><Spinner /></div>
return (
<SettingsCard title={t('settings.venue.title')} testId="settings-venue">
<SettingRow label={t('settings.venue.language')} htmlFor={langId} hint={t('settings.venue.languageHint')}>
<Select id={langId} value={s.get('venue.language', 'en')} disabled={s.saving} data-testid="setting-venue.language"
onChange={e => s.save('venue.language', e.target.value)}
options={(languages || ['en', 'el']).map(l => ({ value: l, label: LANGUAGE_NAMES[l] || l }))} />
</SettingRow>
<SettingRow label={t('settings.venue.timezone')} htmlFor={tzId}
hint={t('settings.venue.timezoneHint', { time: f.formatTime(new Date()) })}>
<Select id={tzId} value={tz} disabled={s.saving} data-testid="setting-venue.timezone"
onChange={e => s.save('venue.timezone', e.target.value)}
options={zones.map(z => ({ value: z, label: z.replace(/_/g, ' ') }))} />
</SettingRow>
</SettingsCard>
)
}
@@ -0,0 +1,12 @@
/** Every IANA zone the browser knows; the current one is kept even when the browser lacks it. */
export function timeZones(current) {
let zones = []
try { zones = Intl.supportedValuesOf('timeZone') } catch { zones = [] }
if (current && !zones.includes(current)) zones = [current, ...zones]
return zones
}
/** The browser's own zone (for the setup wizard's default), or Europe/Athens. */
export function browserTimeZone() {
try { return Intl.DateTimeFormat().resolvedOptions().timeZone || 'Europe/Athens' } catch { return 'Europe/Athens' }
}
@@ -0,0 +1,41 @@
// Venue settings for the v2 settings sections (plan step 2.6f): GET /api/settings/ (all
// declared keys with their values) and PUT /api/settings/{key} {value} (core.settings.manage;
// the backend checks types, enums, time zones and languages). Shares the react-query key
// with the older settings tabs, so both stay in sync.
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useAccess } from '@xenia/access'
import { useTranslation } from '@xenia/i18n'
import client from '../../../api/client'
/** Keys that change what bootstrap says (language, time zone, sign-in mode): reload it. */
const BOOTSTRAP_KEYS = new Set(['venue.language', 'venue.timezone', 'auth.manager_login_mode', 'security.autofill_username'])
export function useSettings() {
const { t } = useTranslation('manager')
const qc = useQueryClient()
const access = useAccess()
const query = useQuery({
queryKey: ['pos-settings'],
queryFn: () => client.get('/api/settings/').then(r => r.data),
staleTime: 30_000,
})
const mutation = useMutation({
mutationFn: ({ key, value }) => client.put(`/api/settings/${key}`, { value }),
onSuccess: (_r, { key }) => {
toast.success(t('settings.saved'))
qc.invalidateQueries({ queryKey: ['pos-settings'] })
if (BOOTSTRAP_KEYS.has(key)) access.refresh()
},
onError: err => toast.error(errorMessage(err, t)),
})
return {
loading: query.isLoading,
error: query.error ? errorMessage(query.error, t) : null,
/** The stored value (strings, as the backend keeps them), or `fallback`. */
get: (key, fallback = '') => query.data?.[key]?.value ?? fallback,
save: (key, value) => mutation.mutate({ key, value: String(value) }),
saving: mutation.isPending,
}
}
@@ -1,4 +1,5 @@
import React, { useState, useEffect, useRef, useCallback } from 'react'
import PrintAlertSetting from '../sections/PrintAlertSetting'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import client from '../../../api/client'
@@ -1115,6 +1116,7 @@ export default function PrintFontsTab() {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
<PrintAlertSetting />
{/* 1. Printers */}
<PrintersSection />
@@ -1,8 +1,9 @@
import { useState } from 'react'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { Shield, Lock, LogOut, User, KeyRound, ShieldCheck, Copy, RefreshCw, X } from 'lucide-react'
import { Shield, Lock, LogOut, User, ShieldCheck, Copy, RefreshCw, X } from 'lucide-react'
import client from '../../../api/client'
import SignInSettings from '../sections/SignInSettings'
import { PANEL_CLASS } from '../../../ui/tokens'
import Button from '../../../ui/Button'
@@ -76,28 +77,6 @@ function Toggle({ checked, onChange, disabled }) {
)
}
function SegmentedControl({ options, value, onChange, disabled }) {
return (
<div className="flex rounded-lg border border-gray-200 overflow-hidden bg-gray-50 p-0.5 gap-0.5">
{options.map(opt => (
<button
key={opt.value}
type="button"
onClick={() => !disabled && onChange(opt.value)}
disabled={disabled}
className={`px-3 py-1.5 text-xs font-medium rounded-md transition-all ${
value === opt.value
? 'bg-white text-gray-800 shadow-sm'
: 'text-gray-500 hover:text-gray-700'
}`}
>
{opt.label}
</button>
))}
</div>
)
}
function TimeSelect({ value, onChange, disabled }) {
return (
<div className="flex items-center gap-2">
@@ -290,8 +269,6 @@ export default function SecurityTab() {
)
}
const loginMethod = get('security.login_method', 'password')
const autofill = get('security.autofill_username', 'true') === 'true'
const autoLock = get('security.auto_lock', 'false') === 'true'
const autoLockSecs = get('security.auto_lock_seconds', '300')
const autoLogout = get('security.auto_logout', 'false') === 'true'
@@ -300,46 +277,8 @@ export default function SecurityTab() {
return (
<div className="space-y-5">
{/* ── Μέθοδος σύνδεσης ─────────────────────────────────────────────── */}
<SectionCard
icon={KeyRound}
title="Σύνδεση"
description="Τι διαπιστευτήρια απαιτούνται όταν η εφαρμογή ξεκινά ή μετά από πλήρη αποσύνδεση."
>
<OptionRow
label="Μέθοδος σύνδεσης"
description="Πώς πιστοποιούνται οι διαχειριστές κατά την πρώτη πρόσβαση."
>
<SegmentedControl
value={loginMethod}
onChange={v => save('security.login_method', v)}
disabled={busy}
options={[
{ value: 'password', label: 'Κωδικός' },
{ value: 'pin', label: 'PIN' },
{ value: 'none', label: 'Κανένα' },
]}
/>
</OptionRow>
{loginMethod === 'none' && (
<div className="mx-5 mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-[12px] text-amber-700">
<strong>Προσοχή:</strong> με έναν μόνο λογαριασμό διαχειριστή, η εφαρμογή θα ανοίγει χωρίς πιστοποίηση.
Χρησιμοποιήστε αυτό μόνο σε φυσικά ασφαλή, ιδιωτική συσκευή.
</div>
)}
<OptionRow
label="Αυτόματη συμπλήρωση ονόματος χρήστη"
description="Όταν υπάρχει μόνο ένας διαχειριστής, παράλειψη του πεδίου ονόματος."
>
<Toggle
checked={autofill}
onChange={v => save('security.autofill_username', v ? 'true' : 'false')}
disabled={busy}
/>
</OptionRow>
</SectionCard>
{/* Sign-in (2.6f): the v2 settings auth.* replace the v1 security.login_method card */}
<SignInSettings />
{/* ── Αυτόματο κλείδωμα ────────────────────────────────────────────── */}
<SectionCard