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/next/components/account/config/layout.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Alert, Divider, Layout, Space } from "antd";
7
import { join } from "path";
8
9
import { Icon } from "@cocalc/frontend/components/icon";
10
import { capitalize } from "@cocalc/util/misc";
11
import { COLORS } from "@cocalc/util/theme";
12
import Avatar from "components/account/avatar";
13
import Config from "components/account/config";
14
import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";
15
import { Paragraph, Text, Title } from "components/misc";
16
import A from "components/misc/A";
17
import Loading from "components/share/loading";
18
import SiteName from "components/share/site-name";
19
import basePath from "lib/base-path";
20
import useIsBrowser from "lib/hooks/is-browser";
21
import useProfile from "lib/hooks/profile";
22
import { useRouter } from "next/router";
23
import Anonymous from "./anonymous";
24
import ConfigMenu from "./menu";
25
import { menu } from "./register";
26
import Search from "./search/component";
27
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
28
29
const { Content, Sider } = Layout;
30
31
interface Props {
32
page: string[]; // e.g. ["account", "name"]
33
}
34
35
export default function ConfigLayout({ page }: Props) {
36
const router = useRouter();
37
const isBrowser = useIsBrowser();
38
const profile = useProfile({ noCache: true });
39
if (!profile) {
40
return (
41
<div
42
style={{ textAlign: "center", minHeight: "400px", paddingTop: "100px" }}
43
>
44
<Loading large />
45
</div>
46
);
47
}
48
const { account_id, is_anonymous } = profile;
49
50
if (!account_id) {
51
return (
52
<Alert
53
style={{ margin: "15px auto" }}
54
type="warning"
55
message={
56
<InPlaceSignInOrUp
57
title="Account Configuration"
58
why="to edit your account configuration"
59
onSuccess={() => {
60
router.reload();
61
}}
62
/>
63
}
64
/>
65
);
66
}
67
68
if (is_anonymous) {
69
return <Anonymous />;
70
}
71
72
const [main, sub] = page;
73
const info = menu[main]?.[sub];
74
75
function renderIcon() {
76
const { icon } = info;
77
if (icon === "ai") {
78
return (
79
<AIAvatar
80
size={22}
81
style={{ position: "relative", top: "-12px", paddingRight: "15px" }}
82
/>
83
);
84
} else {
85
return <Icon name={icon} style={{ marginRight: "5px" }} />;
86
}
87
}
88
89
const content = (
90
<Content
91
style={{
92
padding: 24,
93
margin: 0,
94
minHeight: 500,
95
...(info?.danger
96
? { color: "#ff4d4f", backgroundColor: COLORS.ATND_BG_RED_L }
97
: undefined),
98
}}
99
>
100
<Space style={{ marginBottom: "15px" }}>
101
<Avatar account_id={account_id} style={{ marginRight: "15px" }} />
102
<div style={{ color: COLORS.GRAY }}>
103
<Text strong style={{ fontSize: "13pt" }}>
104
{profile?.first_name} {profile?.last_name}
105
{profile.name ? ` (@${profile.name})` : ""}
106
</Text>
107
<div>Your account</div>
108
</div>
109
</Space>
110
{main != "search" && <Search />}
111
{info && (
112
<>
113
<Title level={2}>
114
{renderIcon()} {capitalize(main)} - {info.title}
115
</Title>
116
<Paragraph type="secondary">{info.desc}</Paragraph>
117
<Divider />
118
</>
119
)}
120
{info?.desc?.toLowerCase().includes("todo") && (
121
<Alert
122
style={{ margin: "15px auto", maxWidth: "600px" }}
123
message={<b>Under Constructions</b>}
124
description={
125
<Paragraph>
126
This page is under construction. To configure your <SiteName />{" "}
127
account, visit{" "}
128
<A href={join(basePath, "settings")} external>
129
Account Preferences
130
</A>
131
.
132
</Paragraph>
133
}
134
type="warning"
135
showIcon
136
/>
137
)}
138
<Config main={main} sub={sub} />
139
</Content>
140
);
141
142
return (
143
<Layout>
144
<Sider width={"30ex"} breakpoint="sm" collapsedWidth="0">
145
{isBrowser && <ConfigMenu main={main} sub={sub} />}
146
</Sider>
147
<Layout
148
style={{
149
padding: "0",
150
backgroundColor: "white",
151
color: COLORS.GRAY_D,
152
maxWidth: "1200px",
153
}}
154
>
155
{content}
156
</Layout>
157
</Layout>
158
);
159
}
160
161