'use client' import { useState } from 'react' import { setMatrixEntry } from '@/lib/sdk/training/api' import type { TrainingModule } from '@/lib/sdk/training/types' import { ROLE_LABELS, REGULATION_LABELS } from '@/lib/sdk/training/types' export default function MatrixAddModal({ roleCode, modules, onClose, onSaved, }: { roleCode: string modules: 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 setMatrixEntry({ role_code: roleCode, module_id: fd.get('module_id') as string, is_mandatory: fd.get('is_mandatory') === 'on', priority: parseInt(fd.get('priority') as string) || 1, }) onSaved() } catch (err) { setError(err instanceof Error ? err.message : 'Fehler beim Hinzufuegen') } finally { setSaving(false) } } return (

Modul zuweisen

Rolle: {ROLE_LABELS[roleCode] ?? roleCode} ({roleCode})

{error && (
{error}
)}
) }