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 @@
|
||||
|
||||
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 (
|
||||
<button
|
||||
onClick={() => updateStatus('in_progress')}
|
||||
disabled={loading}
|
||||
className="text-sm px-3 py-1.5 border border-divider hover:bg-gray-50 disabled:opacity-50"
|
||||
>
|
||||
<Button variant="secondary" onClick={() => updateStatus('in_progress')} disabled={loading}>
|
||||
{loading ? '…' : 'Mark In Progress'}
|
||||
</button>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
if (currentStatus === 'in_progress') {
|
||||
return (
|
||||
<button
|
||||
onClick={() => updateStatus('pending_verification')}
|
||||
disabled={loading}
|
||||
className="text-sm px-3 py-1.5 bg-accent text-white hover:bg-accent-600 disabled:opacity-50"
|
||||
>
|
||||
<Button onClick={() => updateStatus('pending_verification')} disabled={loading}>
|
||||
{loading ? '…' : 'Submit for Verification'}
|
||||
</button>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<div className="mt-3 space-y-1">
|
||||
<label className="text-xs text-gray-500 font-medium">Remarks / Notes</label>
|
||||
<textarea
|
||||
value={notes}
|
||||
onChange={e => { setNotes(e.target.value); setSaved(false) }}
|
||||
rows={2}
|
||||
placeholder="Add any notes or updates for this action…"
|
||||
className="w-full border border-divider px-3 py-2 text-sm text-gray-800 resize-none focus:outline-none focus:ring-2 focus:ring-accent"
|
||||
/>
|
||||
{error && <p className="text-xs text-red-600">{error}</p>}
|
||||
<div className="mt-3 space-y-2">
|
||||
<Field label="Remarks / Notes" htmlFor={`notes-${capaId}`}>
|
||||
<Textarea
|
||||
id={`notes-${capaId}`}
|
||||
value={notes}
|
||||
onChange={e => { setNotes(e.target.value); setSaved(false) }}
|
||||
rows={2}
|
||||
placeholder="Add any notes or updates for this action…"
|
||||
/>
|
||||
</Field>
|
||||
{error && <p role="alert" className="text-xs text-danger">{error}</p>}
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="text-xs px-3 py-1 bg-gray-800 text-white hover:bg-gray-700 disabled:opacity-50"
|
||||
>
|
||||
<Button variant="secondary" onClick={handleSave} disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save Notes'}
|
||||
</button>
|
||||
{saved && <span className="text-xs text-ink">Saved</span>}
|
||||
</Button>
|
||||
{saved && <span className="text-xs text-st-green-fg">Saved</span>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
interface Props {
|
||||
capaId: string
|
||||
@@ -31,19 +32,21 @@ export function CloseCapaButton({ capaId }: Props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border border-divider p-5 space-y-3 bg-neutral-100">
|
||||
<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-accent text-white py-2 text-sm font-semibold hover:bg-accent-700 disabled:opacity-50"
|
||||
>
|
||||
<div className="space-y-3 rounded-xl bg-surface p-5 shadow-card">
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold">Close CAPA</h3>
|
||||
<p className="mt-0.5 text-xs text-muted">
|
||||
This CAPA has been verified as effective. Close it to mark it fully resolved.
|
||||
</p>
|
||||
</div>
|
||||
{error && (
|
||||
<p role="alert" className="rounded-md bg-st-red-bg px-3 py-2 text-[13px] text-st-red-fg">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<Button onClick={handleClose} disabled={loading}>
|
||||
{loading ? 'Closing…' : 'Close CAPA'}
|
||||
</button>
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,14 +2,47 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Field, Textarea } from '@/components/ui/field'
|
||||
import { cx } from '@/components/ui/cx'
|
||||
|
||||
interface Props {
|
||||
capaId: string
|
||||
}
|
||||
|
||||
type Verdict = 'verified' | 'reopened'
|
||||
|
||||
function Choice({
|
||||
selected,
|
||||
onSelect,
|
||||
title,
|
||||
hint,
|
||||
}: {
|
||||
selected: boolean
|
||||
onSelect: () => void
|
||||
title: string
|
||||
hint: string
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
onClick={onSelect}
|
||||
className={cx(
|
||||
'cursor-pointer rounded-xl p-3 text-left transition-colors',
|
||||
selected ? 'bg-accent-tint shadow-chip-set' : 'bg-surface shadow-chip hover:bg-surface-2',
|
||||
)}
|
||||
>
|
||||
<span className="block text-[13px] font-semibold">{title}</span>
|
||||
<span className="mt-0.5 block text-xs text-muted">{hint}</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export function VerifyForm({ capaId }: Props) {
|
||||
const router = useRouter()
|
||||
const [verdict, setVerdict] = useState<'verified' | 'reopened' | null>(null)
|
||||
const [verdict, setVerdict] = useState<Verdict | null>(null)
|
||||
const [reopenReason, setReopenReason] = useState('')
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
@@ -39,50 +72,50 @@ export function VerifyForm({ capaId }: Props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="border border-divider p-5 space-y-4 bg-accent-100">
|
||||
<h3 className="text-sm font-semibold text-gray-800">HSE Verification</h3>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setVerdict('verified')}
|
||||
className={`flex-1 py-2 text-sm font-medium border ${
|
||||
verdict === 'verified'
|
||||
? 'bg-accent text-white border-accent'
|
||||
: 'bg-surface text-gray-700 border-divider hover:border-accent'
|
||||
}`}
|
||||
>
|
||||
Verified — Effective
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setVerdict('reopened')}
|
||||
className={`flex-1 py-2 text-sm font-medium border ${
|
||||
verdict === 'reopened'
|
||||
? 'bg-accent text-white border-accent'
|
||||
: 'bg-surface text-gray-700 border-divider hover:border-accent'
|
||||
}`}
|
||||
>
|
||||
Reopen — Ineffective
|
||||
</button>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 rounded-xl bg-surface p-5 shadow-card">
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold">Verify this action</h3>
|
||||
<p className="mt-0.5 text-xs text-muted">Confirm the corrective action fixed the root cause, or send it back.</p>
|
||||
</div>
|
||||
|
||||
<div role="radiogroup" aria-label="Verification verdict" className="grid gap-3 sm:grid-cols-2">
|
||||
<Choice
|
||||
selected={verdict === 'verified'}
|
||||
onSelect={() => setVerdict('verified')}
|
||||
title="Verified, effective"
|
||||
hint="Root cause addressed. The action is marked verified."
|
||||
/>
|
||||
<Choice
|
||||
selected={verdict === 'reopened'}
|
||||
onSelect={() => setVerdict('reopened')}
|
||||
title="Reopen, ineffective"
|
||||
hint="Returns to the owner with a required reason."
|
||||
/>
|
||||
</div>
|
||||
|
||||
{verdict === 'reopened' && (
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Why is the action ineffective? *</label>
|
||||
<textarea
|
||||
<Field label="Why is the action ineffective? *" htmlFor="reopen-reason">
|
||||
<Textarea
|
||||
id="reopen-reason"
|
||||
value={reopenReason}
|
||||
onChange={e => setReopenReason(e.target.value)}
|
||||
rows={2} required
|
||||
className="w-full border border-divider px-3 py-2 text-sm"
|
||||
rows={2}
|
||||
required
|
||||
placeholder="Describe why the corrective action did not resolve the root cause…"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
)}
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
|
||||
{error && (
|
||||
<p role="alert" className="rounded-md bg-st-red-bg px-3 py-2 text-[13px] text-st-red-fg">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{verdict && (
|
||||
<button type="submit" disabled={saving}
|
||||
className="w-full bg-gray-900 text-white py-2 text-sm font-semibold disabled:opacity-50">
|
||||
{saving ? 'Saving…' : 'Submit Verification'}
|
||||
</button>
|
||||
<Button type="submit" disabled={saving}>
|
||||
{saving ? 'Saving…' : verdict === 'verified' ? 'Confirm verification' : 'Reopen action'}
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user