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/landing/compute-server-templates.tsx
Views: 687
import PublicTemplates from "@cocalc/frontend/compute/public-templates";1import { useState } from "react";2import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";3import useProfile from "lib/hooks/profile";4import SelectProject from "components/project/select";5import basePath from "lib/base-path";6import { join } from "path";7import apiPost from "lib/api/post";89type State = "browse" | "sign-in" | "select-project";1011export default function ComputeServerTemplates({12style,13getPopupContainer,14}: {15style?;16getPopupContainer?;17}) {18const [id, setId0] = useState<number | null>(null);19const setId = (id) => {20setId0(id);21setState("browse");22};23const [state, setState] = useState<State>("browse");24const profile = useProfile({ noCache: true });25//const [account_id, setAccountId] = useState<string | null>(null);26return (27<div>28<PublicTemplates29getPopupContainer={getPopupContainer}30style={style}31setId={(id) => {32setId(id);33if (!id) {34setState("browse");35} else if (profile?.account_id) {36setState("select-project");37} else {38setState("sign-in");39}40}}41/>42{state == "sign-in" && (43<InPlaceSignInOrUp44title="Create Account"45why="to build your compute server"46onSuccess={() => {47setState("select-project");48}}49/>50)}51{state == "select-project" && (52<div style={{ maxWidth: "600px", margin: "auto" }}>53<SelectProject54label={"Select or Create Project for your Compute Server"}55defaultOpen56allowCreate57onChange={async ({ project_id, title }) => {58if (!project_id) {59// create the project60const response = await apiPost("/projects/create", {61title,62});63project_id = response.project_id;64if (!project_id) {65// didn't work -- TODO: show error66return;67}68}69window.location.href = join(70basePath,71"projects",72project_id,73`servers?compute-server-template=${id}.${project_id}`,74);75}}76/>77</div>78)}79</div>80);81}828384