'use client' import React, { useState, useEffect, useCallback } from 'react' import { API, ISMSPolicy } from '../_types' import { EmptyState, LoadingSpinner, StatusBadge } from './shared' // ============================================================================= // TAB: POLICIES // ============================================================================= export function PoliciesTab() { const [policies, setPolicies] = useState([]) const [loading, setLoading] = useState(true) const [showCreate, setShowCreate] = useState(false) const [filter, setFilter] = useState('') const load = useCallback(async () => { setLoading(true) try { const url = filter ? `${API}/policies?policy_type=${filter}` : `${API}/policies` const res = await fetch(url) if (res.ok) { const data = await res.json() setPolicies(data.policies || []) } } catch { /* ignore */ } setLoading(false) }, [filter]) useEffect(() => { load() }, [load]) const createPolicy = async (form: Record) => { try { const res = await fetch(`${API}/policies`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(form), }) if (res.ok) { setShowCreate(false); load() } } catch { /* ignore */ } } const approvePolicy = async (policyId: string) => { try { await fetch(`${API}/policies/${policyId}/approve`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ reviewed_by: 'admin', approved_by: 'admin', effective_date: new Date().toISOString().split('T')[0], }), }) load() } catch { /* ignore */ } } if (loading) return const policyTypes = ['master', 'topic', 'operational', 'standard'] return (
{policyTypes.map(t => ( ))}
{policies.length === 0 ? ( setShowCreate(true)} /> ) : (
{policies.map(p => (
{p.policy_id} {p.title} v{p.version}

{p.description}

Typ: {p.policy_type} Review: alle {p.review_frequency_months} Monate {p.next_review_date && Naechste Review: {new Date(p.next_review_date).toLocaleDateString('de-DE')}}
{p.status === 'draft' && ( )}
))}
)} {/* Create Modal */} {showCreate && ( setShowCreate(false)} onSave={createPolicy} /> )}
) } function PolicyCreateModal({ onClose, onSave }: { onClose: () => void; onSave: (data: Record) => void }) { const [form, setForm] = useState({ policy_id: '', title: '', policy_type: 'topic', description: '', policy_text: '', applies_to: ['Alle Mitarbeiter'], review_frequency_months: 12, related_controls: [] as string[], authored_by: 'admin', }) return (

Neue ISMS Policy

setForm({ ...form, policy_id: e.target.value })} className="w-full border rounded-lg px-3 py-2 text-sm" placeholder="z.B. POL-SEC-001" />
setForm({ ...form, title: e.target.value })} className="w-full border rounded-lg px-3 py-2 text-sm" />