commit 70cb0b9de2bdbb6b564a7e6fb3a926a104e1e17c Author: Louis Knight-Webb <louis@bloop.ai> Date: Tue Jun 17 14:16:45 2025 -0400 Update API commit 36a5161b96b8f034daa91d08d648be77fbdcb30b Author: Louis Knight-Webb <louis@bloop.ai> Date: Tue Jun 17 14:14:33 2025 -0400 Further auth removal commit cba24ffd462a3de178658f26231011ed4d28a78b Author: Louis Knight-Webb <louis@bloop.ai> Date: Tue Jun 17 14:03:13 2025 -0400 Fully remove users commit cfb1aec9b984c3374e5cc0ffe182de2647caf85d Author: Louis Knight-Webb <louis@bloop.ai> Date: Tue Jun 17 11:51:20 2025 -0400 Start removing users
202 lines
6.8 KiB
TypeScript
202 lines
6.8 KiB
TypeScript
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 { makeRequest } from '@/lib/api'
|
|
import { Plus, Edit, Trash2, Calendar, AlertCircle, Loader2, MoreHorizontal, ExternalLink } from 'lucide-react'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu'
|
|
|
|
export function ProjectList() {
|
|
const navigate = useNavigate()
|
|
const [projects, setProjects] = useState<Project[]>([])
|
|
const [loading, setLoading] = useState(false)
|
|
const [showForm, setShowForm] = useState(false)
|
|
const [editingProject, setEditingProject] = useState<Project | null>(null)
|
|
const [error, setError] = useState('')
|
|
|
|
const fetchProjects = async () => {
|
|
setLoading(true)
|
|
setError('')
|
|
try {
|
|
const response = await makeRequest('/api/projects')
|
|
const data: ApiResponse<Project[]> = 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 makeRequest(`/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 (
|
|
<div className="space-y-6">
|
|
<div className="flex justify-between items-center">
|
|
<div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Projects</h1>
|
|
<p className="text-muted-foreground">
|
|
Manage your projects and track their progress
|
|
</p>
|
|
</div>
|
|
<Button onClick={() => setShowForm(true)}>
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
Create Project
|
|
</Button>
|
|
</div>
|
|
|
|
{error && (
|
|
<Alert variant="destructive">
|
|
<AlertCircle className="h-4 w-4" />
|
|
<AlertDescription>
|
|
{error}
|
|
</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
|
|
{loading ? (
|
|
<div className="flex items-center justify-center py-12">
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
Loading projects...
|
|
</div>
|
|
) : projects.length === 0 ? (
|
|
<Card>
|
|
<CardContent className="py-12 text-center">
|
|
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-lg bg-muted">
|
|
<Plus className="h-6 w-6" />
|
|
</div>
|
|
<h3 className="mt-4 text-lg font-semibold">No projects yet</h3>
|
|
<p className="mt-2 text-sm text-muted-foreground">
|
|
Get started by creating your first project.
|
|
</p>
|
|
<Button
|
|
className="mt-4"
|
|
onClick={() => setShowForm(true)}
|
|
>
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
Create your first project
|
|
</Button>
|
|
</CardContent>
|
|
</Card>
|
|
) : (
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
{projects.map((project) => (
|
|
<Card
|
|
key={project.id}
|
|
className="hover:shadow-md transition-shadow cursor-pointer"
|
|
onClick={() => navigate(`/projects/${project.id}/tasks`)}
|
|
>
|
|
<CardHeader className="pb-3">
|
|
<div className="flex items-start justify-between">
|
|
<CardTitle className="text-lg">
|
|
{project.name}
|
|
</CardTitle>
|
|
<div className="flex items-center gap-2">
|
|
<Badge variant="secondary">
|
|
Active
|
|
</Badge>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild onClick={(e) => e.stopPropagation()}>
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="h-8 w-8 p-0"
|
|
>
|
|
<MoreHorizontal className="h-4 w-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onClick={(e) => {
|
|
e.stopPropagation()
|
|
navigate(`/projects/${project.id}`)
|
|
}}>
|
|
<ExternalLink className="mr-2 h-4 w-4" />
|
|
View Project
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onClick={(e) => {
|
|
e.stopPropagation()
|
|
handleEdit(project)
|
|
}}>
|
|
<Edit className="mr-2 h-4 w-4" />
|
|
Edit
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
handleDelete(project.id, project.name)
|
|
}}
|
|
className="text-red-600"
|
|
>
|
|
<Trash2 className="mr-2 h-4 w-4" />
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
<CardDescription className="flex items-center">
|
|
<Calendar className="mr-1 h-3 w-3" />
|
|
Created {new Date(project.created_at).toLocaleDateString()}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<ProjectForm
|
|
open={showForm}
|
|
onClose={() => {
|
|
setShowForm(false)
|
|
setEditingProject(null)
|
|
}}
|
|
onSuccess={handleFormSuccess}
|
|
project={editingProject}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|