Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Handle alerts sent by the server (moderation or internal)
*/
import { IAlert } from "@sc07-canvas/lib/src/net";
import { toast } from "react-toastify";
/**
* Handles IAlert outside of react
* @param alert
*/
export const handleAlert = (alert: IAlert) => {
switch (alert.is) {
case "toast":
handleToast(alert);
break;
case "modal":
handleModal(alert);
break;
}
};
export const handleDismiss = (id: string) => {
toast.dismiss(id);
};
const handleToast = (alert: IAlert<"toast">) => {
const Body = (
<>
<b>{alert.title}</b>
{alert.body && <> {alert.body}</>}
</>
);
toast(Body, {
toastId: alert.id,
type: alert.severity,
autoClose: alert.autoDismiss ? 5000 : false,
});
};
const handleModal = (alert: IAlert<"modal">) => {
window.alert("alerts#handleModal triggered, but no implementation exists");
};