"use client"; import { useEffect, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw } from "lucide-react"; import { useRouter } from "next/navigation"; import { useSession } from "next-auth/react"; interface StatusLabel { id: string; name: string; statusType: string; class: string; sortKey: number; kanbanCol: boolean; } interface Project { projectId: string; labels: StatusLabel[]; } export function Flow() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [refreshing, setRefreshing] = useState(false); const router = useRouter(); const { data: session } = useSession(); const fetchStatusLabels = async (isRefresh = false) => { try { if (isRefresh) { setRefreshing(true); } const response = await fetch('/api/leantime/status-labels', { cache: 'no-store', next: { revalidate: 0 }, }); if (response.status === 401) { setError('Session expired. Please sign in again.'); return; } if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || 'Failed to fetch status labels'); } const data = await response.json(); setProjects(data.projects); setError(null); } catch (err) { console.error('Error fetching status labels:', err); const errorMessage = err instanceof Error ? err.message : 'Failed to fetch status labels'; setError(errorMessage); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { if (session) { fetchStatusLabels(); // Set up polling every 5 minutes const interval = setInterval(() => fetchStatusLabels(), 300000); return () => clearInterval(interval); } }, [session]); return ( router.push('/flow')} > Flow {loading &&

Loading status labels...

} {error && (

Error: {error}

)} {!loading && !error && (
{projects.length === 0 ? (

No status labels found

) : ( projects.map((project) => (

Project {project.projectId}

{project.labels.map((label) => (

{label.name}

{label.statusType}
))}
)) )}
)}
); }