22 lines
623 B
TypeScript
22 lines
623 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { TEAM_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
|
|
|
export function useAllTeams() {
|
|
const teamService = useInject(TEAM_SERVICE_TOKEN);
|
|
|
|
const queryResult = useQuery({
|
|
queryKey: ['allTeams'],
|
|
queryFn: async () => {
|
|
const result = await teamService.getAllTeams();
|
|
if (result.isErr()) {
|
|
throw result.getError();
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
});
|
|
|
|
return enhanceQueryResult(queryResult);
|
|
}
|