'use client' import { useState } from 'react' import { updateModule, deleteModule } from '@/lib/sdk/training/api' import type { TrainingModule } from '@/lib/sdk/training/types' import { REGULATION_LABELS, FREQUENCY_LABELS } from '@/lib/sdk/training/types' export default function ModuleEditDrawer({ module, onClose, onSaved, }: { module: TrainingModule onClose: () => void onSaved: () => void }) { const [saving, setSaving] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setSaving(true) setError(null) const fd = new FormData(e.currentTarget) try { await updateModule(module.id, { title: fd.get('title') as string, description: (fd.get('description') as string) || undefined, regulation_area: fd.get('regulation_area') as string, frequency_type: fd.get('frequency_type') as string, validity_days: parseInt(fd.get('validity_days') as string), duration_minutes: parseInt(fd.get('duration_minutes') as string), pass_threshold: parseInt(fd.get('pass_threshold') as string), risk_weight: parseFloat(fd.get('risk_weight') as string), nis2_relevant: fd.get('nis2_relevant') === 'on', is_active: fd.get('is_active') === 'on', }) onSaved() } catch (err) { setError(err instanceof Error ? err.message : 'Fehler beim Speichern') } finally { setSaving(false) } } async function handleDelete() { if (!window.confirm('Modul wirklich loeschen?')) return try { await deleteModule(module.id) onSaved() } catch (err) { setError(err instanceof Error ? err.message : 'Fehler beim Loeschen') } } return (

Modul bearbeiten

{error && (
{error}
)}
{module.module_code} ID: {module.id.slice(0, 8)}