"use client"; import { useState } from "react"; import { useUpdateTask } from "@/hooks/use-tasks"; import { Task, Team, Complexity, TaskNature, TaskType } from "@/types"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from "@/components/ui/dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import { ChevronDown, ChevronRight, GitBranch } from "lucide-react"; import { toast } from "sonner"; import { MarkdownEditor } from "./markdown-editor"; import { AgentSelector } from "@/components/agents/agent-selector"; import { ProjectSelector } from "@/components/projects/project-selector"; // Priority options (0=P0 highest, 3=P3 lowest) const PRIORITY_OPTIONS = [ { value: 0, label: "P0 - Highest" }, { value: 1, label: "P1 - High" }, { value: 2, label: "P2 - Medium" }, { value: 3, label: "P3 - Low" }, ]; // Complexity options const COMPLEXITY_OPTIONS = [ { value: Complexity.LOW, label: "Low" }, { value: Complexity.MEDIUM, label: "Medium" }, { value: Complexity.HIGH, label: "High" }, ]; // Nature options const NATURE_OPTIONS = [ { value: TaskNature.TECHNICAL, label: "Technical" }, { value: TaskNature.NON_TECHNICAL, label: "Non-Technical" }, ]; // Task type options const TASK_TYPE_OPTIONS = [ { value: TaskType.CODE, label: "Code" }, { value: TaskType.DOCUMENTATION, label: "Documentation" }, { value: TaskType.RESEARCH, label: "Research" }, { value: TaskType.PLANNING, label: "Planning" }, { value: TaskType.DESIGN, label: "Design" }, { value: TaskType.ADMINISTRATIVE, label: "Administrative" }, ]; interface EditTaskDialogProps { task: Task; open: boolean; onOpenChange: (open: boolean) => void; } // Inner component that resets when task.id changes via key function EditTaskDialogInner({ task, onOpenChange }: { task: Task; onOpenChange: (open: boolean) => void }) { const [title, setTitle] = useState(task.title); const [description, setDescription] = useState(task.description); const [team, setTeam] = useState(task.team); const [priority, setPriority] = useState(task.priority); const [complexity, setComplexity] = useState(task.estimated_complexity); const [nature, setNature] = useState(task.nature ?? TaskNature.TECHNICAL); const [taskType, setTaskType] = useState(task.task_type ?? TaskType.CODE); const [projectId, setProjectId] = useState(task.project_id ?? ""); const [assignedTo, setAssignedTo] = useState(task.assigned_to ?? null); const [targetDate, setTargetDate] = useState( task.target_date ? new Date(task.target_date).toISOString().slice(0, 16) : "" ); const [advancedOpen, setAdvancedOpen] = useState(false); const updateTask = useUpdateTask(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!title.trim() || title.trim().length < 5) { toast.error("Title must be at least 5 characters"); return; } if (!description.trim() || description.trim().length < 20) { toast.error("Description must be at least 20 characters"); return; } try { await updateTask.mutateAsync({ taskId: task.id, updates: { title: title.trim(), description: description.trim(), team, priority, estimated_complexity: complexity, nature, task_type: taskType, project_id: projectId, assigned_to: assignedTo, target_date: targetDate ? new Date(targetDate).toISOString() : null, }, }); toast.success("Task updated successfully"); onOpenChange(false); } catch { toast.error("Failed to update task"); } }; return ( Edit Task Update task details. Some fields may be locked based on task status.
{/* Title */}
setTitle(e.target.value)} placeholder="Enter task title" />
{/* Description */} {/* Team, Priority, Complexity, Nature */}
{/* Advanced Options */} {/* Assigned To */}
{/* Target Date */}
setTargetDate(e.target.value)} />
{/* Git Configuration Section */}
Git & Work Configuration
{/* Task Type */}
{/* Project Selector (required - all tasks follow git workflow) */}
setProjectId(value || "")} placeholder="Select project..." disabled={!!task.branch_name} /> {task.branch_name && (

Project cannot be changed after work has started

)}
{/* Actions */}
); } // Wrapper component that uses key to reset form when task changes export function EditTaskDialog({ task, open, onOpenChange }: EditTaskDialogProps) { if (!open) return null; return ; }