"use client" import { useState, useEffect } from "react" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { X, Plus, Trash2, Play } from "lucide-react" import { cn } from "@/lib/utils" interface TaskDialogProps { open: boolean onOpenChange: (open: boolean) => void task: { id?: string title: string description?: string status: string priority: string assigned_agent?: string | null progress?: number tags?: string[] due_date?: string notes?: string } | null onSubmit: (data: { title: string description?: string status?: string priority?: string assigned_agent?: string | null progress?: number tags?: string[] due_date?: string notes?: string }) => void onDelete?: () => void onRun?: () => void } const STATUS_OPTIONS = [ { value: "backlog", label: "Backlog" }, { value: "ready", label: "Ready" }, { value: "in-progress", label: "In Progress" }, { value: "review", label: "Review" }, { value: "done", label: "Done" }, ] const PRIORITY_OPTIONS = [ { value: "low", label: "Low" }, { value: "medium", label: "Medium" }, { value: "high", label: "High" }, { value: "urgent", label: "Urgent" }, ] const AGENT_OPTIONS = [ { value: "manual", label: "Manual (unassigned)" }, { value: "coder", label: "Coder" }, { value: "researcher", label: "Researcher" }, { value: "writer", label: "Writer" }, { value: "pm", label: "Project Manager" }, ] export function TaskDialog({ open, onOpenChange, task, onSubmit, onDelete, onRun }: TaskDialogProps) { const isEditing = !!task?.id const [title, setTitle] = useState("") const [description, setDescription] = useState("") const [status, setStatus] = useState("backlog") const [priority, setPriority] = useState("medium") const [assignedAgent, setAssignedAgent] = useState("manual") const [dueDate, setDueDate] = useState("") const [tags, setTags] = useState([]) const [newTag, setNewTag] = useState("") const [progress, setProgress] = useState(0) const [notes, setNotes] = useState("") // Reset form when dialog opens useEffect(() => { if (open) { if (task) { setTitle(task.title || "") setDescription(task.description || "") setStatus(task.status || "backlog") setPriority(task.priority || "medium") setAssignedAgent(task.assigned_agent || "manual") setDueDate(task.due_date ? task.due_date.split("T")[0] : "") setTags(typeof task.tags === "string" ? JSON.parse(task.tags || "[]") : (task.tags || [])) setProgress(task.progress || 0) setNotes(task.notes || "") } else { setTitle("") setDescription("") setStatus("backlog") setPriority("medium") setAssignedAgent("manual") setDueDate("") setTags([]) setNewTag("") setProgress(0) setNotes("") } } }, [open, task]) const handleSubmit = () => { if (!title.trim()) return onSubmit({ title: title.trim(), description: description.trim() || undefined, status, priority, assigned_agent: assignedAgent !== "manual" ? assignedAgent : undefined, progress, tags, due_date: dueDate || undefined, notes: notes.trim() || undefined, }) } const addTag = () => { if (newTag.trim() && !tags.includes(newTag.trim())) { setTags([...tags, newTag.trim()]) setNewTag("") } } const removeTag = (tag: string) => { setTags(tags.filter(t => t !== tag)) } return ( {isEditing ? "Edit Task" : "Create New Task"} {isEditing ? "Update task details and progress" : "Add a new task to your board"}
{/* Title */}
setTitle(e.target.value)} />
{/* Description */}