44 * See License.AGPL.txt in the project root for license information.
55 */
66
7- import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb" ;
87import { useQuery , useQueryClient } from "@tanstack/react-query" ;
98import { useCallback } from "react" ;
109import { useLocation } from "react-router" ;
@@ -15,19 +14,20 @@ import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
1514
1615export function useOrganizationsInvalidator ( ) {
1716 const user = useCurrentUser ( ) ;
17+
1818 const queryClient = useQueryClient ( ) ;
1919 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 ] ) ;
2323}
2424
2525export function useOrganizations ( ) {
2626 const user = useCurrentUser ( ) ;
2727 const query = useQuery < Organization [ ] , Error > (
28- getQueryKey ( user ) ,
28+ getQueryKey ( user ?. id ) ,
2929 async ( ) => {
30- console . log ( "Fetching orgs... " + JSON . stringify ( getQueryKey ( user ) ) ) ;
30+ console . log ( "Fetching orgs... " + JSON . stringify ( getQueryKey ( user ?. id ) ) ) ;
3131 if ( ! user ) {
3232 console . log ( "useOrganizations with empty user" ) ;
3333 return [ ] ;
@@ -47,8 +47,8 @@ export function useOrganizations() {
4747 return query ;
4848}
4949
50- function getQueryKey ( user ?: User ) {
51- return noPersistence ( [ "organizations" , user ?. id ] ) ;
50+ function getQueryKey ( userId ?: string ) {
51+ return noPersistence ( [ "organizations" , userId ] ) ;
5252}
5353
5454// Custom hook to return the current org if one is selected
0 commit comments