4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { User } from "@gitpod/gitpod-protocol" ;
8
7
import { useQuery , useQueryClient } from "@tanstack/react-query" ;
9
8
import { useCallback } from "react" ;
10
9
import { useLocation } from "react-router" ;
@@ -15,19 +14,20 @@ import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
15
14
16
15
export function useOrganizationsInvalidator ( ) {
17
16
const user = useCurrentUser ( ) ;
17
+
18
18
const queryClient = useQueryClient ( ) ;
19
19
return useCallback ( ( ) => {
20
- console . log ( "Invalidating orgs... " + JSON . stringify ( getQueryKey ( user ) ) ) ;
21
- queryClient . invalidateQueries ( getQueryKey ( user ) ) ;
22
- } , [ user , queryClient ] ) ;
20
+ console . log ( "Invalidating orgs... " + JSON . stringify ( getQueryKey ( user ?. id ) ) ) ;
21
+ queryClient . invalidateQueries ( getQueryKey ( user ?. id ) ) ;
22
+ } , [ user ?. id , queryClient ] ) ;
23
23
}
24
24
25
25
export function useOrganizations ( ) {
26
26
const user = useCurrentUser ( ) ;
27
27
const query = useQuery < Organization [ ] , Error > (
28
- getQueryKey ( user ) ,
28
+ getQueryKey ( user ?. id ) ,
29
29
async ( ) => {
30
- console . log ( "Fetching orgs... " + JSON . stringify ( getQueryKey ( user ) ) ) ;
30
+ console . log ( "Fetching orgs... " + JSON . stringify ( getQueryKey ( user ?. id ) ) ) ;
31
31
if ( ! user ) {
32
32
console . log ( "useOrganizations with empty user" ) ;
33
33
return [ ] ;
@@ -47,8 +47,8 @@ export function useOrganizations() {
47
47
return query ;
48
48
}
49
49
50
- function getQueryKey ( user ?: User ) {
51
- return noPersistence ( [ "organizations" , user ?. id ] ) ;
50
+ function getQueryKey ( userId ?: string ) {
51
+ return noPersistence ( [ "organizations" , userId ] ) ;
52
52
}
53
53
54
54
// Custom hook to return the current org if one is selected
0 commit comments