25 lines
989 B
TypeScript
25 lines
989 B
TypeScript
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
|
import { TEAM_JOIN_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { ApiError } from '@/lib/gateways/api/base/ApiError';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
export function useTeamJoinRequests(teamId: string, currentUserId: string, isOwner: boolean) {
|
|
const teamJoinService = useInject(TEAM_JOIN_SERVICE_TOKEN);
|
|
|
|
const queryResult = useQuery({
|
|
queryKey: ['teamJoinRequests', teamId, currentUserId, isOwner],
|
|
queryFn: async () => {
|
|
const result = await teamJoinService.getJoinRequests(teamId, currentUserId, isOwner);
|
|
if (result.isErr()) {
|
|
const error = result.getError();
|
|
throw new ApiError(error.message, 'SERVER_ERROR', { timestamp: new Date().toISOString() });
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
enabled: !!teamId && !!currentUserId,
|
|
});
|
|
|
|
return enhanceQueryResult(queryResult);
|
|
}
|