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/sign-out.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
import { Button, Popconfirm } from "antd";
6
import { FormattedMessage, useIntl } from "react-intl";
7
import { Icon } from "@cocalc/frontend/components/icon";
8
import { React, Rendered, redux } from "@cocalc/frontend/app-framework";
9
import { labels } from "@cocalc/frontend/i18n";
10
import track from "@cocalc/frontend/user-tracking";
11
12
interface Props {
13
everywhere?: boolean;
14
sign_in?: boolean;
15
highlight?: boolean;
16
style?: React.CSSProperties;
17
narrow?: boolean;
18
}
19
20
export const SignOut: React.FC<Props> = (props: Readonly<Props>) => {
21
const { everywhere, sign_in, highlight, style, narrow = false } = props;
22
23
const intl = useIntl();
24
25
function sign_out(): void {
26
const account = redux.getActions("account");
27
if (account != null) {
28
track("sign-out", { how: "settings-page", everywhere, sign_in });
29
account.sign_out(!!everywhere, !!sign_in);
30
}
31
}
32
33
function render_body(): Rendered {
34
if (sign_in) {
35
return (
36
<span>
37
<FormattedMessage
38
id="account.sign_out.body.sign_in"
39
description={"Sign in button, if not signed in"}
40
defaultMessage={"Sign in to your account..."}
41
/>
42
</span>
43
);
44
} else {
45
return (
46
<span>
47
<FormattedMessage
48
id="account.sign_out.body.sign_out"
49
description={"Sign out button, if signed in"}
50
defaultMessage={`Sign out{everywhere, select, true { everywhere} other {}}...`}
51
values={{ everywhere }}
52
/>
53
</span>
54
);
55
}
56
}
57
58
// I think not using reduxProps is fine for this, since it's only rendered once
59
// you are signed in, and falling back to "your account" isn't bad.
60
const store = redux.getStore("account");
61
const account: string = store.get("email_address") ?? "your account";
62
63
return (
64
<Popconfirm
65
title={
66
<div style={{ maxWidth: "60ex" }}>
67
<FormattedMessage
68
id="account.sign-out.button.title"
69
description="Sign out/Sign out everyhwere button in account settings"
70
defaultMessage={`Are you sure you want to sign {account} out
71
{everywhere, select,
72
true {on all web browsers? Every web browser will have to reauthenticate before using this account again.}
73
other {on this web browser?}
74
}
75
{is_anonymous, select,
76
true {Everything you have done using this TEMPORARY ACCOUNT will be immediately deleted! If you would like to save your work to a new account, click cancel and sign up below.}
77
other {}
78
}`}
79
values={{
80
account,
81
everywhere,
82
is_anonymous: store.get("is_anonymous"),
83
}}
84
/>
85
</div>
86
}
87
onConfirm={sign_out}
88
okText={intl.formatMessage(
89
{
90
id: "account.sign-out.button.ok",
91
defaultMessage: `Yes, sign out{everywhere, select, true { everywhere} other {}}`,
92
},
93
{ everywhere },
94
)}
95
cancelText={intl.formatMessage(labels.cancel)}
96
>
97
{/* NOTE: weirdly darkreader breaks when we use the antd LogoutOutlined icon!? */}
98
<Button type={highlight ? "primary" : undefined} style={style}>
99
<Icon name="sign-in" />{" "}
100
{!narrow || everywhere ? render_body() : undefined}
101
</Button>
102
</Popconfirm>
103
);
104
};
105
106