feat(capa): allow overdue CAPAs to be acted on, fix owner page stats

- CapaOwnerActions: add 'overdue' to open/reopened branch so DB-overdue
  CAPAs show 'Mark In Progress' button (cron transitions open→overdue)
- capa-owner page: compute overdue at runtime (dueDate < today) so stats
  and red highlight are correct even before cron runs
- openCount now excludes overdue items to avoid double-counting
- Add CapaOwnerActions test suite covering all status transitions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HEYxFQiCyxJvnBCoZeYzB9
This commit is contained in:
2026-07-30 08:41:41 +08:00
co-authored by Claude Sonnet 4.6
parent 3fd8dfe294
commit a4253a80f5
3 changed files with 50 additions and 4 deletions
+9 -3
View File
@@ -52,8 +52,14 @@ export default async function CapaOwnerPage() {
.orderBy(asc(capaActions.dueDate))
)
const openCount = rows.filter(c => ['open', 'in_progress', 'reopened'].includes(c.status)).length
const overdueCount = rows.filter(c => c.status === 'overdue').length
const today = new Date().toISOString().slice(0, 10)
function isCapaOverdue(c: { status: string; dueDate: string | null }): boolean {
if (c.status === 'overdue') return true
return (c.status === 'open' || c.status === 'in_progress') && !!c.dueDate && c.dueDate < today
}
const openCount = rows.filter(c => ['open', 'in_progress', 'reopened'].includes(c.status) && !isCapaOverdue(c)).length
const overdueCount = rows.filter(c => isCapaOverdue(c)).length
const doneCount = rows.filter(c => ['verified', 'closed'].includes(c.status)).length
const PRIORITY_COLORS: Record<string, string> = {
@@ -82,7 +88,7 @@ export default async function CapaOwnerPage() {
) : (
<div className="bg-white rounded-xl shadow-sm divide-y divide-gray-50">
{activeRows.map(capa => {
const isOverdue = capa.status === 'overdue'
const isOverdue = isCapaOverdue(capa)
return (
<div key={capa.id} className={`p-4 ${isOverdue ? 'bg-red-50' : ''}`}>
<div className="flex items-start justify-between gap-4">