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