feat(capa): restyle the CAPA detail page, verification form, close card, owner actions and notes
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ export const dynamic = 'force-dynamic'
|
||||
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { ArrowLeft } from 'lucide-react'
|
||||
import { asAdmin } from '@/lib/db/with-user'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { capaActions, incidents, users } from '@/lib/db/schema'
|
||||
@@ -10,12 +11,23 @@ import { aliasedTable } from 'drizzle-orm'
|
||||
import { VerifyForm } from '@/components/capa/verify-form'
|
||||
import { CloseCapaButton } from '@/components/capa/close-capa-button'
|
||||
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
||||
import { PriorityTag } from '@/components/ui/status-tag'
|
||||
import { Avatar } from '@/components/ui/avatar'
|
||||
import { PriorityTag, StatusTag } from '@/components/ui/status-tag'
|
||||
import { daysLate } from '@/lib/capa/list'
|
||||
|
||||
interface Props {
|
||||
params: Promise<{ id: string }>
|
||||
}
|
||||
|
||||
function Row({ label, children }: { label: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-3 border-b border-rule py-2.5 last:border-0">
|
||||
<dt className="text-xs text-muted">{label}</dt>
|
||||
<dd className="text-right text-[13px]">{children}</dd>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default async function CapaDetailPage({ params }: Props) {
|
||||
const { id } = await params
|
||||
const session = await getSession()
|
||||
@@ -50,75 +62,90 @@ export default async function CapaDetailPage({ params }: Props) {
|
||||
|
||||
const isHse = session && ['hse', 'admin'].includes(session.role)
|
||||
const status = capa.status
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const pastDue = (status === 'open' || status === 'in_progress') && Boolean(capa.dueDate) && capa.dueDate < today
|
||||
const shownStatus = pastDue ? 'overdue' : status
|
||||
const late = shownStatus === 'overdue' ? daysLate(capa.dueDate, today) : 0
|
||||
const canAct = ['open', 'in_progress', 'overdue', 'reopened'].includes(status) &&
|
||||
(isHse || session?.sub === capa.ownerUserId)
|
||||
|
||||
return (
|
||||
<main className="max-w-2xl mx-auto px-4 py-6">
|
||||
<Link href="/hse/capa" className="text-sm text-accent-700 hover:underline mb-4 inline-block">
|
||||
← CAPA Board
|
||||
<div className="space-y-4 px-4 py-5 md:px-8 md:py-6">
|
||||
<Link href="/hse/capa" className="inline-flex items-center gap-1 text-[13px] text-accent hover:underline">
|
||||
<ArrowLeft size={14} strokeWidth={2} aria-hidden />
|
||||
CAPA
|
||||
</Link>
|
||||
|
||||
<div className="bg-surface shadow-sm p-5 mb-4 space-y-4">
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<p className="text-xs text-gray-500 mb-1">
|
||||
Incident: {capa.incidentRefNo ?? '—'}
|
||||
</p>
|
||||
<p className="text-gray-900 font-medium">{capa.description}</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-xl font-[650]">{capa.description}</h1>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<StatusTag status={shownStatus} />
|
||||
<PriorityTag priority={capa.priority} />
|
||||
<span className="text-[13px] text-muted">
|
||||
From{' '}
|
||||
<Link href={`/hse/incidents/${capa.incidentId}`} className="font-mono text-[12.5px] text-accent hover:underline">
|
||||
{capa.incidentRefNo ?? '—'}
|
||||
</Link>
|
||||
</span>
|
||||
</div>
|
||||
{capa.rootCauseRef && <p className="text-[13px] text-muted">Root cause: {capa.rootCauseRef}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Owner</p>
|
||||
<p className="text-gray-800">{capa.ownerName ?? '—'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Department</p>
|
||||
<p className="text-gray-800">{capa.department}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Due Date</p>
|
||||
<p className="text-gray-800">{capa.dueDate}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Status</p>
|
||||
<p className="text-gray-800 capitalize">{status.replace(/_/g, ' ')}</p>
|
||||
</div>
|
||||
{capa.ownerNotes && (
|
||||
<div className="col-span-2">
|
||||
<p className="text-xs text-gray-500">Owner Notes</p>
|
||||
<p className="text-sm text-gray-800 whitespace-pre-wrap">{capa.ownerNotes}</p>
|
||||
<div className="grid gap-4 lg:grid-cols-[1fr_320px]">
|
||||
<div className="space-y-4">
|
||||
{canAct && (
|
||||
<div>
|
||||
<CapaOwnerActions capaId={id} currentStatus={status} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isHse && status === 'pending_verification' && <VerifyForm capaId={id} />}
|
||||
{isHse && status === 'verified' && <CloseCapaButton capaId={id} />}
|
||||
|
||||
{(capa.ownerNotes || capa.completedAt) && (
|
||||
<section className="space-y-2 rounded-xl bg-surface p-5 shadow-card">
|
||||
<h2 className="text-sm font-semibold">Completion report</h2>
|
||||
{capa.completedAt && (
|
||||
<p className="text-xs text-muted">
|
||||
Completed {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||
</p>
|
||||
)}
|
||||
{capa.ownerNotes && (
|
||||
<p className="whitespace-pre-wrap text-[13px] text-ink-3">{capa.ownerNotes}</p>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{capa.rootCauseRef && (
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Root Cause Reference</p>
|
||||
<p className="text-sm text-gray-800">{capa.rootCauseRef}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{capa.completedAt && (
|
||||
<p className="text-xs text-gray-500">
|
||||
Completed: {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||
</p>
|
||||
)}
|
||||
<aside>
|
||||
<section className="rounded-xl bg-surface p-5 shadow-card">
|
||||
<h2 className="mb-1 text-sm font-semibold">Details</h2>
|
||||
<dl>
|
||||
<Row label="Owner">
|
||||
{capa.ownerName ? (
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<Avatar name={capa.ownerName} />
|
||||
{capa.ownerName}
|
||||
</span>
|
||||
) : (
|
||||
'—'
|
||||
)}
|
||||
</Row>
|
||||
<Row label="Department">{capa.department}</Row>
|
||||
<Row label="Priority"><PriorityTag priority={capa.priority} /></Row>
|
||||
<Row label="Due">
|
||||
{capa.dueDate}
|
||||
{late > 0 && <span className="ml-1.5 text-xs text-danger">{`${late} day${late === 1 ? '' : 's'} late`}</span>}
|
||||
</Row>
|
||||
{capa.completedAt && (
|
||||
<Row label="Completed">
|
||||
{new Date(capa.completedAt).toLocaleDateString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||
</Row>
|
||||
)}
|
||||
</dl>
|
||||
</section>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
{['open', 'in_progress', 'overdue', 'reopened'].includes(status) &&
|
||||
(isHse || session?.sub === capa.ownerUserId) && (
|
||||
<CapaOwnerActions capaId={id} currentStatus={status} />
|
||||
)}
|
||||
|
||||
{isHse && status === 'pending_verification' && (
|
||||
<VerifyForm capaId={id} />
|
||||
)}
|
||||
|
||||
{isHse && status === 'verified' && (
|
||||
<CloseCapaButton capaId={id} />
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user