"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"; interface StatusLabel { id: string; name: string; class: string; statusType: string; kanbanCol: boolean | string; sortKey: number | string; } interface Project { id: number; name: string; labels: StatusLabel[]; } export function Flow() { const [projects, setProjects] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [retryTimeout, setRetryTimeout] = useState(null); const fetchStatusLabels = async (isRefresh = false) => { try { if (isRefresh) { setRefreshing(true); } const response = await fetch('/api/leantime/status-labels'); if (response.status === 429) { const retryAfter = parseInt(response.headers.get('retry-after') || '60'); const timeout = setTimeout(() => fetchStatusLabels(), retryAfter * 1000); setRetryTimeout(timeout); setError(`Rate limit exceeded. Retrying in ${retryAfter} seconds...`); return; } if (!response.ok) { throw new Error('Failed to fetch status labels'); } const data = await response.json(); if (data.projects && Array.isArray(data.projects)) { setProjects(data.projects); } else { setProjects([]); } setError(null); } catch (err) { console.error('Error fetching status labels:', err); setError('Failed to fetch status labels'); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { fetchStatusLabels(); return () => { if (retryTimeout) { clearTimeout(retryTimeout); } }; }, []); return ( Flow {loading ? (
) : error ? (
{error}
) : projects.length === 0 ? (
No status labels found
) : (
{projects.map((project) => (

{project.name}

{project.labels.map((label) => (
{label.name}
{label.statusType}
))}
))}
)} ); } function getLabelClass(className: string): string { const classMap: Record = { 'label-default': 'bg-gray-100 text-gray-800', 'label-success': 'bg-green-100 text-green-800', 'label-warning': 'bg-yellow-100 text-yellow-800', 'label-info': 'bg-blue-100 text-blue-800', 'label-blue': 'bg-blue-100 text-blue-800', 'label-darker-blue': 'bg-indigo-100 text-indigo-800', 'label-dark-green': 'bg-emerald-100 text-emerald-800', 'label-important': 'bg-red-100 text-red-800', }; return classMap[className] || 'bg-gray-100 text-gray-800'; }