Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/account/config/anonymous/upgrade.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Button, Input, Space } from "antd";6import { delay } from "awaiting";7import { CSSProperties, useState } from "react";89import { Icon } from "@cocalc/frontend/components/icon";10import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";11import { TermsCheckbox } from "components/auth/sign-up";12import SSO from "components/auth/sso";13import { Title } from "components/misc";14import apiPost from "lib/api/post";15import { useRouter } from "next/router";1617interface Props {18style: CSSProperties;19}2021export default function Upgrade({ style }: Props) {22const [terms, setTerms] = useState<boolean>(false);23return (24<div style={style}>25<TermsCheckbox onChange={setTerms} checked={terms} />26<br />27<br />28{terms && <EmailPassword />}29<br />30<br />31{terms && (32<SSO33style={{ margin: "30px 0" }}34header={<Title level={3}>Or Use Single Sign On</Title>}35/>36)}37</div>38);39}4041function EmailPassword() {42const router = useRouter();43const [success, setSuccess] = useState<boolean>(false);44const [error, setError] = useState<string>("");45const [email_address, setEmailAddress] = useState<string>("");46const [password, setPassword] = useState<string>("");47async function setEmailAndPassword() {48setError("");49try {50await apiPost("/accounts/set-email-address", {51email_address,52password,53});54setSuccess(true);55// send them to configure their name, which is a good next step...56router.push("/config/account/name");57await delay(1000);58// need to force reload to know that they are no longer anonymous.59router.reload();60} catch (err) {61setError(err.message);62}63}64return (65<>66<Title level={3}>Set an Email Address and Password</Title>67{error && (68<Alert69type="error"70showIcon71message={error}72style={{ marginTop: "15px" }}73/>74)}75<Space style={{ width: "100%" }}>76<Input77disabled={success}78style={{ fontSize: "12pt" }}79placeholder="Email address"80autoComplete="username"81value={email_address}82onChange={(e) => {83setEmailAddress(e.target.value);84setError("");85}}86/>87<Input.Password88disabled={success}89style={{ fontSize: "12pt" }}90value={password}91placeholder="Password"92autoComplete="new-password"93onChange={(e) => {94setPassword(e.target.value);95setError("");96}}97onPressEnter={setEmailAndPassword}98/>99{/* change height of button to match input boxes */}100<Button101type="primary"102disabled={success || !email_address || password.length < 6}103style={{ height: "35px" }}104onClick={setEmailAndPassword}105>106{success ? (107<>108<Icon name="check" style={{ marginRight: "5px" }} /> Saved109</>110) : email_address.length > 0 &&111!isValidEmailAddress(email_address) ? (112"Enter valid email"113) : password.length > 0 && password.length < 6 ? (114"At least 6 characters"115) : (116<>117<Icon name="check" style={{ marginRight: "5px" }} /> Save118</>119)}120</Button>121</Space>122</>123);124}125126127