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/licenses/layout.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Alert, Layout } from "antd";
7
8
import { COLORS } from "@cocalc/util/theme";
9
import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";
10
import Anonymous from "components/misc/anonymous";
11
import Loading from "components/share/loading";
12
import { MAX_WIDTH } from "lib/config";
13
import useProfile from "lib/hooks/profile";
14
import Error from "next/error";
15
import { useRouter } from "next/router";
16
import HowUsed from "./how-used";
17
import LicensedProjects from "./licensed-projects";
18
import ManagedLicenses from "./managed";
19
import Menu from "./menu";
20
import Overview from "./overview";
21
22
const { Content } = Layout;
23
24
interface Props {
25
page: ("projects" | "how-used" | "managed" | undefined)[];
26
}
27
28
export default function LicensesLayout({ page }: Props) {
29
const router = useRouter();
30
const profile = useProfile({ noCache: true });
31
if (!profile) {
32
return <Loading large center />;
33
}
34
const { account_id, is_anonymous } = profile;
35
36
if (!account_id) {
37
return (
38
<Alert
39
style={{ margin: "15px auto" }}
40
type="warning"
41
message={
42
<InPlaceSignInOrUp
43
title="Account Configuration"
44
why="to see information about your licenses"
45
onSuccess={() => {
46
router.reload();
47
}}
48
/>
49
}
50
/>
51
);
52
}
53
54
if (is_anonymous) {
55
return <Anonymous />;
56
}
57
58
const [main] = page;
59
60
function body() {
61
if (main == null) return <Overview />;
62
switch (main) {
63
case "projects":
64
return <LicensedProjects />;
65
case "managed":
66
return <ManagedLicenses />;
67
case "how-used":
68
return <HowUsed account_id={account_id} />;
69
default:
70
return <Error statusCode={404} />;
71
}
72
}
73
74
// this is layout the same way as ../store/index.tsx
75
return (
76
<Layout
77
style={{
78
padding: "0 24px 24px",
79
backgroundColor: "white",
80
color: COLORS.GRAY_D,
81
}}
82
>
83
<Content
84
style={{
85
margin: 0,
86
minHeight: "60vh",
87
}}
88
>
89
<div style={{ maxWidth: MAX_WIDTH, margin: "auto" }}>
90
<Menu main={main} />
91
{body()}
92
</div>
93
</Content>
94
</Layout>
95
);
96
}
97
98