Path: blob/master/src/packages/next/components/auth/in-place-sign-in-or-up.tsx
6265 views
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// TODO: below we need to get the strategies!6// and also requiresToken for SignUp!7import { Icon } from "@cocalc/frontend/components/icon";8import { Divider } from "antd";9import SignInAuth from "components/auth/sign-in";10import SignUpAuth from "components/auth/sign-up";11import { useRouter } from "next/router";12import { CSSProperties, ReactNode, useState } from "react";1314import { AUTH_WRAPPER_STYLE } from "./shared";1516type SelectedView = "sign-in" | "sign-up" | "compact";1718interface InPlaceOrSignUpProps {19title?: ReactNode;20why?: ReactNode;21defaultView?: SelectedView;22onSuccess?: () => void;23style?: CSSProperties;24has_site_license?: boolean;25publicPathId?: string;26minimal?: boolean;27}2829export default function InPlaceSignInOrUp({30title = "Sign in or sign up",31defaultView = "compact",32why,33onSuccess,34style,35has_site_license,36publicPathId,37}: InPlaceOrSignUpProps) {38const router = useRouter();39const [show, setShow] = useState<SelectedView>(defaultView);4041return (42<div style={{ ...style, ...AUTH_WRAPPER_STYLE }}>43<Divider>44<Icon name="sign-in" style={{ marginRight: "10px" }} /> {title}45</Divider>46<div style={{ fontSize: "11pt", marginTop: "8px", padding: "8px" }}>47<a onClick={() => setShow("sign-in")}>Sign In</a> {" or "}48<a onClick={() => setShow("sign-up")}>Sign Up</a>49{why ? ` ${why}` : ""}.50</div>51{show === "sign-up" && (52<SignUpAuth53minimal54requireTags={false}55has_site_license={has_site_license}56publicPathId={publicPathId}57onSuccess={58onSuccess ??59(() =>60router.push({61pathname: router.asPath.split("?")[0],62query: { edit: "true" },63}))64}65/>66)}67{show === "sign-in" && (68<SignInAuth69minimal70onSuccess={71onSuccess ??72(() =>73router.push({74pathname: router.asPath.split("?")[0],75query: { edit: "true" },76}))77}78/>79)}80</div>81);82}838485