-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathScriptLinkWarningDialog.tsx
118 lines (106 loc) · 2.92 KB
/
ScriptLinkWarningDialog.tsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
import React from "react";
// dialogs stack on top of each other when all are open as:
// opt out language warning > link warning > script editor
const styles = {
dialog: {
zIndex: 10002
}
};
export enum ScriptWarningContext {
GenericLink = "generic-link",
ShortLink = "short-link"
}
interface ContentProps {
warningContext: ScriptWarningContext;
}
const DialogContentWrapper = (props: ContentProps) => {
const { warningContext } = props;
const genericLinkContent = (
<div>
It looks like you're sending a message that includes a link.
<br />
<p>
Be sure to read our advice{" "}
<a
href="https://docs.spokerewired.com/article/113-sending-links"
target="_blank"
rel="noopener noreferrer"
>
here
</a>
.
</p>
</div>
);
const shortLinkContent = (
<div>
<div>
It looks like you're sending a message that includes a link shortener.
</div>
<div style={{ display: "flex" }}>
For better deliverability, we
<div style={{ color: "red" }}> strongly </div>
advise against this.
</div>
<p>
If you need to insert a short link into your message, be sure to read
the docs{" "}
<a
href="https://docs.spokerewired.com/article/113-sending-links"
target="_blank"
rel="noopener noreferrer"
>
here
</a>
.
</p>
</div>
);
switch (warningContext) {
case ScriptWarningContext.GenericLink:
return genericLinkContent;
case ScriptWarningContext.ShortLink:
return shortLinkContent;
default:
return <p>Error: unknown context</p>;
}
};
export interface WarningProps {
open: boolean;
warningContext: ScriptWarningContext;
handleConfirm: () => void;
handleClose: () => void;
}
const ScriptLinkWarningDialog = ({
warningContext,
handleClose,
handleConfirm,
open
}: WarningProps) => {
const title =
(warningContext === ScriptWarningContext.GenericLink && "Confirm Script") ||
(warningContext === ScriptWarningContext.ShortLink && "Short Link Warning");
const actions = [
<Button key="close" onClick={handleClose}>
Close
</Button>,
<Button key="save" color="primary" onClick={handleConfirm}>
Confirm and Save
</Button>
];
return (
<Dialog open={open} style={styles.dialog}>
<DialogTitle>{title}</DialogTitle>
<DialogContent>
<DialogContentWrapper warningContext={warningContext} />
</DialogContent>
<DialogActions>{actions}</DialogActions>
</Dialog>
);
};
export default ScriptLinkWarningDialog;