import { useState, useEffect } from 'react' const API_BASE = import.meta.env.VITE_BRAIN_API ?? '' interface GateDrawerProps { open: boolean onClose: () => void workflowId: string | null stepId: string | null } export default function GateDrawer({ open, onClose, workflowId, stepId }: GateDrawerProps) { const [busy, setBusy] = useState(false) const [approved, setApproved] = useState(false) // Reset state when drawer opens for a new gate useEffect(() => { if (open) { setBusy(false) setApproved(false) } }, [open, workflowId, stepId]) const handleApprove = async () => { if (!workflowId || !stepId || busy) return setBusy(true) try { await fetch( `${API_BASE}/gate/${encodeURIComponent(workflowId)}/${encodeURIComponent(stepId)}/approve`, { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, } ) setApproved(true) setTimeout(() => { setApproved(false) onClose() }, 1500) } finally { setBusy(false) } } const handleReject = async () => { if (!workflowId || !stepId || busy) return setBusy(true) try { const res = await fetch( `${API_BASE}/gate/${encodeURIComponent(workflowId)}/${encodeURIComponent(stepId)}/reject`, { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, } ) // 404 = endpoint optionnel — gérer silencieusement if (res.ok || res.status === 404) { onClose() } } finally { setBusy(false) } } return ( <> {/* Overlay — cliquable pour fermer */}
{/* Panel slide-in depuis la droite */}Cette étape est un point de contrôle. Approuver pour continuer le workflow.
{/* Métadonnées */} {workflowId && stepId && (