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