diff --git a/app/(protected)/hse/capa/[id]/page.tsx b/app/(protected)/hse/capa/[id]/page.tsx index a689504..14a74b4 100644 --- a/app/(protected)/hse/capa/[id]/page.tsx +++ b/app/(protected)/hse/capa/[id]/page.tsx @@ -4,6 +4,7 @@ import { notFound, redirect } from 'next/navigation' import Link from 'next/link' import { createClient } from '@/lib/supabase/server' import { VerifyForm } from '@/components/capa/verify-form' +import { CloseCapaButton } from '@/components/capa/close-capa-button' interface Props { params: Promise<{ id: string }> @@ -95,6 +96,10 @@ export default async function CapaDetailPage({ params }: Props) { {isHse && status === 'pending_verification' && ( )} + + {isHse && status === 'verified' && ( + + )} ) } diff --git a/components/capa/close-capa-button.tsx b/components/capa/close-capa-button.tsx new file mode 100644 index 0000000..4763657 --- /dev/null +++ b/components/capa/close-capa-button.tsx @@ -0,0 +1,49 @@ +'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}

} + +
+ ) +}