'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' interface Props { capaId: string } export function CloseCapaButton({ capaId }: Props) { const router = useRouter() const [loading, setLoading] = useState(false) const [error, setError] = useState(null) async function handleClose() { if (!confirm('Close this CAPA? This marks it as fully resolved.')) return setLoading(true) setError(null) const res = await fetch(`/ims/api/capa/${capaId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ status: 'closed' }), }) if (!res.ok) { setError('Failed to close CAPA. Please try again.') setLoading(false) return } router.push('/hse/capa') router.refresh() } return (

Close CAPA

This CAPA has been verified as effective. Close it to mark it fully resolved.

{error &&

{error}

}
) }