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-button.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 { Popconfirm, Popover } from "antd";
7
import React from "react";
8
import { FormattedMessage, useIntl } from "react-intl";
9
10
import { AccountActions } from "@cocalc/frontend/account";
11
import { labels } from "@cocalc/frontend/i18n";
12
import { CancelText } from "@cocalc/frontend/i18n/components";
13
14
interface Props {
15
icon: React.ReactNode; // When clicked, show popover
16
links: React.ReactNode; // Should change view to correct account settings tab when clicked
17
label_class: string; // class name for AccountTabDropdown label
18
show_label: boolean; // This tells button to show
19
is_active: boolean; // if true set button background to ACTIVE_BG_COLOR
20
user_label: string;
21
}
22
23
interface AccountTabProps {
24
icon;
25
links;
26
label_class;
27
show_label;
28
is_active;
29
user_label;
30
}
31
32
export const AccountTabDropdown: React.FC<Props> = (props: AccountTabProps) => {
33
const { icon, links, label_class, show_label, is_active, user_label } = props;
34
const intl = useIntl();
35
36
const label = intl.formatMessage(labels.account);
37
38
// If icon is a string then use the Icon component
39
// Else (it is a node already) just render icon
40
return (
41
<Popover
42
placement="bottom"
43
title={"Signed in as " + user_label}
44
trigger="click"
45
content={links}
46
>
47
<div
48
style={{
49
display: "flex",
50
flex: "0 0 auto",
51
float: "left",
52
position: "relative",
53
height: "30px",
54
padding: "8px",
55
whiteSpace: "nowrap",
56
...(is_active && { backgroundColor: "white" }),
57
}}
58
>
59
{icon}
60
<span style={{ marginLeft: 5 }} className={label_class}>
61
{show_label ? label : undefined}
62
</span>
63
</div>
64
</Popover>
65
);
66
};
67
68
interface LinksProps {
69
account_actions: AccountActions;
70
page_actions: any;
71
}
72
73
export const DefaultAccountDropDownLinks: React.FC<LinksProps> = ({
74
account_actions, // Type AccountActions
75
page_actions, // PageActions (untyped for now)
76
}) => {
77
return (
78
<>
79
<div className="cocalc-account-button-dropdown-links">
80
<li>
81
<a
82
style={{
83
width: "100%",
84
padding: "4px 8px 4px 16px",
85
display: "inline-block",
86
}}
87
className={"cocalc-account-button"}
88
onClick={(event) => {
89
event.preventDefault();
90
page_actions.set_active_tab("account"); // Set to account page
91
account_actions.set_active_tab("account"); /// Set to the Subs and course packs tab
92
}}
93
href=""
94
>
95
Preferences
96
</a>
97
</li>
98
<li>
99
<a
100
style={{
101
width: "100%",
102
padding: "4px 8px 4px 16px",
103
display: "inline-block",
104
}}
105
className={"cocalc-account-button"}
106
onClick={(event) => {
107
event.preventDefault();
108
page_actions.set_active_tab("account"); // Set to account page
109
account_actions.set_active_tab("billing"); /// Set to the Preferences tab
110
}}
111
href=""
112
>
113
Billing
114
</a>
115
</li>
116
<li>
117
<a
118
style={{
119
width: "100%",
120
padding: "4px 8px 4px 16px",
121
display: "inline-block",
122
}}
123
className={"cocalc-account-button"}
124
onClick={(event) => {
125
event.preventDefault();
126
page_actions.set_active_tab("account"); // Set to account page
127
account_actions.set_active_tab("upgrades"); /// Set to the Preferences tab
128
}}
129
href=""
130
>
131
Upgrades
132
</a>
133
</li>
134
<li>
135
<a
136
style={{
137
width: "100%",
138
padding: "4px 8px 4px 16px",
139
display: "inline-block",
140
}}
141
className={"cocalc-account-button"}
142
onClick={(event) => {
143
event.preventDefault();
144
page_actions.set_active_tab("account"); // Set to account page
145
account_actions.set_active_tab("support"); /// Set to the Preferences tab
146
}}
147
href=""
148
>
149
Support
150
</a>
151
</li>
152
<li>
153
<Popconfirm
154
title={
155
<FormattedMessage
156
id="account.account-button.confirm.title"
157
defaultMessage={"Sign out of your account?"}
158
/>
159
}
160
onConfirm={() => account_actions.sign_out(false, false)}
161
okText={
162
<FormattedMessage
163
id="account.account-button.confirm.ok"
164
defaultMessage={"Yes, sign out"}
165
/>
166
}
167
cancelText={<CancelText />}
168
>
169
<a
170
style={{
171
width: "100%",
172
padding: "4px 8px 4px 16px",
173
display: "inline-block",
174
}}
175
className={"cocalc-account-button"}
176
href=""
177
>
178
Sign out...
179
</a>
180
</Popconfirm>
181
</li>
182
</div>
183
</>
184
);
185
};
186
187