website refactor
This commit is contained in:
21
apps/website/hooks/team/useAllTeams.ts
Normal file
21
apps/website/hooks/team/useAllTeams.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user