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/table-error.tsx
Views: 687
1
/*
2
Show an error if something goes wrong trying to save
3
the account settings table to the database.
4
*/
5
6
import { Alert } from "antd";
7
import { useTypedRedux } from "../app-framework";
8
9
export default function AccountTableError() {
10
const tableError = useTypedRedux("account", "tableError");
11
if (!tableError) return null;
12
13
const { error, query } = tableError.toJS();
14
15
let obj;
16
try {
17
// this should work.
18
obj = query[0]["accounts"];
19
delete query["account_id"];
20
} catch (_err) {
21
obj = query;
22
}
23
24
let description;
25
if (obj["name"] != null) {
26
// Issue trying to set the username.
27
description =
28
"Please try a different username. Names can be between 1 and 39 characters, contain upper and lower case letters, numbers, and dashes.";
29
} else {
30
description = (
31
<>
32
There was an error trying to save an account setting to the server. In
33
particular, the following change failed:
34
<pre style={{ margin: "30px" }}>
35
{JSON.stringify(obj, undefined, 2)}
36
</pre>
37
Try changing the relevant field below.
38
</>
39
);
40
}
41
42
return (
43
<div style={{ width: "100%" }}>
44
<Alert
45
style={{ margin: "15px auto", maxWidth: "900px" }}
46
message={<b>{error}</b>}
47
description={description}
48
type="error"
49
/>
50
</div>
51
);
52
}
53
54