Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/organizations/create-org-mutation.ts
2501 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 { useMutation } from "@tanstack/react-query";
8
import { useOrganizationsInvalidator } from "./orgs-query";
9
import { organizationClient } from "../../service/public-api";
10
import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
11
12
type CreateOrgArgs = Pick<Organization, "name">;
13
14
export const useCreateOrgMutation = () => {
15
const invalidateOrgs = useOrganizationsInvalidator();
16
17
return useMutation<Organization, Error, CreateOrgArgs>({
18
mutationFn: async ({ name }) => {
19
const { organization } = await organizationClient.createOrganization({ name });
20
if (!organization) {
21
throw new Error("Error creating organization");
22
}
23
24
return organization;
25
},
26
onSuccess(newOrg) {
27
invalidateOrgs();
28
},
29
});
30
};
31
32