import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { Alert, AlertDescription } from '@/components/ui/alert' import { Project, ApiResponse } from 'shared/types' import { ProjectForm } from './project-form' import { Plus, Edit, Trash2, Calendar, AlertCircle, Loader2 } from 'lucide-react' export function ProjectList() { const [projects, setProjects] = useState([]) const [loading, setLoading] = useState(false) const [showForm, setShowForm] = useState(false) const [editingProject, setEditingProject] = useState(null) const [error, setError] = useState('') const fetchProjects = async () => { setLoading(true) setError('') try { const response = await fetch('/api/projects') const data: ApiResponse = await response.json() if (data.success && data.data) { setProjects(data.data) } else { setError('Failed to load projects') } } catch (error) { console.error('Failed to fetch projects:', error) setError('Failed to connect to server') } finally { setLoading(false) } } const handleDelete = async (id: string, name: string) => { if (!confirm(`Are you sure you want to delete "${name}"? This action cannot be undone.`)) return try { const response = await fetch(`/api/projects/${id}`, { method: 'DELETE', }) if (response.ok) { fetchProjects() } } catch (error) { console.error('Failed to delete project:', error) setError('Failed to delete project') } } const handleEdit = (project: Project) => { setEditingProject(project) setShowForm(true) } const handleFormSuccess = () => { setShowForm(false) setEditingProject(null) fetchProjects() } useEffect(() => { fetchProjects() }, []) return (

Projects

Manage your projects and track their progress

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

No projects yet

Get started by creating your first project.

) : (
{projects.map((project) => (
{project.name} Active
Created {new Date(project.created_at).toLocaleDateString()}
))}
)} { setShowForm(false) setEditingProject(null) }} onSuccess={handleFormSuccess} project={editingProject} />
) }