import React, { useState } from 'react'; import { AlertTriangle, CheckCircle } from 'lucide-react'; import toast from 'react-hot-toast'; import { resolveGsdHitl } from '../../api/client'; interface GsdHitlBannerProps { projectId: string; hitl: { id: string; title: string; question: string; options?: string[]; risk_level?: string; }; onResolved: () => void; } export const GsdHitlBanner: React.FC = ({ projectId, hitl, onResolved }) => { const [isSubmitting, setIsSubmitting] = useState(false); const options = hitl.options?.length ? hitl.options : ['Tak, kontynuuj', 'Nie, wymaga poprawy']; const handleDecision = async (decision: string) => { try { setIsSubmitting(true); toast.loading('Zapisuję odpowiedź...', { id: 'gsd-hitl' }); const res = await resolveGsdHitl(projectId, hitl.id || '', decision); if (res?.status === 'error') { throw new Error(res.message || 'Błąd zapisu HITL'); } const msg = res?.approved === false ? res.message || 'Zapisano prośbę o korektę.' : res?.message || 'Odpowiedź zapisana — kontynuujemy przygotowanie wniosku.'; toast.success(msg, { id: 'gsd-hitl' }); onResolved(); // Force project + sections refresh in parent trees try { window.dispatchEvent(new Event('refresh-sections')); } catch { /* ignore */ } } catch (err: any) { const detail = err?.response?.data?.detail || err?.message; toast.error(typeof detail === 'string' ? detail : 'Nie udało się zapisać odpowiedzi.', { id: 'gsd-hitl' }); } finally { setIsSubmitting(false); } }; return (
Wymagane potwierdzenie: {hitl.title}
{hitl.question}
{hitl.risk_level && (
Poziom ryzyka: {hitl.risk_level}
)}
{options.map((opt) => ( ))}
); };