feat(capa): restyle the create CAPA form and page with the shared field primitives

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 11:38:44 +08:00
co-authored by Claude Haiku 4.5
parent 587b580797
commit 40878c126a
3 changed files with 132 additions and 42 deletions
+38 -33
View File
@@ -2,6 +2,8 @@
import { useState, useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { Button } from '@/components/ui/button'
import { Field, Input, Select, Textarea } from '@/components/ui/field'
interface User {
id: string
@@ -71,59 +73,62 @@ export function CapaForm({ incidentId }: Props) {
return (
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Action Description *</label>
<textarea
<Field label="Action Description *" htmlFor="capa-description">
<Textarea
id="capa-description"
value={description}
onChange={e => setDescription(e.target.value)}
rows={3} required
className="w-full border border-divider px-3 py-2 text-sm"
rows={3}
required
placeholder="What corrective action will be taken?"
/>
</div>
</Field>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Root Cause Reference</label>
<input type="text" value={rootCauseRef}
<Field label="Root Cause Reference" htmlFor="capa-root-cause">
<Input
id="capa-root-cause"
type="text"
value={rootCauseRef}
onChange={e => setRootCauseRef(e.target.value)}
className="w-full border border-divider px-3 py-2 text-sm"
placeholder="e.g. Why #3 — inadequate training" />
</div>
placeholder="e.g. Why #3 — inadequate training"
/>
</Field>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Assigned To *</label>
<select value={ownerId} onChange={e => handleOwnerChange(e.target.value)} required
className="w-full border border-divider px-3 py-2 text-sm">
<Field label="Assigned To *" htmlFor="capa-owner">
<Select id="capa-owner" value={ownerId} onChange={e => handleOwnerChange(e.target.value)} required>
<option value="">Select owner…</option>
{users.map(u => (
<option key={u.id} value={u.id}>{u.name} ({u.department})</option>
))}
</select>
</div>
</Select>
</Field>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Due Date *</label>
<input type="date" value={dueDate} onChange={e => setDueDate(e.target.value)} required
className="w-full border border-divider px-3 py-2 text-sm" />
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Priority</label>
<select value={priority} onChange={e => setPriority(e.target.value as 'low' | 'med' | 'high')}
className="w-full border border-divider px-3 py-2 text-sm">
<Field label="Due Date *" htmlFor="capa-due">
<Input id="capa-due" type="date" value={dueDate} onChange={e => setDueDate(e.target.value)} required />
</Field>
<Field label="Priority" htmlFor="capa-priority">
<Select
id="capa-priority"
value={priority}
onChange={e => setPriority(e.target.value as 'low' | 'med' | 'high')}
>
<option value="low">Low</option>
<option value="med">Medium</option>
<option value="high">High</option>
</select>
</div>
</Select>
</Field>
</div>
{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>
)}
<button type="submit" disabled={saving}
className="w-full bg-accent text-white py-2 text-sm font-semibold disabled:opacity-50">
<Button type="submit" block disabled={saving}>
{saving ? 'Creating…' : 'Create CAPA Action'}
</button>
</Button>
</form>
)
}