11import { useQuery , useSuspenseQuery } from '@tanstack/react-query' ;
22import { appId } from '@src/constants' ;
3- import { LibraryMetadata , TeamMember } from '@src/types' ;
3+ import { LibraryMetadata } from '@src/types' ;
44import {
5- getLibrary , getPermissionsByRole , getTeamMembers , PermissionsByRole , QuerySettings ,
5+ getLibrary , getPermissionsByRole , getTeamMembers , GetTeamMembersResponse , PermissionsByRole , QuerySettings ,
66} from './api' ;
77
88const authzQueryKeys = {
99 all : [ appId , 'authz' ] as const ,
10- teamMembers : ( object : string , querySettings ?: QuerySettings ) => [
11- ...authzQueryKeys . all ,
12- 'teamMembers' ,
13- object ,
14- querySettings ?. roles ?? null ,
15- querySettings ?. search ?? null ,
16- querySettings ?. ordering ?? null ,
17- querySettings ?. pageSize ?? 10 ,
18- querySettings ?. pageIndex ?? 0 ,
19- ] as const ,
10+ teamMembersAll : ( scope : string ) => [ ...authzQueryKeys . all , 'teamMembers' , scope ] as const ,
11+ teamMembers : ( scope : string , querySettings ?: QuerySettings ) => [
12+ ...authzQueryKeys . teamMembersAll ( scope ) , querySettings ] as const ,
2013 permissionsByRole : ( scope : string ) => [ ...authzQueryKeys . all , 'permissionsByRole' , scope ] as const ,
2114 library : ( libraryId : string ) => [ ...authzQueryKeys . all , 'library' , libraryId ] as const ,
2215} ;
@@ -25,24 +18,20 @@ const authzQueryKeys = {
2518 * React Query hook to fetch all team members for a specific object/scope.
2619 * It retrieves the full list of members who have access to the given scope.
2720 *
28- * @param object - The unique identifier of the object/scope
21+ * @param scope - The unique identifier of the object/scope
2922 * @param querySettings - Optional query parameters for filtering, sorting, and pagination
3023 *
3124 * @example
3225 * ```tsx
3326 * const { data: teamMembers, isLoading, isError } = useTeamMembers('lib:123', querySettings);
3427 * ```
3528 */
36- export const useTeamMembers = ( object : string , querySettings : QuerySettings ) => {
37- const queryKey = authzQueryKeys . teamMembers ( object , querySettings ) ;
38-
39- return useQuery < TeamMember [ ] , Error > ( {
40- queryKey,
41- queryFn : ( ) => getTeamMembers ( object , querySettings ) ,
42- staleTime : 1000 * 60 * 30 , // refetch after 30 minutes
43- refetchOnWindowFocus : false ,
44- } ) ;
45- } ;
29+ export const useTeamMembers = ( scope : string , querySettings : QuerySettings ) => useQuery < GetTeamMembersResponse , Error > ( {
30+ queryKey : authzQueryKeys . teamMembers ( scope , querySettings ) ,
31+ queryFn : ( ) => getTeamMembers ( scope , querySettings ) ,
32+ staleTime : 1000 * 60 * 30 , // refetch after 30 minutes
33+ refetchOnWindowFocus : false ,
34+ } ) ;
4635
4736/**
4837 * React Query hook to fetch all the roles for the specific object/scope.
0 commit comments