CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/account-preferences.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Form, Switch, Tooltip } from "antd";
7
import { join } from "path";
8
import { FormattedMessage } from "react-intl";
9
import { Col, Row } from "@cocalc/frontend/antd-bootstrap";
10
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
11
import { A, Loading } from "@cocalc/frontend/components";
12
import { Footer } from "@cocalc/frontend/customize";
13
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
14
import track from "@cocalc/frontend/user-tracking";
15
import { EditorSettings } from "./editor-settings/editor-settings";
16
import { KeyboardSettings } from "./keyboard-settings";
17
import { OtherSettings } from "./other-settings";
18
import { ProfileSettings } from "./profile-settings";
19
import { AccountSettings } from "./settings/account-settings";
20
import ApiKeys from "./settings/api-keys";
21
import TableError from "./table-error";
22
import { TerminalSettings } from "./terminal-settings";
23
24
export const AccountPreferences: React.FC = () => {
25
const account_id = useTypedRedux("account", "account_id");
26
const first_name = useTypedRedux("account", "first_name");
27
const last_name = useTypedRedux("account", "last_name");
28
const name = useTypedRedux("account", "name");
29
const email_address = useTypedRedux("account", "email_address");
30
const email_address_verified = useTypedRedux(
31
"account",
32
"email_address_verified",
33
);
34
const passports = useTypedRedux("account", "passports");
35
const sign_out_error = useTypedRedux("account", "sign_out_error");
36
const stripe_customer = useTypedRedux("account", "stripe_customer");
37
const other_settings = useTypedRedux("account", "other_settings");
38
const is_anonymous = useTypedRedux("account", "is_anonymous");
39
const created = useTypedRedux("account", "created");
40
const strategies = useTypedRedux("account", "strategies");
41
const unlisted = useTypedRedux("account", "unlisted");
42
const email_enabled = useTypedRedux("customize", "email_enabled");
43
const verify_emails = useTypedRedux("customize", "verify_emails");
44
const kucalc = useTypedRedux("customize", "kucalc");
45
46
function render_account_settings(): JSX.Element {
47
return (
48
<AccountSettings
49
account_id={account_id}
50
first_name={first_name}
51
last_name={last_name}
52
name={name}
53
email_address={email_address}
54
email_address_verified={email_address_verified}
55
passports={passports}
56
sign_out_error={sign_out_error}
57
other_settings={other_settings as any}
58
is_anonymous={is_anonymous}
59
email_enabled={email_enabled}
60
verify_emails={verify_emails}
61
created={created}
62
strategies={strategies}
63
unlisted={unlisted}
64
/>
65
);
66
}
67
68
function render_other_settings(): JSX.Element {
69
if (other_settings == null) return <Loading />;
70
return (
71
<OtherSettings
72
other_settings={other_settings as any}
73
is_stripe_customer={
74
!!stripe_customer?.getIn(["subscriptions", "total_count"])
75
}
76
kucalc={kucalc}
77
/>
78
);
79
}
80
81
function renderDarkMode(): JSX.Element {
82
return (
83
<Tooltip title="Enable dark mode across the entire user interface. See further dark mode configuration below.">
84
<Form>
85
<Form.Item
86
label={
87
<div
88
onClick={() => {
89
redux
90
.getActions("account")
91
.set_other_settings(
92
"dark_mode",
93
!other_settings.get("dark_mode"),
94
);
95
}}
96
style={{
97
cursor: "pointer",
98
color: "rgba(229, 224, 216)",
99
backgroundColor: "rgb(36, 37, 37)",
100
padding: "5px 10px",
101
borderRadius: "3px",
102
}}
103
>
104
Dark Mode
105
</div>
106
}
107
>
108
<Switch
109
checked={other_settings.get("dark_mode")}
110
onChange={(checked) => {
111
redux
112
.getActions("account")
113
.set_other_settings("dark_mode", checked);
114
track("dark-mode", { how: "settings page", checked });
115
}}
116
/>
117
</Form.Item>
118
</Form>
119
</Tooltip>
120
);
121
}
122
123
function render_all_settings(): JSX.Element {
124
return (
125
<>
126
<div style={{ float: "right" }}>{renderDarkMode()}</div>
127
<h2>
128
<FormattedMessage
129
id="account.account_preferences.title"
130
defaultMessage={"Account Preferences"}
131
/>
132
</h2>
133
<div style={{ fontSize: "14pt" }}>
134
<FormattedMessage
135
id="accountaccount.account_preferences.subtitle"
136
defaultMessage={
137
"Adjust account preferences below. <A>Visit your account configuration for more...</A>"
138
}
139
values={{
140
A: (ch) => <A href={join(appBasePath, "config")}>{ch}</A>,
141
}}
142
/>
143
</div>
144
<br />
145
<br />
146
<Row>
147
<Col xs={12} md={6}>
148
{render_account_settings()}
149
<ProfileSettings
150
email_address={email_address}
151
// first_name={first_name}
152
// last_name={last_name}
153
/>
154
{render_other_settings()}
155
{!is_anonymous && <ApiKeys />}
156
</Col>
157
<Col xs={12} md={6}>
158
<EditorSettings />
159
<TerminalSettings />
160
<KeyboardSettings />
161
</Col>
162
</Row>
163
<Footer />
164
</>
165
);
166
}
167
168
return (
169
<div style={{ marginTop: "1em" }}>
170
<TableError />
171
{is_anonymous ? render_account_settings() : render_all_settings()}
172
</div>
173
);
174
};
175
176