File size: 665 Bytes
cd99321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
}