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/pages/auth/sign-up.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 { Layout } from "antd";
7
import { GetServerSidePropsContext } from "next";
8
import { useRouter } from "next/router";
9
import { join } from "path";
10
11
import getRequiresToken from "@cocalc/server/auth/tokens/get-requires-token";
12
import { gtag_id, sign_up_id } from "@cocalc/util/theme";
13
import SignUp from "components/auth/sign-up";
14
import Footer from "components/landing/footer";
15
import Head from "components/landing/head";
16
import Header from "components/landing/header";
17
import apiPost from "lib/api/post";
18
import basePath from "lib/base-path";
19
import { Customize } from "lib/customize";
20
import withCustomize from "lib/with-customize";
21
22
export default function SignUpPage({ customize, requiresToken, requireTags }) {
23
const { siteName, isCommercial } = customize;
24
const router = useRouter();
25
26
function openRoot() {
27
router.push("/");
28
}
29
30
async function onSuccess({ firstFile }) {
31
if (isCommercial) {
32
try {
33
(window as any).gtag?.("event", "conversion", {
34
send_to: `${gtag_id}/${sign_up_id}`,
35
event_callback: openRoot,
36
});
37
} catch (err) {
38
console.warn("error sending gtag event", err);
39
}
40
}
41
try {
42
// If you have at least one project, open the newest one.
43
const { project_id } = await apiPost("/projects/get-one");
44
if (project_id) {
45
let url = join(basePath, `/projects/${project_id}`);
46
if (firstFile) {
47
url = join(url, "files", firstFile);
48
}
49
window.location.href = url;
50
}
51
return;
52
} catch (_err) {
53
// no problem -- many situation where wouldn't have a project
54
}
55
openRoot();
56
}
57
58
return (
59
<Customize value={customize}>
60
<Head title={`Sign up for ${siteName}`} />
61
<Layout>
62
<Header page="sign-up" />
63
<Layout.Content style={{ backgroundColor: "white" }}>
64
<SignUp
65
requiresToken={requiresToken}
66
onSuccess={onSuccess}
67
requireTags={requireTags}
68
/>
69
<Footer />
70
</Layout.Content>
71
</Layout>
72
</Customize>
73
);
74
}
75
76
export async function getServerSideProps(context: GetServerSidePropsContext) {
77
const customize = await withCustomize({ context });
78
if (customize.props.customize.account != null) {
79
// user is already signed in -- redirect them to top level page for now (todo).
80
const { res } = context;
81
res.writeHead(302, { location: basePath });
82
res.end();
83
return { props: { customize: {} } };
84
}
85
customize.props.requiresToken = await getRequiresToken();
86
// this field only has an effect, if we're on the cocalc.com site.
87
customize.props.requireTags =
88
process.env.COCALC_SIGNUP_REQUIRE_TAGS !== "false";
89
return customize;
90
}
91
92