25 lines
1017 B
TypeScript
25 lines
1017 B
TypeScript
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
|
import { LEAGUE_STEWARDING_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { ApiError } from '@/lib/gateways/api/base/ApiError';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
export function useProtestDetail(leagueId: string, protestId: string, enabled: boolean = true) {
|
|
const leagueStewardingService = useInject(LEAGUE_STEWARDING_SERVICE_TOKEN);
|
|
|
|
const queryResult = useQuery({
|
|
queryKey: ['protestDetail', leagueId, protestId],
|
|
queryFn: async () => {
|
|
const result = await leagueStewardingService.getProtestDetailViewModel(leagueId, protestId);
|
|
if (result.isErr()) {
|
|
const error = result.getError();
|
|
throw new ApiError(error.message, 'SERVER_ERROR', { timestamp: new Date().toISOString() });
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
enabled: enabled && !!leagueId && !!protestId,
|
|
});
|
|
|
|
return enhanceQueryResult(queryResult);
|
|
}
|