'use client' import React, { useState, useEffect } from 'react' import { useParams } from 'next/navigation' import { VerificationForm } from './_components/VerificationForm' import { CompleteModal } from './_components/CompleteModal' import { SuggestEvidenceModal } from './_components/SuggestEvidenceModal' import { VerificationTable } from './_components/VerificationTable' import type { VerificationFormData } from './_components/VerificationForm' interface VerificationItem { id: string title: string description: string method: string status: 'pending' | 'in_progress' | 'completed' | 'failed' result: string | null linked_hazard_id: string | null linked_hazard_name: string | null linked_mitigation_id: string | null linked_mitigation_name: string | null completed_at: string | null completed_by: string | null created_at: string } 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 json = await verRes.json(); setItems(json.verifications || json || []) } if (hazRes.ok) { const json = await hazRes.json(); setHazards((json.hazards || json || []).map((h: { id: string; name: string }) => ({ id: h.id, name: h.name }))) } if (mitRes.ok) { const json = await mitRes.json(); setMitigations((json.mitigations || json || []).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 && ( )}
) )}
) }