import { useState, useEffect } from "react" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { ALL_STATUSES, ALL_PRIORITIES, STATUS_CONFIG, PRIORITY_CONFIG, type Agent, type Task, type TaskStatus, type TaskPriority, type CreateTaskInput, } from "@/types" interface TaskDialogProps { open: boolean onOpenChange: (open: boolean) => void task: Task | null // null = creating new task defaultStatus?: TaskStatus agents: Agent[] onSave: (data: CreateTaskInput & { id?: number; status?: TaskStatus }) => void onDelete?: (id: number) => void } export function TaskDialog({ open, onOpenChange, task, defaultStatus, agents, onSave, onDelete }: TaskDialogProps) { const [title, setTitle] = useState("") const [description, setDescription] = useState("") const [priority, setPriority] = useState("p2") const [status, setStatus] = useState(defaultStatus ?? "backlog") const [assigneeId, setAssigneeId] = useState("unassigned") useEffect(() => { if (task) { setTitle(task.title) setDescription(task.description) setPriority(task.priority) setStatus(task.status) setAssigneeId(task.assigneeId ? String(task.assigneeId) : "unassigned") } else { setTitle("") setDescription("") setPriority("p2") setStatus(defaultStatus ?? "backlog") setAssigneeId("unassigned") } }, [task, defaultStatus, open]) function handleSubmit(e: React.FormEvent) { e.preventDefault() if (!title.trim()) return onSave({ id: task?.id, title: title.trim(), description: description.trim(), priority, status, assigneeId: assigneeId === "unassigned" ? null : Number(assigneeId), }) onOpenChange(false) } const isEditing = task !== null return ( {isEditing ? "Edit Task" : "New Task"} {isEditing ? "Update the task details below." : "Fill in the details to create a new task."}
{/* Title */}
setTitle(e.target.value)} autoFocus />
{/* Description */}