25 lines
837 B
TypeScript
25 lines
837 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { SPONSOR_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { enhanceQueryResult } from '@/lib/di/hooks/useReactQueryWithApiError';
|
|
|
|
export function useSponsorshipRequests(entityType: string, entityId: string) {
|
|
const sponsorshipService = useInject(SPONSOR_SERVICE_TOKEN);
|
|
|
|
const queryResult = useQuery({
|
|
queryKey: ['sponsorshipRequests', entityType, entityId],
|
|
queryFn: async () => {
|
|
const result = await (sponsorshipService as any).getPendingSponsorshipRequests({
|
|
entityType,
|
|
entityId,
|
|
});
|
|
if (result.isErr()) {
|
|
throw result.getError();
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
enabled: !!entityType && !!entityId,
|
|
});
|
|
|
|
return enhanceQueryResult(queryResult);
|
|
} |