'use client'; import { useState } from 'react'; import { Modal } from '@/components/ui/Modal'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { TagInput } from '@/components/ui/TagInput'; import { TaskPriority, TaskStatus } from '@/lib/types'; import { CreateTaskData } from '@/clients/tasks-client'; import { getAllStatuses, getAllPriorities } from '@/lib/status-config'; interface CreateTaskFormProps { isOpen: boolean; onClose: () => void; onSubmit: (data: CreateTaskData) => Promise; loading?: boolean; } export function CreateTaskForm({ isOpen, onClose, onSubmit, loading = false }: CreateTaskFormProps) { const [formData, setFormData] = useState({ title: '', description: '', status: 'todo' as TaskStatus, priority: 'medium' as TaskPriority, tags: [], dueDate: undefined }); const [errors, setErrors] = useState>({}); const validateForm = (): boolean => { const newErrors: Record = {}; if (!formData.title.trim()) { newErrors.title = 'Le titre est requis'; } if (formData.title.length > 200) { newErrors.title = 'Le titre ne peut pas dépasser 200 caractères'; } if (formData.description && formData.description.length > 1000) { newErrors.description = 'La description ne peut pas dépasser 1000 caractères'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!validateForm()) return; try { await onSubmit(formData); handleClose(); } catch (error) { console.error('Erreur lors de la création:', error); } }; const handleClose = () => { setFormData({ title: '', description: '', status: 'todo', priority: 'medium', tags: [], dueDate: undefined }); setErrors({}); onClose(); }; return (
{/* Titre */} setFormData((prev: CreateTaskData) => ({ ...prev, title: e.target.value }))} placeholder="Titre de la tâche..." error={errors.title} disabled={loading} /> {/* Description */}