Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/organizations/update-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 { useCurrentOrg, 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 UpdateOrgArgs = Pick<Organization, "name">;
13
14
export const useUpdateOrgMutation = () => {
15
const org = useCurrentOrg().data;
16
const invalidateOrgs = useOrganizationsInvalidator();
17
18
return useMutation<Organization, Error, UpdateOrgArgs>({
19
mutationFn: async ({ name }) => {
20
if (!org) {
21
throw new Error("No current organization selected");
22
}
23
24
const response = await organizationClient.updateOrganization({
25
organizationId: org.id,
26
name,
27
});
28
return response.organization!;
29
},
30
onSuccess(updatedOrg) {
31
// TODO: Update query cache with new org prior to invalidation so it's reflected immediately
32
invalidateOrgs();
33
},
34
});
35
};
36
37