'use client' import React, { useState, useEffect } from 'react' import { useParams } from 'next/navigation' import type { VerificationItem, VerificationFormData } from './_components/verification-types' import { VerificationForm } from './_components/VerificationForm' import { CompleteModal } from './_components/CompleteModal' import { SuggestEvidenceModal } from './_components/SuggestEvidenceModal' import { VerificationTable } from './_components/VerificationTable' export default function VerificationPage() { const params = useParams() const projectId = params.projectId as string const [items, setItems] = useState([]) const [hazards, setHazards] = useState<{ id: string; name: string }[]>([]) const [mitigations, setMitigations] = useState<{ id: string; title: string }[]>([]) const [loading, setLoading] = useState(true) const [showForm, setShowForm] = useState(false) const [completingItem, setCompletingItem] = useState(null) const [showSuggest, setShowSuggest] = useState(false) useEffect(() => { fetchData() }, [projectId]) async function fetchData() { try { const [verRes, hazRes, mitRes] = await Promise.all([ fetch(`/api/sdk/v1/iace/projects/${projectId}/verifications`), fetch(`/api/sdk/v1/iace/projects/${projectId}/hazards`), fetch(`/api/sdk/v1/iace/projects/${projectId}/mitigations`), ]) if (verRes.ok) { const j = await verRes.json(); setItems(j.verifications || j || []) } if (hazRes.ok) { const j = await hazRes.json(); setHazards((j.hazards || j || []).map((h: { id: string; name: string }) => ({ id: h.id, name: h.name }))) } if (mitRes.ok) { const j = await mitRes.json(); setMitigations((j.mitigations || j || []).map((m: { id: string; title: string }) => ({ id: m.id, title: m.title }))) } } catch (err) { console.error('Failed to fetch data:', err) } finally { setLoading(false) } } async function handleSubmit(data: VerificationFormData) { try { const res = await fetch(`/api/sdk/v1/iace/projects/${projectId}/verifications`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) if (res.ok) { setShowForm(false); await fetchData() } } catch (err) { console.error('Failed to add verification:', err) } } async function handleAddSuggestedEvidence(title: string, description: string, method: string, mitigationId: string) { try { const res = await fetch(`/api/sdk/v1/iace/projects/${projectId}/verifications`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title, description, method, linked_mitigation_id: mitigationId }), }) if (res.ok) await fetchData() } catch (err) { console.error('Failed to add suggested evidence:', err) } } async function handleComplete(id: string, result: string, passed: boolean) { try { const res = await fetch(`/api/sdk/v1/iace/projects/${projectId}/verifications/${id}/complete`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ result, passed }), }) if (res.ok) { setCompletingItem(null); await fetchData() } } catch (err) { console.error('Failed to complete verification:', err) } } async function handleDelete(id: string) { if (!confirm('Verifikation wirklich loeschen?')) return try { const res = await fetch(`/api/sdk/v1/iace/projects/${projectId}/verifications/${id}`, { method: 'DELETE' }) if (res.ok) await fetchData() } catch (err) { console.error('Failed to delete verification:', err) } } const completed = items.filter(i => i.status === 'completed').length const failed = items.filter(i => i.status === 'failed').length const pending = items.filter(i => i.status === 'pending' || i.status === 'in_progress').length if (loading) return (
) return (

Verifikationsplan

Nachweisfuehrung fuer alle Schutzmassnahmen und Sicherheitsanforderungen.

{mitigations.length > 0 && ( )}
{items.length > 0 && (
{items.length}
Gesamt
{completed}
Abgeschlossen
{failed}
Fehlgeschlagen
{pending}
Ausstehend
)} {showForm && setShowForm(false)} hazards={hazards} mitigations={mitigations} />} {completingItem && setCompletingItem(null)} />} {showSuggest && setShowSuggest(false)} />} {items.length > 0 ? ( ) : !showForm && (

Kein Verifikationsplan vorhanden

Definieren Sie Verifikationsschritte fuer Ihre Schutzmassnahmen. Jede Massnahme sollte durch mindestens eine Verifikation abgedeckt sein.

{mitigations.length > 0 && ( )}
)}
) }