Disabled token validation and session auth on /api/evidence endpoint. Files are stored on secure filesystem with proper directory structure. Path traversal protection remains in place. NOTE: Server running old compiled code - requires rebuild to take effect. Build failing on server (npm/pnpm not found). Need proper deployment pipeline.
250 lines
8.2 KiB
Markdown
250 lines
8.2 KiB
Markdown
# Overdue CAPA Actionable Implementation Plan
|
||
|
||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||
|
||
**Goal:** Allow CAPA owners to act on overdue CAPAs (Mark In Progress / Submit for Verification) and fix overdue count + highlight on the owner page.
|
||
|
||
**Architecture:** Two-file client+server fix. CapaOwnerActions gets `overdue` added to its branch logic. capa-owner page gets runtime overdue computation replacing the DB-status-only check. No schema, API, or migration changes needed.
|
||
|
||
**Tech Stack:** Next.js 15 App Router, React, TypeScript, Vitest
|
||
|
||
## Global Constraints
|
||
- Project root: `/Users/yapweeihan/Desktop/Projects/IMS.nosync`
|
||
- No new npm packages
|
||
- No schema/migration changes
|
||
- Tests: Vitest (`npx vitest run`)
|
||
- Every CAPA status transition already permitted by PATCH `/api/capa/[id]` — no API changes needed
|
||
- Commit with `fix:` prefix, co-authored by Claude
|
||
|
||
---
|
||
|
||
## File Map
|
||
|
||
- **Modify:** `components/capa/capa-owner-actions.tsx` — add `'overdue'` to the `open/reopened` branch
|
||
- **Modify:** `app/(protected)/capa-owner/page.tsx` — add `isCapaOverdue` runtime helper, fix `overdueCount`, `openCount`, and `isOverdue`
|
||
- **Create:** `tests/components/capa/capa-owner-actions.test.tsx` — unit tests for status-branch logic
|
||
|
||
---
|
||
|
||
### Task 1: Fix overdue CAPA action buttons and owner page stats
|
||
|
||
**Files:**
|
||
- Modify: `components/capa/capa-owner-actions.tsx`
|
||
- Modify: `app/(protected)/capa-owner/page.tsx`
|
||
- Create: `tests/components/capa/capa-owner-actions.test.tsx`
|
||
|
||
**Interfaces:**
|
||
- Consumes: `CapaOwnerActions({ capaId: string, currentStatus: string })` — existing component
|
||
- Produces: same component, extended to handle `currentStatus === 'overdue'`
|
||
|
||
---
|
||
|
||
- [ ] **Step 1: Write the failing test**
|
||
|
||
Create `tests/components/capa/capa-owner-actions.test.tsx`:
|
||
|
||
```tsx
|
||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||
import { render, screen } from '@testing-library/react'
|
||
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
||
|
||
// Mock Next.js router
|
||
vi.mock('next/navigation', () => ({
|
||
useRouter: () => ({ refresh: vi.fn() }),
|
||
}))
|
||
|
||
describe('CapaOwnerActions', () => {
|
||
it('shows Mark In Progress for open status', () => {
|
||
render(<CapaOwnerActions capaId="abc" currentStatus="open" />)
|
||
expect(screen.getByText('Mark In Progress')).toBeTruthy()
|
||
})
|
||
|
||
it('shows Mark In Progress for reopened status', () => {
|
||
render(<CapaOwnerActions capaId="abc" currentStatus="reopened" />)
|
||
expect(screen.getByText('Mark In Progress')).toBeTruthy()
|
||
})
|
||
|
||
it('shows Mark In Progress for overdue status', () => {
|
||
render(<CapaOwnerActions capaId="abc" currentStatus="overdue" />)
|
||
expect(screen.getByText('Mark In Progress')).toBeTruthy()
|
||
})
|
||
|
||
it('shows Submit for Verification for in_progress status', () => {
|
||
render(<CapaOwnerActions capaId="abc" currentStatus="in_progress" />)
|
||
expect(screen.getByText('Submit for Verification')).toBeTruthy()
|
||
})
|
||
|
||
it('renders nothing for pending_verification status', () => {
|
||
const { container } = render(<CapaOwnerActions capaId="abc" currentStatus="pending_verification" />)
|
||
expect(container.firstChild).toBeNull()
|
||
})
|
||
|
||
it('renders nothing for verified status', () => {
|
||
const { container } = render(<CapaOwnerActions capaId="abc" currentStatus="verified" />)
|
||
expect(container.firstChild).toBeNull()
|
||
})
|
||
})
|
||
```
|
||
|
||
- [ ] **Step 2: Run test to verify it fails**
|
||
|
||
```bash
|
||
cd /Users/yapweeihan/Desktop/Projects/IMS.nosync
|
||
npx vitest run tests/components/capa/capa-owner-actions.test.tsx 2>&1 | tail -20
|
||
```
|
||
|
||
Expected: FAIL — "shows Mark In Progress for overdue status" fails because `overdue` hits `return null`.
|
||
|
||
- [ ] **Step 3: Fix `CapaOwnerActions` — add `'overdue'` to first branch**
|
||
|
||
Replace `components/capa/capa-owner-actions.tsx` entirely:
|
||
|
||
```tsx
|
||
'use client'
|
||
|
||
import { useState } from 'react'
|
||
import { useRouter } from 'next/navigation'
|
||
|
||
interface Props {
|
||
capaId: string
|
||
currentStatus: string
|
||
}
|
||
|
||
export function CapaOwnerActions({ capaId, currentStatus }: Props) {
|
||
const router = useRouter()
|
||
const [loading, setLoading] = useState(false)
|
||
|
||
async function updateStatus(status: string) {
|
||
setLoading(true)
|
||
try {
|
||
const res = await fetch(`/api/capa/${capaId}`, {
|
||
method: 'PATCH',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ status }),
|
||
})
|
||
if (!res.ok) {
|
||
alert('Update failed. Please try again.')
|
||
return
|
||
}
|
||
router.refresh()
|
||
setTimeout(() => window.location.reload(), 300)
|
||
} finally {
|
||
setLoading(false)
|
||
}
|
||
}
|
||
|
||
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-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50"
|
||
>
|
||
{loading ? '…' : 'Mark In Progress'}
|
||
</button>
|
||
)
|
||
}
|
||
|
||
if (currentStatus === 'in_progress') {
|
||
return (
|
||
<button
|
||
onClick={() => updateStatus('pending_verification')}
|
||
disabled={loading}
|
||
className="text-sm px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50"
|
||
>
|
||
{loading ? '…' : 'Submit for Verification'}
|
||
</button>
|
||
)
|
||
}
|
||
|
||
return null
|
||
}
|
||
```
|
||
|
||
- [ ] **Step 4: Run test to verify it passes**
|
||
|
||
```bash
|
||
npx vitest run tests/components/capa/capa-owner-actions.test.tsx 2>&1 | tail -10
|
||
```
|
||
|
||
Expected: PASS — 6/6 tests passing.
|
||
|
||
- [ ] **Step 5: Fix `capa-owner/page.tsx` — runtime overdue computation**
|
||
|
||
In `app/(protected)/capa-owner/page.tsx`, replace the three broken lines:
|
||
|
||
**Find (lines ~55–57 and ~85):**
|
||
```tsx
|
||
const openCount = rows.filter(c => ['open', 'in_progress', 'reopened'].includes(c.status)).length
|
||
const overdueCount = rows.filter(c => c.status === 'overdue').length
|
||
const doneCount = rows.filter(c => ['verified', 'closed'].includes(c.status)).length
|
||
```
|
||
and (inside the `activeRows.map` render):
|
||
```tsx
|
||
const isOverdue = capa.status === 'overdue'
|
||
```
|
||
|
||
**Replace with:**
|
||
|
||
After the `rows` assignment (before `openCount`), add the helper and recompute all three counts:
|
||
|
||
```tsx
|
||
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
|
||
```
|
||
|
||
And inside the map:
|
||
```tsx
|
||
const isOverdue = isCapaOverdue(capa)
|
||
```
|
||
|
||
Full updated file for reference (show only changed regions, not the entire file — use Edit tool on the exact strings above).
|
||
|
||
- [ ] **Step 6: Build check**
|
||
|
||
```bash
|
||
npm run build 2>&1 | tail -5
|
||
```
|
||
|
||
Expected output ends with:
|
||
```
|
||
ƒ (Dynamic) server-rendered on demand
|
||
```
|
||
No TypeScript errors.
|
||
|
||
- [ ] **Step 7: Commit**
|
||
|
||
```bash
|
||
git add components/capa/capa-owner-actions.tsx \
|
||
app/\(protected\)/capa-owner/page.tsx \
|
||
tests/components/capa/capa-owner-actions.test.tsx
|
||
git commit -m "fix(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
|
||
|
||
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>"
|
||
```
|
||
|
||
---
|
||
|
||
Plan complete and saved to `docs/superpowers/plans/2026-07-30-overdue-capa-actionable.md`.
|
||
|
||
**Two execution options:**
|
||
|
||
**1. Subagent-Driven (recommended)** — I dispatch a fresh subagent per task, review between tasks, fast iteration
|
||
|
||
**2. Inline Execution** — Execute tasks in this session using executing-plans, batch execution with checkpoints
|
||
|
||
**Which approach?**
|