'use client'; import { useState } from 'react'; import { DailyCheckbox, DailyCheckboxType } from '@/lib/types'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { Modal } from '@/components/ui/Modal'; import { TaskSelector } from './TaskSelector'; interface EditCheckboxModalProps { checkbox: DailyCheckbox; isOpen: boolean; onClose: () => void; onSave: (text: string, type: DailyCheckboxType, taskId?: string) => Promise; saving?: boolean; } export function EditCheckboxModal({ checkbox, isOpen, onClose, onSave, saving = false }: EditCheckboxModalProps) { const [text, setText] = useState(checkbox.text); const [type, setType] = useState(checkbox.type); const [taskId, setTaskId] = useState(checkbox.taskId); const handleSave = async () => { if (!text.trim()) return; try { await onSave(text.trim(), type, taskId); onClose(); } catch (error) { console.error('Erreur lors de la sauvegarde:', error); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSave(); } }; const resetForm = () => { setText(checkbox.text); setType(checkbox.type); setTaskId(checkbox.taskId); }; const handleClose = () => { resetForm(); onClose(); }; return (
{/* Texte */}
setText(e.target.value)} onKeyDown={handleKeyPress} placeholder="Description de la tâche..." className="w-full" autoFocus />
{/* Type */}
{/* Liaison tâche (seulement pour les tâches) */} {type === 'task' && (
{taskId && (
Tâche liée : #{taskId.slice(-6)}
)}
)} {/* Actions */}
); }