diff --git a/admin-compliance/app/(sdk)/sdk/consent/page.tsx b/admin-compliance/app/(sdk)/sdk/consent/page.tsx index 2b38182..59947bc 100644 --- a/admin-compliance/app/(sdk)/sdk/consent/page.tsx +++ b/admin-compliance/app/(sdk)/sdk/consent/page.tsx @@ -67,7 +67,7 @@ function transformApiDocument(doc: ApiDocument): LegalDocument { // COMPONENTS // ============================================================================= -function DocumentCard({ document }: { document: LegalDocument }) { +function DocumentCard({ document, onDelete }: { document: LegalDocument; onDelete: (id: string) => void }) { const typeColors = { 'privacy-policy': 'bg-blue-100 text-blue-700', terms: 'bg-green-100 text-green-700', @@ -149,6 +149,12 @@ function DocumentCard({ document }: { document: LegalDocument }) { Veroeffentlichen )} + @@ -165,6 +171,9 @@ export default function ConsentPage() { const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [filter, setFilter] = useState('all') + const [showCreateModal, setShowCreateModal] = useState(false) + const [newDocForm, setNewDocForm] = useState({ type: 'privacy_policy', name: '', description: '' }) + const [creating, setCreating] = useState(false) useEffect(() => { loadDocuments() @@ -192,6 +201,51 @@ export default function ConsentPage() { } } + async function handleCreateDocument() { + if (!newDocForm.name.trim()) return + setCreating(true) + try { + const token = localStorage.getItem('bp_admin_token') + const res = await fetch('/api/admin/consent/documents', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(token ? { 'Authorization': `Bearer ${token}` } : {}), + }, + body: JSON.stringify(newDocForm), + }) + if (res.ok) { + setShowCreateModal(false) + setNewDocForm({ type: 'privacy_policy', name: '', description: '' }) + await loadDocuments() + } else { + setError('Fehler beim Erstellen des Dokuments') + } + } catch { + setError('Verbindungsfehler beim Erstellen') + } finally { + setCreating(false) + } + } + + async function handleDeleteDocument(id: string) { + if (!confirm('Dokument wirklich löschen?')) return + try { + const token = localStorage.getItem('bp_admin_token') + const res = await fetch(`/api/admin/consent/documents/${id}`, { + method: 'DELETE', + headers: token ? { 'Authorization': `Bearer ${token}` } : {}, + }) + if (res.ok || res.status === 204) { + setDocuments(prev => prev.filter(d => d.id !== id)) + } else { + setError('Fehler beim Löschen des Dokuments') + } + } catch { + setError('Verbindungsfehler beim Löschen') + } + } + const filteredDocuments = filter === 'all' ? documents : documents.filter(d => d.type === filter || d.status === filter) @@ -211,7 +265,10 @@ export default function ConsentPage() { explanation={stepInfo.explanation} tips={stepInfo.tips} > -