'use client'; import { useEffect, useState, useCallback } from 'react'; import ReportsView from '@/components/ReportsView'; import { listExecutions } from '@/lib/pipeline-api'; import type { ExecutionStatus } from '@/lib/pipeline-types'; import type { JobStatus } from '@/components/ScraperTest'; export default function ReportsPage() { const [executions, setExecutions] = useState([]); const [jobsMap, setJobsMap] = useState>(new Map()); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchData = useCallback(async () => { try { setLoading(true); setError(null); // Fetch executions and jobs in parallel const [executionsData, jobsResponse] = await Promise.all([ listExecutions('reviewiq', { limit: 100 }), fetch('/api/jobs?limit=100').then(r => r.json()) ]); setExecutions(executionsData); // Create a map of job_id -> job for quick lookup const map = new Map(); const jobsList = jobsResponse?.jobs || jobsResponse; if (Array.isArray(jobsList)) { jobsList.forEach((job: JobStatus) => { map.set(job.job_id, job); }); } setJobsMap(map); } catch (err) { console.error('Failed to fetch data:', err); setError(err instanceof Error ? err.message : 'Failed to load reports'); } finally { setLoading(false); } }, []); useEffect(() => { fetchData(); }, [fetchData]); if (loading) { return (

Reports

AI-generated business intelligence reports from ReviewIQ pipeline

Loading reports...
); } if (error) { return (

Reports

AI-generated business intelligence reports from ReviewIQ pipeline

Error loading reports

{error}

); } return (

Reports

AI-generated business intelligence reports from ReviewIQ pipeline

); }