Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/dedicated-setup/OrgNamingStep.tsx
2506 views
1
/**
2
* Copyright (c) 2023 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 { FC, useCallback, useState } from "react";
8
import { SetupLayout } from "./SetupLayout";
9
import { Heading1, Subheading } from "../components/typography/headings";
10
import { TextInputField } from "../components/forms/TextInputField";
11
import { useOnBlurError } from "../hooks/use-onblur-error";
12
import { useCreateOrgMutation } from "../data/organizations/create-org-mutation";
13
import Alert from "../components/Alert";
14
import { useCurrentOrg } from "../data/organizations/orgs-query";
15
import { useUpdateOrgMutation } from "../data/organizations/update-org-mutation";
16
import { LoadingButton } from "@podkit/buttons/LoadingButton";
17
18
type Props = {
19
onComplete: () => void;
20
progressCurrent?: number;
21
progressTotal?: number;
22
};
23
export const OrgNamingStep: FC<Props> = ({ onComplete, progressCurrent, progressTotal }) => {
24
const org = useCurrentOrg();
25
const [orgName, setOrgName] = useState(org.data?.name ?? "");
26
const createOrg = useCreateOrgMutation();
27
const updateOrg = useUpdateOrgMutation();
28
29
const handleContinue = useCallback(
30
(e) => {
31
e.preventDefault();
32
33
if (org.data) {
34
updateOrg.mutate({ name: orgName }, { onSuccess: onComplete });
35
} else {
36
createOrg.mutate(
37
{ name: orgName },
38
{
39
onSuccess: (newOrg) => {
40
// Need to manually set active-org here so it's returned via subsequent useCurrentOrg() calls
41
localStorage.setItem("active-org", newOrg.id);
42
onComplete();
43
},
44
},
45
);
46
}
47
},
48
[createOrg, onComplete, org.data, orgName, updateOrg],
49
);
50
51
const nameError = useOnBlurError("Please provide a name", orgName.trim().length > 0);
52
53
return (
54
<SetupLayout progressCurrent={progressCurrent} progressTotal={progressTotal}>
55
<div className="mb-10">
56
<Heading1>Name your organization</Heading1>
57
<Subheading>
58
Your Gitpod organization allows you to manage settings, projects and collaborate with teammates.
59
</Subheading>
60
</div>
61
{(createOrg.isError || updateOrg.isError) && (
62
<Alert type="danger">{createOrg.error?.message || updateOrg.error?.message}</Alert>
63
)}
64
<form onSubmit={handleContinue}>
65
<TextInputField
66
label="Organization Name"
67
placeholder="e.g. ACME Inc"
68
hint="The name of your company or organization."
69
value={orgName}
70
error={nameError.message}
71
onChange={setOrgName}
72
onBlur={nameError.onBlur}
73
/>
74
<div className="mt-6">
75
<LoadingButton
76
type="submit"
77
className="w-full"
78
disabled={!nameError.isValid}
79
loading={createOrg.isLoading || updateOrg.isLoading}
80
>
81
Continue
82
</LoadingButton>
83
</div>
84
</form>
85
</SetupLayout>
86
);
87
};
88
89