'use client' import { useState } from 'react' import { EMPTY_FORM, CATEGORY_LABELS, PRIORITY_LABELS, FREQUENCY_LABELS } from './types' import type { TaskFormData } from './types' export function TaskFormModal({ initial, onClose, onSave, }: { initial?: Partial onClose: () => void onSave: (data: TaskFormData) => Promise }) { const [form, setForm] = useState({ ...EMPTY_FORM, ...initial }) const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const update = (field: keyof TaskFormData, value: string | number) => setForm(prev => ({ ...prev, [field]: value })) const handleSave = async () => { if (!form.title.trim()) { setError('Titel ist erforderlich'); return } if (!form.task_code.trim()) { setError('Task-Code ist erforderlich'); return } setSaving(true) setError(null) try { await onSave(form) onClose() } catch (e) { setError(e instanceof Error ? e.message : 'Fehler beim Speichern') } finally { setSaving(false) } } return (
e.target === e.currentTarget && onClose()}>

{initial?.title ? 'Aufgabe bearbeiten' : 'Neue Aufgabe erstellen'}

{error &&
{error}
}
update('task_code', e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500" placeholder="z.B. DSGVO-VVT-REVIEW" />
update('title', e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500" placeholder="z.B. VVT-Review und Aktualisierung" />