Files
TREK/client/src/components/SystemNotices/noticeActions.ts
T
jubnl 293506217e feat(notices): add system notice infrastructure
Server-side notice registry with per-user condition evaluation (firstLogin,
existingUserBeforeVersion, addonEnabled, dateWindow, role, custom).
Notices are sorted by priority then severity, filtered against dismissals
stored in a new user_notice_dismissals table, and served via
GET /api/system-notices/active + POST /api/system-notices/:id/dismiss.

Client renders notices through a host component that partitions by
display type (modal / banner / toast). The modal renderer supports
multi-page pagination with directional slide transitions, keyboard
navigation, and correct dismiss-all semantics on CTA / X / ESC.
Dismissals are optimistic with a single background retry.

Includes 3.0.0 upgrade notices (v3-photos, v3-journey, v3-features),
onboarding welcome modal, and full i18n coverage across 15 languages.
The /journey route is addon-gated on both client and server.

Also includes: unit + integration test suites, registry integrity test
that validates action CTA IDs against client source, and technical
documentation in docs/system-notices.md.
2026-04-16 14:36:33 +02:00

22 lines
665 B
TypeScript

import type { NavigateFunction } from 'react-router-dom';
export interface NoticeActionContext {
navigate: NavigateFunction;
}
type NoticeActionHandler = (ctx: NoticeActionContext) => void | Promise<void>;
const actions = new Map<string, NoticeActionHandler>();
export function registerNoticeAction(id: string, handler: NoticeActionHandler): void {
actions.set(id, handler);
}
export function runNoticeAction(id: string, ctx: NoticeActionContext): void {
const handler = actions.get(id);
if (!handler) {
console.error(`[systemNotices] unknown action CTA id: "${id}". Register it via registerNoticeAction().`);
return;
}
void handler(ctx);
}