feat(capa): add Close CAPA button for HSE after verification
Verified CAPAs now show a Close button on the detail page for HSE/admin, transitioning status to closed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { notFound, redirect } from 'next/navigation'
|
|||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { createClient } from '@/lib/supabase/server'
|
import { createClient } from '@/lib/supabase/server'
|
||||||
import { VerifyForm } from '@/components/capa/verify-form'
|
import { VerifyForm } from '@/components/capa/verify-form'
|
||||||
|
import { CloseCapaButton } from '@/components/capa/close-capa-button'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: Promise<{ id: string }>
|
params: Promise<{ id: string }>
|
||||||
@@ -95,6 +96,10 @@ export default async function CapaDetailPage({ params }: Props) {
|
|||||||
{isHse && status === 'pending_verification' && (
|
{isHse && status === 'pending_verification' && (
|
||||||
<VerifyForm capaId={id} />
|
<VerifyForm capaId={id} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isHse && status === 'verified' && (
|
||||||
|
<CloseCapaButton capaId={id} />
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<string | null>(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 (
|
||||||
|
<div className="border border-gray-200 rounded-xl p-5 space-y-3 bg-green-50">
|
||||||
|
<h3 className="text-sm font-semibold text-gray-800">Close CAPA</h3>
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
This CAPA has been verified as effective. Close it to mark it fully resolved.
|
||||||
|
</p>
|
||||||
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
<button
|
||||||
|
onClick={handleClose}
|
||||||
|
disabled={loading}
|
||||||
|
className="w-full bg-green-700 text-white rounded-lg py-2 text-sm font-semibold hover:bg-green-800 disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{loading ? 'Closing…' : 'Close CAPA'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user