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:
@@ -0,0 +1,37 @@
|
||||
// The manager's one live connection (plan step 2.6f): the backend WebSocket through
|
||||
// createLiveClient (@xenia/api, CS-2/CS-18), opened while signed in. Components listen
|
||||
// with useLiveEvent(type, handler). The cursor is kept in memory: a reconnect replays what
|
||||
// was missed; a page reload starts fresh (pages load their data anyway).
|
||||
import { useEffect, useMemo, useRef } from 'react'
|
||||
import { createLiveClient, wsUrlFor } from '@xenia/api'
|
||||
import useAuthStore from '../store/authStore'
|
||||
import { LiveContext } from './context'
|
||||
|
||||
export default function LiveProvider({ children }) {
|
||||
const token = useAuthStore(s => s.token)
|
||||
const listeners = useRef(new Map()) // type -> Set(fn)
|
||||
|
||||
const value = useMemo(() => ({
|
||||
subscribe(type, fn) {
|
||||
if (!listeners.current.has(type)) listeners.current.set(type, new Set())
|
||||
listeners.current.get(type).add(fn)
|
||||
return () => listeners.current.get(type)?.delete(fn)
|
||||
},
|
||||
}), [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return undefined
|
||||
const emit = (type, data) => listeners.current.get(type)?.forEach(fn => { try { fn(data) } catch { /* one listener must not stop the others */ } })
|
||||
let seq = 0
|
||||
const live = createLiveClient({
|
||||
url: () => wsUrlFor(`/api/ws/connect?token=${encodeURIComponent(token)}`),
|
||||
cursor: { load: () => seq, save: s => { seq = s } },
|
||||
onEvent: emit,
|
||||
onReady: () => emit('ready', null),
|
||||
})
|
||||
live.start()
|
||||
return () => live.stop()
|
||||
}, [token])
|
||||
|
||||
return <LiveContext.Provider value={value}>{children}</LiveContext.Provider>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createContext } from 'react'
|
||||
|
||||
/** { subscribe(type, fn) → unsubscribe } or null outside <LiveProvider> */
|
||||
export const LiveContext = createContext(null)
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useContext, useEffect, useRef } from 'react'
|
||||
import { LiveContext } from './context'
|
||||
|
||||
/**
|
||||
* Run `handler(data)` for each live event of `type` (plan step 2.6f).
|
||||
* The type 'ready' fires after every (re)connect, once missed events are replayed:
|
||||
* a good moment to refetch what a page shows.
|
||||
*/
|
||||
export function useLiveEvent(type, handler) {
|
||||
const live = useContext(LiveContext)
|
||||
const ref = useRef(handler)
|
||||
useEffect(() => { ref.current = handler }, [handler])
|
||||
useEffect(() => (live ? live.subscribe(type, data => ref.current?.(data)) : undefined), [live, type])
|
||||
}
|
||||
Reference in New Issue
Block a user