Path: blob/master/src/packages/next/pages/auth/sign-up.tsx
6077 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Layout } from "antd";6import { GetServerSidePropsContext } from "next";7import { useRouter } from "next/router";89import getRequiresToken from "@cocalc/server/auth/tokens/get-requires-token";10import { gtag_id, sign_up_id } from "@cocalc/util/theme";11import SignUp from "components/auth/sign-up";12import Footer from "components/landing/footer";13import Head from "components/landing/head";14import Header from "components/landing/header";15import basePath from "lib/base-path";16import { Customize } from "lib/customize";17import withCustomize from "lib/with-customize";1819export default function SignUpPage({ customize, requiresToken, requireTags }) {20const { siteName, isCommercial } = customize;21const router = useRouter();2223function openRoot() {24router.push("/");25}2627async function onSuccess() {28if (isCommercial) {29try {30(window as any).gtag?.("event", "conversion", {31send_to: `${gtag_id}/${sign_up_id}`,32event_callback: openRoot,33});34} catch (err) {35console.warn("error sending gtag event", err);36}37}38router.push("/app?sign-in");39}4041return (42<Customize value={customize}>43<Head title={`Sign up for ${siteName}`} />44<Layout>45<Header page="sign-up" />46<Layout.Content style={{ backgroundColor: "white" }}>47<SignUp48requiresToken={requiresToken}49onSuccess={onSuccess}50requireTags={requireTags}51/>52<Footer />53</Layout.Content>54</Layout>55</Customize>56);57}5859export async function getServerSideProps(context: GetServerSidePropsContext) {60const customize = await withCustomize({ context });61if (customize.props.customize.account != null) {62// user is already signed in -- redirect them to top level page for now (todo).63const { res } = context;64res.writeHead(302, { location: basePath });65res.end();66return { props: { customize: {} } };67}68customize.props.requiresToken = await getRequiresToken();69// this field only has an effect, if we're on the cocalc.com site.70customize.props.requireTags =71process.env.COCALC_SIGNUP_REQUIRE_TAGS !== "false";72return customize;73}747576