"use client"; import { useState } from "react"; import { Trash2 } from "lucide-react"; 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 { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useBoard } from "@/components/board/board-context"; import type { TodoDTO } from "@/types/board"; const TITLE_MAX = 20; export function TodoEditDialog({ todo, groupId, categoryId, open, onOpenChange, }: { todo: TodoDTO; groupId: string; categoryId: string; open: boolean; onOpenChange: (open: boolean) => void; }) { const { editTodo, removeTodo } = useBoard(); const [title, setTitle] = useState(todo.title); const [details, setDetails] = useState(todo.details ?? ""); const [pending, setPending] = useState(false); function handleOpenChange(next: boolean) { if (next) { setTitle(todo.title); setDetails(todo.details ?? ""); } onOpenChange(next); } async function handleSave() { const trimmed = title.trim(); if (!trimmed) return; setPending(true); const ok = await editTodo(todo.id, groupId, categoryId, { title: trimmed, details: details.trim() || null, }); setPending(false); if (ok) onOpenChange(false); } async function handleDelete() { setPending(true); await removeTodo(todo.id, groupId, categoryId); setPending(false); onOpenChange(false); } return ( Edit to-do
setTitle(e.target.value)} />

{title.length}/{TITLE_MAX}