import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' 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 { makeAuthenticatedRequest } from '@/lib/auth' import { ArrowLeft, Edit, Trash2, Calendar, Clock, User, AlertCircle, Loader2, CheckSquare } from 'lucide-react' interface ProjectDetailProps { projectId: string onBack: () => void } export function ProjectDetail({ projectId, onBack }: ProjectDetailProps) { const navigate = useNavigate() const [project, setProject] = useState(null) const [loading, setLoading] = useState(false) const [showEditForm, setShowEditForm] = useState(false) const [error, setError] = useState('') const fetchProject = async () => { setLoading(true) setError('') try { const response = await makeAuthenticatedRequest(`/api/projects/${projectId}`) const data: ApiResponse = await response.json() if (data.success && data.data) { setProject(data.data) } else { setError('Project not found') } } catch (error) { console.error('Failed to fetch project:', error) setError('Failed to load project') } finally { setLoading(false) } } const handleDelete = async () => { if (!project) return if (!confirm(`Are you sure you want to delete "${project.name}"? This action cannot be undone.`)) return try { const response = await makeAuthenticatedRequest(`/api/projects/${projectId}`, { method: 'DELETE', }) if (response.ok) { onBack() } } catch (error) { console.error('Failed to delete project:', error) setError('Failed to delete project') } } const handleEditSuccess = () => { setShowEditForm(false) fetchProject() } useEffect(() => { fetchProject() }, [projectId]) if (loading) { return (
Loading project...
) } if (error || !project) { return (

Project not found

{error || 'The project you\'re looking for doesn\'t exist or has been deleted.'}

) } return (

{project.name}

Project details and settings

{error && ( {error} )}
Project Information
Status Active
Created: {new Date(project.created_at).toLocaleDateString()}
Last Updated: {new Date(project.updated_at).toLocaleDateString()}
Owner ID: {project.owner_id.substring(0, 8)}...
Project Details Technical information about this project

Project ID

{project.id}

Created At

{new Date(project.created_at).toLocaleString()}

Last Modified

{new Date(project.updated_at).toLocaleString()}

setShowEditForm(false)} onSuccess={handleEditSuccess} project={project} />
) }