Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/account-preferences-communication.tsx
2209 views
1
/*
2
* This file is part of CoCalc: Copyright © 2025 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Button } from "antd";
7
import { FormattedMessage, useIntl } from "react-intl";
8
9
import { Panel, Switch } from "@cocalc/frontend/antd-bootstrap";
10
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
11
import { Icon, IconName } from "@cocalc/frontend/components";
12
import { labels } from "@cocalc/frontend/i18n";
13
import { webapp_client } from "@cocalc/frontend/webapp-client";
14
15
export const COMMUNICATION_ICON_NAME: IconName = "mail";
16
17
export function AccountPreferencesCommunication(): React.JSX.Element {
18
const intl = useIntl();
19
const other_settings = useTypedRedux("account", "other_settings");
20
const stripe_customer = useTypedRedux("account", "stripe_customer");
21
const email_address_verified = useTypedRedux(
22
"account",
23
"email_address_verified",
24
);
25
const email_address = useTypedRedux("account", "email_address");
26
const isVerified = !!email_address_verified?.get(email_address ?? "");
27
const is_stripe_customer = !!stripe_customer?.getIn([
28
"subscriptions",
29
"total_count",
30
]);
31
32
function on_change(name: string, value: any): void {
33
redux.getActions("account").set_other_settings(name, value);
34
}
35
36
function toggle_global_banner(val: boolean): void {
37
if (val) {
38
// this must be "null", not "undefined" – otherwise the data isn't stored in the DB.
39
on_change("show_global_info2", null);
40
} else {
41
on_change("show_global_info2", webapp_client.server_time());
42
}
43
}
44
45
function render_global_banner() {
46
return (
47
<Switch
48
checked={!other_settings.get("show_global_info2")}
49
onChange={(e) => toggle_global_banner(e.target.checked)}
50
>
51
<FormattedMessage
52
id="account.other-settings.global_banner"
53
defaultMessage={`<strong>Show Announcement Banner</strong>: only shows up if there is a
54
message`}
55
/>
56
</Switch>
57
);
58
}
59
60
function render_no_free_warnings() {
61
const extra = is_stripe_customer ? (
62
<span>(thanks for being a customer)</span>
63
) : (
64
<span>(only available to customers)</span>
65
);
66
67
return (
68
<Switch
69
disabled={!is_stripe_customer}
70
checked={!!other_settings.get("no_free_warnings")}
71
onChange={(e) => on_change("no_free_warnings", e.target.checked)}
72
>
73
<strong>Hide free warnings</strong>: do{" "}
74
<strong>
75
<i>not</i>
76
</strong>{" "}
77
show a warning banner when using a free trial project {extra}
78
</Switch>
79
);
80
}
81
82
function render_no_email_new_messages() {
83
return (
84
<>
85
<Switch
86
checked={other_settings.get("no_email_new_messages")}
87
onChange={(e) => {
88
on_change("no_email_new_messages", e.target.checked);
89
}}
90
>
91
Do NOT send email when you get new{" "}
92
<Button
93
onClick={(e) => {
94
e.stopPropagation();
95
redux.getActions("page").set_active_tab("notifications");
96
redux
97
.getActions("mentions")
98
.set_filter("messages-inbox" as "messages-inbox");
99
}}
100
type="link"
101
size="small"
102
>
103
Internal Messages
104
</Button>
105
</Switch>
106
{!isVerified && !other_settings.get("no_email_new_messages") && (
107
<>
108
(NOTE: You must also verify your email address above to get emails
109
about new messages.)
110
</>
111
)}
112
</>
113
);
114
}
115
116
return (
117
<Panel
118
size="small"
119
header={
120
<>
121
<Icon name={COMMUNICATION_ICON_NAME} />{" "}
122
{intl.formatMessage(labels.communication)}
123
</>
124
}
125
>
126
{render_global_banner()}
127
{render_no_free_warnings()}
128
{render_no_email_new_messages()}
129
</Panel>
130
);
131
}
132
133