diff --git a/src/frontend/apps/desk/src/features/teams/api/index.ts b/src/frontend/apps/desk/src/features/teams/api/index.ts index 7021b9c..5b969f5 100644 --- a/src/frontend/apps/desk/src/features/teams/api/index.ts +++ b/src/frontend/apps/desk/src/features/teams/api/index.ts @@ -1,3 +1,5 @@ +export * from './types'; export * from './useCreateTeam'; export * from './useTeam'; export * from './useTeams'; +export * from './useTeamsAccesses'; diff --git a/src/frontend/apps/desk/src/features/teams/api/types.tsx b/src/frontend/apps/desk/src/features/teams/api/types.tsx index 8e571d4..180905d 100644 --- a/src/frontend/apps/desk/src/features/teams/api/types.tsx +++ b/src/frontend/apps/desk/src/features/teams/api/types.tsx @@ -7,7 +7,7 @@ enum Role { export interface Access { id: string; role: Role; - user: string; + user: User; } export interface Team { @@ -17,3 +17,9 @@ export interface Team { created_at: string; updated_at: string; } + +export interface User { + id: string; + email: string; + name?: string; +} diff --git a/src/frontend/apps/desk/src/features/teams/api/useTeamsAccesses.tsx b/src/frontend/apps/desk/src/features/teams/api/useTeamsAccesses.tsx new file mode 100644 index 0000000..123a0b7 --- /dev/null +++ b/src/frontend/apps/desk/src/features/teams/api/useTeamsAccesses.tsx @@ -0,0 +1,41 @@ +import { UseQueryOptions, useQuery } from '@tanstack/react-query'; + +import { APIError, APIList, errorCauses, fetchAPI } from '@/api'; + +import { Access } from './types'; + +export type TeamAccessesAPIParams = { + page: number; + teamId: string; +}; + +type AccessesResponse = APIList; + +export const getTeamAccesses = async ({ + page, + teamId, +}: TeamAccessesAPIParams): Promise => { + const response = await fetchAPI(`teams/${teamId}/accesses/?page=${page}`); + + if (!response.ok) { + throw new APIError( + 'Failed to get the team accesses', + await errorCauses(response), + ); + } + + return response.json() as Promise; +}; + +export const KEY_LIST_TEAM_ACCESSES = 'teams-accesses'; + +export function useTeamAccesses( + params: TeamAccessesAPIParams, + queryConfig?: UseQueryOptions, +) { + return useQuery({ + queryKey: [KEY_LIST_TEAM_ACCESSES, params], + queryFn: () => getTeamAccesses(params), + ...queryConfig, + }); +}