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/delete-account.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 { Alert, Button, Input } from "antd";
7
import { FormattedMessage, useIntl } from "react-intl";
8
9
import {
10
React,
11
Rendered,
12
useState,
13
useTypedRedux,
14
} from "@cocalc/frontend/app-framework";
15
import { ErrorDisplay, Icon } from "@cocalc/frontend/components";
16
import { CancelText } from "@cocalc/frontend/i18n/components";
17
18
interface Props {
19
initial_click: () => void;
20
confirm_click: () => void;
21
cancel_click: () => void;
22
user_name: string;
23
show_confirmation?: boolean;
24
style?: React.CSSProperties;
25
}
26
27
export function DeleteAccount(props: Props) {
28
const intl = useIntl();
29
30
return (
31
<div>
32
<div style={{ height: "26px" }}>
33
<Button
34
disabled={props.show_confirmation}
35
className="pull-right"
36
style={props.style}
37
onClick={props.initial_click}
38
>
39
<Icon name="trash" />{" "}
40
{intl.formatMessage({
41
id: "account.delete-account.button",
42
defaultMessage: "Delete Account",
43
})}
44
...
45
</Button>
46
</div>
47
{props.show_confirmation ? (
48
<DeleteAccountConfirmation
49
confirm_click={props.confirm_click}
50
cancel_click={props.cancel_click}
51
required_text={props.user_name}
52
/>
53
) : undefined}
54
</div>
55
);
56
}
57
58
interface ConfProps {
59
confirm_click: () => void;
60
cancel_click: () => void;
61
required_text: string;
62
}
63
64
// Concious choice to make them actually click the confirm delete button.
65
function DeleteAccountConfirmation({
66
confirm_click,
67
cancel_click,
68
required_text,
69
}: ConfProps) {
70
const intl = useIntl();
71
72
const account_deletion_error = useTypedRedux(
73
"account",
74
"account_deletion_error",
75
);
76
77
// State is lost on re-render from cancel. But this is what we want.
78
const [confirmation_text, set_confirmation_text] = useState<string>("");
79
80
function render_error(): Rendered {
81
if (account_deletion_error == null) {
82
return;
83
}
84
return <ErrorDisplay error={account_deletion_error} />;
85
}
86
87
return (
88
<Alert
89
showIcon
90
type="warning"
91
style={{
92
marginTop: "26px",
93
}}
94
message={
95
<FormattedMessage
96
id="account.delete-account.alert.message"
97
defaultMessage={"Are you sure you want to DELETE YOUR ACCOUNT?"}
98
/>
99
}
100
description={
101
<div>
102
<br />
103
<FormattedMessage
104
id="account.delete-account.alert.description"
105
defaultMessage={`You will <b>immediately</b> lose access to <b>all</b> of your projects,
106
any subscriptions will be canceled, and all unspent credit will be lost.
107
{br}
108
{hr}
109
To DELETE YOUR ACCOUNT, first enter "{required_text}" below:`}
110
values={{
111
required_text: required_text,
112
br: <br />,
113
hr: <hr style={{ marginTop: "10px", marginBottom: "10px" }} />,
114
}}
115
/>
116
<br />
117
<Input
118
autoFocus
119
value={confirmation_text}
120
placeholder="Full name"
121
type="text"
122
onChange={(e) => {
123
set_confirmation_text((e.target as any).value);
124
}}
125
style={{
126
margin: "15px",
127
width: "90%",
128
}}
129
/>
130
<div style={{ display: "flex" }}>
131
<Button
132
type="primary"
133
onClick={cancel_click}
134
style={{ marginRight: "15px" }}
135
>
136
<CancelText />
137
</Button>
138
<Button
139
disabled={confirmation_text !== required_text}
140
onClick={() => confirm_click()}
141
>
142
<Icon name="trash" />{" "}
143
{intl.formatMessage({
144
id: "account.delete-account.confirmation",
145
defaultMessage: "Yes, DELETE MY ACCOUNT",
146
})}
147
</Button>
148
</div>
149
{render_error()}
150
</div>
151
}
152
/>
153
);
154
}
155
156