Path: blob/main/components/dashboard/src/teams/NewTeam.tsx
2501 views
/**1* Copyright (c) 2021 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { ConnectError } from "@connectrpc/connect";7import { FormEvent, useState } from "react";8import { useHistory } from "react-router-dom";9import { Heading1, Heading3, Subheading } from "../components/typography/headings";10import { useOrganizationsInvalidator } from "../data/organizations/orgs-query";11import { useDocumentTitle } from "../hooks/use-document-title";12import { organizationClient } from "../service/public-api";13import { Button } from "@podkit/buttons/Button";14import { TextInputField } from "../components/forms/TextInputField";15import { cn } from "@podkit/lib/cn";1617export default function NewTeamPage() {18useDocumentTitle("New Organization");1920const invalidateOrgs = useOrganizationsInvalidator();21const [name, setName] = useState("");2223const history = useHistory();2425const [creationError, setCreationError] = useState<Error>();26const createTeam = async (event: FormEvent) => {27event.preventDefault();2829try {30const team = await organizationClient.createOrganization({ name });31invalidateOrgs();32// Redirects to the new Org's dashboard33history.push(`/workspaces/?org=${team.organization?.id}`);34} catch (error) {35console.error(error);36if (error instanceof ConnectError) {37setCreationError(new Error(error.rawMessage));38} else {39setCreationError(error);40}41}42};4344return (45<div className="flex flex-col w-96 mt-24 mx-auto items-center">46<Heading1>New Organization</Heading1>47<Subheading className="text-center">48<a href="https://www.gitpod.io/docs/configure/teams" className="gp-link">49Organizations50</a>{" "}51allow you to manage related{" "}52<a href="https://www.gitpod.io/docs/configure/repositories" className="gp-link">53repositories54</a>{" "}55and collaborate with other members.56</Subheading>57<form className="mt-6 mb-4" onSubmit={createTeam}>58<div className="rounded-xl p-6 bg-pk-surface-secondary">59<Heading3>You're creating a new organization</Heading3>60<Subheading>After creating an organization, you can invite others to join.</Subheading>6162<TextInputField63label="Organization Name"64value={name}65autoFocus66className={cn("w-full", { error: !!creationError })}67onChange={setName}68/>69{!!creationError && (70<p className="text-gitpod-red">71{creationError.message.replace(/Request \w+ failed with message: /, "")}72</p>73)}74</div>75<div className="flex flex-row-reverse space-x-2 space-x-reverse mt-2">76<Button type="submit">Create Organization</Button>77<Button variant="secondary" onClick={() => history.push("/")}>78Cancel79</Button>80</div>81</form>82</div>83);84}858687