-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b62051
commit 52a39ca
Showing
14 changed files
with
154 additions
and
89 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
29 changes: 29 additions & 0 deletions
29
components/dashboard/src/data/organizations/org-invitation-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,29 @@ | ||
/** | ||
* 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 { useQuery } from "@tanstack/react-query"; | ||
import { useCurrentOrg } from "./orgs-query"; | ||
import { teamsService } from "../../service/public-api"; | ||
|
||
export const useOrgInvitationQuery = () => { | ||
const org = useCurrentOrg().data; | ||
|
||
return useQuery<{ invitationId?: string }>({ | ||
queryKey: getOrgInvitationQueryKey(org?.id ?? ""), | ||
staleTime: 1000 * 60 * 10, // 10 minute | ||
queryFn: async () => { | ||
if (!org) { | ||
throw new Error("No org selected."); | ||
} | ||
|
||
const resp = await teamsService.getTeamInvitation({ teamId: org.id }); | ||
return { invitationId: resp.teamInvitation?.id }; | ||
}, | ||
enabled: !!org, | ||
}); | ||
}; | ||
|
||
export const getOrgInvitationQueryKey = (orgId: string) => ["org-invitation", { orgId }]; |
42 changes: 42 additions & 0 deletions
42
components/dashboard/src/data/organizations/org-members-info-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,42 @@ | ||
/** | ||
* 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 { OrgMemberInfo } from "@gitpod/gitpod-protocol"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useCurrentOrg } from "./orgs-query"; | ||
import { publicApiTeamMembersToProtocol, teamsService } from "../../service/public-api"; | ||
import { useCurrentUser } from "../../user-context"; | ||
import { TeamRole } from "@gitpod/public-api/lib/gitpod/experimental/v1/teams_pb"; | ||
|
||
export interface OrgMembersInfo { | ||
members: OrgMemberInfo[]; | ||
isOwner: boolean; | ||
} | ||
|
||
export const useOrgMembersInfoQuery = () => { | ||
const user = useCurrentUser(); | ||
const org = useCurrentOrg().data; | ||
|
||
return useQuery<OrgMembersInfo>({ | ||
queryKey: getOrgMembersInfoQueryKey(org?.id ?? "", user?.id ?? ""), | ||
staleTime: 1000 * 60 * 5, // 5 minute | ||
queryFn: async () => { | ||
if (!org) { | ||
throw new Error("No org selected."); | ||
} | ||
const resp = await teamsService.listTeamMembers({ teamId: org.id }); | ||
return { | ||
members: publicApiTeamMembersToProtocol(resp.members), | ||
isOwner: | ||
resp.members.findIndex((member) => member.userId === user?.id && member.role === TeamRole.OWNER) >= | ||
0, | ||
}; | ||
}, | ||
enabled: !!org && !!user, | ||
}); | ||
}; | ||
|
||
export const getOrgMembersInfoQueryKey = (orgId: string, userId: string) => ["org-members", { orgId, userId }]; |
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
Oops, something went wrong.