style: fix linter issues and data location
This commit is contained in:
committed by
Adolfo R. Brandes
parent
651ded21a7
commit
727bf74049
37
src/authz-module/data/hooks.ts
Normal file
37
src/authz-module/data/hooks.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
||||
import { LibraryMetadata, TeamMember } from '@src/types';
|
||||
import { getLibrary, getTeamMembers } from './api';
|
||||
|
||||
/**
|
||||
* React Query hook to fetch all team members for a specific object/scope.
|
||||
* It retrieves the full list of members who have access to the given scope.
|
||||
*
|
||||
* @param object - The unique identifier of the object/scope
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { data: teamMembers, isLoading, isError } = useTeamMembers('lib:123');
|
||||
* ```
|
||||
*/
|
||||
export const useTeamMembers = (object: string) => useQuery<TeamMember[], Error>({
|
||||
queryKey: ['team-members', object],
|
||||
queryFn: () => getTeamMembers(object),
|
||||
staleTime: 1000 * 60 * 30, // refetch after 30 minutes
|
||||
});
|
||||
|
||||
/**
|
||||
* React Query hook to retrieve the information of the current library.
|
||||
*
|
||||
* @param libraryId - The unique ID of the library.
|
||||
*
|
||||
* @example
|
||||
* const { data } = useLibrary('lib:123',);
|
||||
*
|
||||
*/
|
||||
export const useLibrary = (libraryId: string) => {
|
||||
return useSuspenseQuery<LibraryMetadata, Error>({
|
||||
queryKey: ['library-metadata', libraryId],
|
||||
queryFn: () => getLibrary(libraryId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user