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:
@@ -22,3 +22,4 @@ export { Field, Input, Textarea, Select } from './components/Field.jsx'
|
||||
export { Switch } from './components/Switch.jsx'
|
||||
export { UiLabelsProvider, DEFAULT_LABELS } from './components/labels.js'
|
||||
export { cx } from './internal/cx.js'
|
||||
export { THEMES, THEME_STORAGE_KEY, applyTheme, getStoredTheme } from './theme.js'
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// The colour theme of an app (plan step 2.6f): light | dark | system (follows the OS).
|
||||
// tokens.css reads it from data-theme on <html>. The choice is per device (localStorage),
|
||||
// like a screen setting, not per user. No React here.
|
||||
//
|
||||
// applyTheme(getStoredTheme()) at startup
|
||||
// applyTheme('dark', { save: true }) when the user picks one
|
||||
//
|
||||
// The manager offers the choice only once its older pages use the tokens (phase 6): until
|
||||
// then it always applies 'light' (decided 2026-11-14), so a saved choice waits unused.
|
||||
|
||||
export const THEMES = ['light', 'dark', 'system']
|
||||
export const THEME_STORAGE_KEY = 'xenia_theme'
|
||||
|
||||
const browserStorage = () => { try { return globalThis.localStorage ?? null } catch { return null } }
|
||||
|
||||
/** The saved theme, or 'light'. */
|
||||
export function getStoredTheme(storage = browserStorage()) {
|
||||
try {
|
||||
const v = storage?.getItem(THEME_STORAGE_KEY)
|
||||
return THEMES.includes(v) ? v : 'light'
|
||||
} catch {
|
||||
return 'light'
|
||||
}
|
||||
}
|
||||
|
||||
/** Set data-theme on the root element (and save it when asked). Unknown values become 'light'. */
|
||||
export function applyTheme(theme, { root = globalThis.document?.documentElement, storage = browserStorage(), save = false } = {}) {
|
||||
const t = THEMES.includes(theme) ? theme : 'light'
|
||||
root?.setAttribute('data-theme', t)
|
||||
if (save) {
|
||||
try { storage?.setItem(THEME_STORAGE_KEY, t) } catch { /* private mode: not remembered */ }
|
||||
}
|
||||
return t
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { applyTheme, getStoredTheme, THEME_STORAGE_KEY } from '../src/theme.js'
|
||||
|
||||
const memory = () => { const m = new Map(); return { getItem: k => m.get(k) ?? null, setItem: (k, v) => m.set(k, v) } }
|
||||
const element = () => { const a = {}; return { setAttribute: (k, v) => { a[k] = v }, attrs: a } }
|
||||
|
||||
test('stored theme: light unless a known one is saved', () => {
|
||||
const s = memory()
|
||||
assert.equal(getStoredTheme(s), 'light')
|
||||
s.setItem(THEME_STORAGE_KEY, 'neon')
|
||||
assert.equal(getStoredTheme(s), 'light')
|
||||
s.setItem(THEME_STORAGE_KEY, 'system')
|
||||
assert.equal(getStoredTheme(s), 'system')
|
||||
assert.equal(getStoredTheme({ getItem: () => { throw new Error('blocked') } }), 'light')
|
||||
})
|
||||
|
||||
test('applyTheme sets data-theme and saves only when asked', () => {
|
||||
const s = memory()
|
||||
const root = element()
|
||||
assert.equal(applyTheme('dark', { root, storage: s }), 'dark')
|
||||
assert.equal(root.attrs['data-theme'], 'dark')
|
||||
assert.equal(getStoredTheme(s), 'light')
|
||||
applyTheme('dark', { root, storage: s, save: true })
|
||||
assert.equal(getStoredTheme(s), 'dark')
|
||||
assert.equal(applyTheme('bogus', { root, storage: s }), 'light')
|
||||
})
|
||||
Reference in New Issue
Block a user