'use client' /** * ProjectTable Component * * Displays a table of projects with admin actions (pause, resume, delete). * Includes loading states and error handling. */ import { useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { Trash2, Loader2 } from 'lucide-react' import { pauseProject, resumeProject, deleteProject, type Project, } from '@/app/actions/projects' interface ProjectTableProps { projects: Project[] isAdmin: boolean } export default function ProjectTable({ projects, isAdmin }: ProjectTableProps) { const router = useRouter() const [loadingAction, setLoadingAction] = useState(null) const [error, setError] = useState(null) const handlePause = async (projectId: string) => { if (!confirm('Are you sure you want to pause this project?')) { return } setLoadingAction(projectId) setError(null) const result = await pauseProject(projectId) if (!result.success) { setError(result.error || 'Failed to pause project') } else { router.refresh() } setLoadingAction(null) } const handleResume = async (projectId: string) => { setLoadingAction(projectId) setError(null) const result = await resumeProject(projectId) if (!result.success) { setError(result.error || 'Failed to resume project') } else { router.refresh() } setLoadingAction(null) } const handleDelete = async (projectId: string) => { if (!confirm('Are you sure you want to delete this project? This action cannot be undone.')) { return } setLoadingAction(projectId) setError(null) const result = await deleteProject(projectId) if (!result.success) { setError(result.error || 'Failed to delete project') } else { router.refresh() } setLoadingAction(null) } const getStatusBadge = (status: Project['status']) => { const styles = { provisioning: 'bg-amber-500/10 text-amber-500 border-amber-500/20', active: 'bg-[#3ECF8E]/10 text-[#3ECF8E] border-[#3ECF8E]/20', paused: 'bg-gray-500/10 text-gray-400 border-gray-500/20', failed: 'bg-red-500/10 text-red-500 border-red-500/20', deleted: 'bg-red-500/10 text-red-500 border-red-500/20', } return ( {status.charAt(0).toUpperCase() + status.slice(1)} ) } if (projects.length === 0) { return (

No projects found

Create Your First Project
) } return (
{/* Error Display */} {error && (

Error

{error}

)} {/* Table */}
{projects.map((project) => ( ))}
Project Name Reference Region Status Creator Created Actions
{project.project_name} {project.purpose && (

{project.purpose}

)}
{project.project_ref} {project.region} {getStatusBadge(project.status)} {project.creator_email} {new Date(project.created_at).toLocaleDateString()}
View {isAdmin && project.status !== 'deleted' && ( )}
) }