-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dashboard] use organization v2 shapes
- Loading branch information
1 parent
18e04fb
commit 0fbe813
Showing
53 changed files
with
2,457 additions
and
2,021 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
components/dashboard/src/data/organizations/invite-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import { useCallback } from "react"; | ||
import { organizationClient } from "../../service/public-api"; | ||
import { useCurrentOrg } from "./orgs-query"; | ||
|
||
export function useInviteInvalidator() { | ||
const organizationId = useCurrentOrg().data?.id; | ||
const queryClient = useQueryClient(); | ||
return useCallback(() => { | ||
queryClient.invalidateQueries(getQueryKey(organizationId)); | ||
}, [organizationId, queryClient]); | ||
} | ||
|
||
export function useInvitationId() { | ||
const organizationId = useCurrentOrg().data?.id; | ||
const query = useQuery<string, Error>( | ||
getQueryKey(organizationId), | ||
async () => { | ||
const response = await organizationClient.getOrganizationInvitation({ | ||
organizationId, | ||
}); | ||
return response.invitationId; | ||
}, | ||
{ | ||
enabled: !!organizationId, | ||
}, | ||
); | ||
return query; | ||
} | ||
|
||
export function useResetInvitationId() { | ||
const invalidate = useInviteInvalidator(); | ||
return useMutation<void, Error, string>({ | ||
mutationFn: async (orgId) => { | ||
if (!orgId) { | ||
throw new Error("No current organization selected"); | ||
} | ||
|
||
await organizationClient.resetOrganizationInvitation({ | ||
organizationId: orgId, | ||
}); | ||
//TODO update useInvitation Query | ||
}, | ||
onSuccess(updatedOrg) { | ||
invalidate(); | ||
}, | ||
}); | ||
} | ||
|
||
function getQueryKey(organizationId: string | undefined) { | ||
return ["invitationId", organizationId || "undefined"]; | ||
} |
54 changes: 54 additions & 0 deletions
54
components/dashboard/src/data/organizations/members-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { OrganizationMember, OrganizationRole } from "@gitpod/public-api/lib/gitpod/v1/organization_pb"; | ||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import { useCallback, useMemo } from "react"; | ||
import { organizationClient } from "../../service/public-api"; | ||
import { useCurrentUser } from "../../user-context"; | ||
import { useCurrentOrg } from "./orgs-query"; | ||
|
||
export function useOrganizationMembersInvalidator() { | ||
const organizationId = useCurrentOrg().data?.id; | ||
const queryClient = useQueryClient(); | ||
return useCallback(() => { | ||
queryClient.invalidateQueries(getQueryKey(organizationId)); | ||
}, [organizationId, queryClient]); | ||
} | ||
|
||
export function useListOrganizationMembers() { | ||
const organizationId = useCurrentOrg().data?.id; | ||
const query = useQuery<OrganizationMember[], Error>( | ||
getQueryKey(organizationId), | ||
async () => { | ||
const response = await organizationClient.listOrganizationMembers({ | ||
organizationId, | ||
pagination: { | ||
pageSize: 1000, | ||
}, | ||
}); | ||
return response.members; | ||
}, | ||
{ | ||
staleTime: 1000 * 60 * 5, // 5 minutes | ||
enabled: !!organizationId, | ||
}, | ||
); | ||
return query; | ||
} | ||
|
||
export function useIsOwner(): boolean { | ||
const user = useCurrentUser(); | ||
const members = useListOrganizationMembers(); | ||
const isOwner = useMemo(() => { | ||
return members?.data?.some((m) => m.userId === user?.id && m.role === OrganizationRole.OWNER); | ||
}, [members?.data, user?.id]); | ||
return !!isOwner; | ||
} | ||
|
||
function getQueryKey(organizationId: string | undefined) { | ||
return ["listOrganizationMembers", organizationId || "undefined"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.