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/billing/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 { unreachable } from "@cocalc/util/misc";
7
import { COLORS } from "@cocalc/util/theme";
8
import { Alert, Layout } from "antd";
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 useCustomize from "lib/use-customize";
15
import { useRouter } from "next/router";
16
import { MainPagesType } from "./consts";
17
import InvoicesAndReceipts from "./invoices-and-receipts";
18
import Menu from "./menu";
19
import Overview from "./overview";
20
import PaymentMethods from "./payment-methods";
21
import Subscriptions from "./subscriptions";
22
23
const { Content } = Layout;
24
25
interface Props {
26
page: [MainPagesType | undefined]; // empty array is the overview page
27
}
28
29
export default function ConfigLayout({ page }: Props) {
30
const { isCommercial } = useCustomize();
31
const router = useRouter();
32
const profile = useProfile({ noCache: true });
33
if (!isCommercial) {
34
return (
35
<Alert
36
showIcon
37
style={{
38
margin: "30px auto",
39
maxWidth: "400px",
40
fontSize: "12pt",
41
padding: "15px 30px",
42
}}
43
type="warning"
44
message="Billing is not enabled for this server."
45
/>
46
);
47
}
48
if (!profile) {
49
return <Loading large center />;
50
}
51
const { account_id, is_anonymous } = profile;
52
53
if (!account_id) {
54
return (
55
<Alert
56
style={{ margin: "15px auto" }}
57
type="warning"
58
message={
59
<InPlaceSignInOrUp
60
title="Account Configuration"
61
why="to see information about your licenses"
62
onSuccess={() => {
63
router.reload();
64
}}
65
/>
66
}
67
/>
68
);
69
}
70
71
if (is_anonymous) {
72
return <Anonymous />;
73
}
74
75
// page could be an empty array, then main is undefined → overview page
76
const [main] = page;
77
78
function body() {
79
// main must be in MainPages defined in [[..page]].tsx
80
if (main == null) return <Overview />;
81
switch (main) {
82
case "cards":
83
return <PaymentMethods />;
84
case "subscriptions":
85
return <Subscriptions />;
86
case "receipts":
87
return <InvoicesAndReceipts />;
88
default:
89
unreachable(main);
90
}
91
}
92
93
// this layout is the same as ../store/index.tsx
94
return (
95
<Layout
96
style={{
97
padding: "0 24px 24px",
98
backgroundColor: "white",
99
color: COLORS.GRAY_D,
100
}}
101
>
102
<Content
103
style={{
104
margin: 0,
105
minHeight: "60vh",
106
}}
107
>
108
<div style={{ maxWidth: MAX_WIDTH, margin: "auto" }}>
109
<Menu main={main} />
110
{body()}
111
</div>
112
</Content>
113
</Layout>
114
);
115
}
116
117