'use client' import React, { useState, useEffect, useCallback } from 'react' import { UseCaseSelector } from './_components/UseCaseSelector' interface Template { id: string name: string description: string mc_filters: string[] regulations: string[] } interface AuditSummary { id: string template_id: string name: string target_name: string status: string total_questions: number answered_questions: number compliance_score: number created_at: string completed_at: string | null } const TENANT_ID = '00000000-0000-0000-0000-000000000001' const STATUS_LABELS: Record = { draft: { label: 'Entwurf', color: 'bg-gray-100 text-gray-700' }, in_progress: { label: 'In Bearbeitung', color: 'bg-blue-100 text-blue-700' }, completed: { label: 'Abgeschlossen', color: 'bg-green-100 text-green-700' }, } export default function UseCaseAuditPage() { const [view, setView] = useState<'list' | 'new'>('list') const [templates, setTemplates] = useState([]) const [audits, setAudits] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const loadData = useCallback(async () => { try { const [tRes, aRes] = await Promise.all([ fetch('/api/sdk/v1/use-case/templates'), fetch('/api/sdk/v1/use-case/audits', { headers: { 'X-Tenant-ID': TENANT_ID }, }), ]) if (tRes.ok) { const td = await tRes.json() setTemplates(td.templates || []) } if (aRes.ok) { const ad = await aRes.json() setAudits(ad.audits || []) } } catch { /* ignore */ } }, []) useEffect(() => { loadData() }, [loadData]) const handleCreateAudit = async (templateId: string, name: string, targetName: string) => { setLoading(true) setError('') try { const res = await fetch('/api/sdk/v1/use-case/audits', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Tenant-ID': TENANT_ID, }, body: JSON.stringify({ template_id: templateId, name, target_name: targetName, }), }) if (!res.ok) { const err = await res.json() throw new Error(err.error || 'Audit konnte nicht erstellt werden') } const data = await res.json() window.location.href = `/sdk/use-case-audit/${data.audit.id}` } catch (e) { setError(e instanceof Error ? e.message : 'Fehler') } finally { setLoading(false) } } return (

Use-Case Audits

Compliance-Pruefungen aus Master Controls — interaktive Frageboegen mit Scoring.

{view === 'list' ? ( ) : ( )}
{error && (

{error}

)} {view === 'new' && ( )} {view === 'list' && (
{audits.length > 0 ? (
{audits.map(a => { const st = STATUS_LABELS[a.status] || STATUS_LABELS.draft const progress = a.total_questions > 0 ? Math.round((a.answered_questions / a.total_questions) * 100) : 0 return ( ) : (
📋

Noch keine Audits

Starten Sie Ihren ersten Compliance-Audit.

)}
)}
) }