From 587b58079771ef476de1b0696d160b5bf467686a Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 1 Oct 2026 11:20:57 +0800 Subject: [PATCH] feat(capa): restyle the CAPA detail page, verification form, close card, owner actions and notes Co-Authored-By: Claude Haiku 4.5 --- app/(protected)/hse/capa/[id]/page.tsx | 145 +++++++++++------- components/capa/capa-owner-actions.tsx | 17 +- components/capa/capa-owner-notes-form.tsx | 33 ++-- components/capa/close-capa-button.tsx | 27 ++-- components/capa/verify-form.tsx | 107 ++++++++----- .../capa/capa-owner-notes-form.test.tsx | 29 ++++ tests/components/capa/verify-form.test.tsx | 76 +++++++++ 7 files changed, 297 insertions(+), 137 deletions(-) create mode 100644 tests/components/capa/capa-owner-notes-form.test.tsx create mode 100644 tests/components/capa/verify-form.test.tsx diff --git a/app/(protected)/hse/capa/[id]/page.tsx b/app/(protected)/hse/capa/[id]/page.tsx index 4cb4257..e086cb4 100644 --- a/app/(protected)/hse/capa/[id]/page.tsx +++ b/app/(protected)/hse/capa/[id]/page.tsx @@ -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 ( +
+
{label}
+
{children}
+
+ ) +} + 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 ( -
- - ← CAPA Board +
+ + + CAPA -
-
-
-

- Incident: {capa.incidentRefNo ?? '—'} -

-

{capa.description}

-
+
+

{capa.description}

+
+ + + From{' '} + + {capa.incidentRefNo ?? '—'} + +
+ {capa.rootCauseRef &&

Root cause: {capa.rootCauseRef}

} +
-
-
-

Owner

-

{capa.ownerName ?? '—'}

-
-
-

Department

-

{capa.department}

-
-
-

Due Date

-

{capa.dueDate}

-
-
-

Status

-

{status.replace(/_/g, ' ')}

-
- {capa.ownerNotes && ( -
-

Owner Notes

-

{capa.ownerNotes}

+
+
+ {canAct && ( +
+
)} + + {isHse && status === 'pending_verification' && } + {isHse && status === 'verified' && } + + {(capa.ownerNotes || capa.completedAt) && ( +
+

Completion report

+ {capa.completedAt && ( +

+ Completed {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })} +

+ )} + {capa.ownerNotes && ( +

{capa.ownerNotes}

+ )} +
+ )}
- {capa.rootCauseRef && ( -
-

Root Cause Reference

-

{capa.rootCauseRef}

-
- )} - - {capa.completedAt && ( -

- Completed: {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })} -

- )} +
- - {['open', 'in_progress', 'overdue', 'reopened'].includes(status) && - (isHse || session?.sub === capa.ownerUserId) && ( - - )} - - {isHse && status === 'pending_verification' && ( - - )} - - {isHse && status === 'verified' && ( - - )} -
+ ) } diff --git a/components/capa/capa-owner-actions.tsx b/components/capa/capa-owner-actions.tsx index a75977f..e2d33ed 100644 --- a/components/capa/capa-owner-actions.tsx +++ b/components/capa/capa-owner-actions.tsx @@ -2,6 +2,7 @@ import { useState } from 'react' import { useRouter } from 'next/navigation' +import { Button } from '@/components/ui/button' interface Props { capaId: string @@ -33,25 +34,17 @@ export function CapaOwnerActions({ capaId, currentStatus }: Props) { if (currentStatus === 'open' || currentStatus === 'reopened' || currentStatus === 'overdue') { return ( - + ) } if (currentStatus === 'in_progress') { return ( - + ) } diff --git a/components/capa/capa-owner-notes-form.tsx b/components/capa/capa-owner-notes-form.tsx index 3d71956..3d461c7 100644 --- a/components/capa/capa-owner-notes-form.tsx +++ b/components/capa/capa-owner-notes-form.tsx @@ -1,6 +1,8 @@ 'use client' import { useState } from 'react' +import { Button } from '@/components/ui/button' +import { Field, Textarea } from '@/components/ui/field' interface Props { capaId: string @@ -32,25 +34,22 @@ export function CapaOwnerNotesForm({ capaId, initialNotes }: Props) { } return ( -
- -