Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a33ec0a234 | ||
|
|
fd78e72669 | ||
|
|
40878c126a | ||
|
|
587b580797 | ||
|
|
572a9c9484 | ||
|
|
4f6afacea4 | ||
|
|
12e017d1d0 | ||
|
|
87f553321b | ||
|
|
582504c24b | ||
|
|
a64b951922 | ||
|
|
9ba708ecb7 | ||
|
|
32dd42ac79 | ||
|
|
2a5b9332c7 | ||
|
|
01343d732e | ||
|
|
9ed8c97c24 | ||
|
|
f117605775 | ||
|
|
86d907afda | ||
|
|
bbe038e3aa | ||
|
|
137780d013 | ||
|
|
c5a98eed06 | ||
|
|
ba9eeefe47 | ||
|
|
0b5020b3d0 | ||
|
|
e7416bf236 | ||
|
|
4411ed54b5 | ||
|
|
3a941a357b | ||
|
|
8701d24c6c | ||
|
|
106136e902 | ||
|
|
ef7f1c9660 | ||
|
|
bf178d5b8d | ||
|
|
38ccc44933 | ||
|
|
d2707ac3df | ||
|
|
cbc01b9de5 |
@@ -51,3 +51,6 @@ graphify-out/
|
|||||||
|
|
||||||
# iCloud sync conflict copies ("name 2.ext")
|
# iCloud sync conflict copies ("name 2.ext")
|
||||||
* 2.*
|
* 2.*
|
||||||
|
|
||||||
|
# local scratch (data exports, deploy archives)
|
||||||
|
tmp/
|
||||||
|
|||||||
@@ -5,53 +5,67 @@ HSE Incident Management System for Setia Corporation (3PL warehouse).
|
|||||||
Replaces WhatsApp/Excel safety reporting. Client: Ms. Agnes, Mr. Terence, Mr. Yap, Mr. Jensen.
|
Replaces WhatsApp/Excel safety reporting. Client: Ms. Agnes, Mr. Terence, Mr. Yap, Mr. Jensen.
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
- **Frontend + API routes:** Next.js (App Router)
|
- **Frontend + API routes:** Next.js 16 (App Router)
|
||||||
- **DB + Auth + Storage:** Supabase (Postgres + RLS + pgvector)
|
- **Database:** self-hosted PostgreSQL on the production server (`127.0.0.1:5433`, db `ims`) with RLS and pgvector. Access through Drizzle ORM + `pg`. Supabase is no longer used (migrated 2026-09-30).
|
||||||
- **Hosting:** VPS at `http://64.176.82.100/ims/` + Supabase cloud
|
- **Auth:** own email + password. `bcryptjs` hashes, `jose` JWT in the `ims_session` cookie (8h), checked in `middleware.ts`. No Supabase GoTrue.
|
||||||
- **AI:** Claude API — server-side only, never client-side
|
- **Storage:** evidence files on the server filesystem (`EVIDENCE_DIR`, `/var/lib/ims-evidence`), served through `/api/evidence/...` with HMAC-signed URLs (`EVIDENCE_URL_SECRET`). Backed up nightly.
|
||||||
- **Email:** Resend
|
- **Hosting:** own server `175.136.239.121` (SSH port 9321), nginx → systemd service `ims` on port 3003 at https://ims.setia.com.my
|
||||||
|
- **AI:** DeepSeek via the OpenAI-compatible client (`lib/claude/client.ts`; key set in Settings or `DEEPSEEK_API_KEY`) for quality check, triage, RCA, risk flags and bulk import. Embeddings (similar incidents) use Google `text-embedding-004` (`GOOGLE_AI_API_KEY`). Server-side only, never client-side.
|
||||||
|
- **Email:** Brevo (`BREVO_API_KEY`, `BREVO_FROM_EMAIL`, `BREVO_FROM_NAME`). Resend is no longer used.
|
||||||
- **WhatsApp:** Meta WhatsApp Business Cloud API
|
- **WhatsApp:** Meta WhatsApp Business Cloud API
|
||||||
- **PDF:** pdf-lib (JKKP form fill)
|
- **PDF:** pdf-lib (JKKP form fill, incident report)
|
||||||
- **QR:** qrcode npm package
|
- **QR:** qrcode npm package
|
||||||
|
|
||||||
## Current Phase
|
## Current Phase
|
||||||
**All phases (0–6) complete as of 2026-07-12.** Remaining work is ops: production env vars (`SUPABASE_SERVICE_ROLE_KEY`, Meta WhatsApp, Resend, `CRON_SECRET`), VPS cron registration (`docs/vps-cron.md`), optional Supabase Pro for image thumbnails.
|
**All phases (0–6) complete as of 2026-07-12.** Supabase to local PostgreSQL migration completed and live 2026-09-30.
|
||||||
|
**UI refresh in progress:** follow `design-system/design.md` §8 build order (tokens → ui primitives → TableCard → shells → migrate Incidents list → remaining screens).
|
||||||
|
Legacy leftovers to remove when convenient: `lib/supabase/*`, the `@supabase/*` dependencies and the `supabase/` folder (the app no longer imports them; `db/schema.sql` + `db/rls.sql` are the schema source of truth).
|
||||||
See `[[phases]]` memory for full phase breakdown and deliverables.
|
See `[[phases]]` memory for full phase breakdown and deliverables.
|
||||||
|
|
||||||
## Deployment (Production)
|
## Deployment (Production)
|
||||||
|
|
||||||
**Deploy path for ims.setia.com.my is `/var/www/ims` on 175.136.239.121:9321.**
|
Host `ims.setia.com.my` (175.136.239.121), SSH port 9321, user `setia`. The server holds **build output only, no source**.
|
||||||
|
|
||||||
```bash
|
- **NEVER run `next build`, `pnpm build` or `npm ci` on the server.** A build without source deletes the working `.next` (took production down on 2026-09-30).
|
||||||
# Correct deployment:
|
- App files: `/srv/apps/ims/app` (`/var/www/ims` is a symlink to it). Service: systemd `ims` (`node server.js`, port 3003). Restart: `sudo systemctl restart ims`.
|
||||||
tar -czf - package.json package-lock.json .next | \
|
- Env files live in `/srv/apps/ims/shared/` (`.env`, `.env.production`); `app/.env*` are links to them. Never overwrite, delete or ship `.env*`.
|
||||||
ssh -p 9321 setia@175.136.239.121 "cd /var/www/ims && tar -xzf -"
|
- Evidence files: `/var/lib/ims-evidence` (do not touch). A deploy never runs DB migrations; ask before changing the DB.
|
||||||
pm2 restart wsims
|
- Cron: two daily jobs call `http://127.0.0.1:3003/api/cron/...` with `CRON_SECRET` from `shared/.env` (`docs/vps-cron.md`).
|
||||||
```
|
|
||||||
|
|
||||||
PM2 process `wsims` runs from `/var/www/ims`. Nginx proxies `ims.setia.com.my` → `http://127.0.0.1:3003`.
|
Deploy steps:
|
||||||
|
1. Build locally: `npm run build` (`output: 'standalone'`).
|
||||||
|
2. Stage and upload without any `.env*` or macOS `._*` files (use `COPYFILE_DISABLE=1 tar --exclude='.env*' --exclude='._*'`). Only `server.js`, `package.json`, `node_modules`, `.next` (standalone `.next` plus `.next/static`) and `public` are needed, since the standalone output otherwise drags in the whole project.
|
||||||
|
3. On the server confirm `/srv/apps/ims/app/.next/BUILD_ID` exists, then `sudo systemctl restart ims`. Never restart if `BUILD_ID` is missing.
|
||||||
|
4. Verify https://ims.setia.com.my/login returns 200 and `systemctl is-active ims` is `active`. Keep a rollback copy first: `tar -czf /srv/apps/ims/next-backup-<date>.tgz .next`.
|
||||||
|
|
||||||
## Dev Conventions
|
## Dev Conventions
|
||||||
- Never commit `.env` or API keys. All secrets in env vars only.
|
- Never commit `.env` or API keys. All secrets in env vars only.
|
||||||
- RLS enforced at DB level for every table — never rely on UI-only hiding.
|
- RLS enforced at DB level for every table (`db/rls.sql`) — never rely on UI-only hiding. Query through `withUser` (RLS as the signed-in user) or `asAdmin` from `lib/db/with-user.ts`; do the write and its `audit_log` entry in one transaction.
|
||||||
- Claude API calls: server-side API routes only (`/app/api/...`).
|
- AI calls: server-side API routes only (`/app/api/...`).
|
||||||
- Incident reference format: `SITE-YYYYMM-####`
|
- Incident reference format: `SITE-YYYYMM-####`
|
||||||
- Every DB mutation writes to `audit_log` (table, record_id, action, changed_by, changed_at, old/new value).
|
- Every DB mutation writes to `audit_log` (table, record_id, action, changed_by, changed_at, old/new value).
|
||||||
- Evidence files: never hard-delete; retain minimum 5 years (DOSH JKKP 8 requirement).
|
- Evidence files: never hard-delete; retain minimum 5 years (DOSH JKKP 8 requirement).
|
||||||
- AI suggestions logged to `audit_log` — capture what Claude suggested + what human chose.
|
- AI suggestions logged to `audit_log` — capture what the AI suggested + what the human chose.
|
||||||
|
- Schema changes: edit `db/schema.sql` / `db/rls.sql` and apply by hand to the server database with the owner's go-ahead.
|
||||||
|
|
||||||
## File Structure (target)
|
## File Structure
|
||||||
```
|
```
|
||||||
IMS/
|
IMS/
|
||||||
├── docs/ # PRD, tech spec, roadmap, specs — source of truth
|
├── docs/ # PRD, tech spec, roadmap, specs — source of truth
|
||||||
|
├── design-system/ # design.md (UI source of truth) + .dc.html references
|
||||||
├── app/ # Next.js App Router pages + API routes
|
├── app/ # Next.js App Router pages + API routes
|
||||||
├── components/ # Shared UI components
|
├── components/
|
||||||
|
│ ├── ui/ # Button, StatusTag, TableCard, … (design.md §4)
|
||||||
|
│ └── layout/ # AppShell, MobileShell
|
||||||
├── lib/
|
├── lib/
|
||||||
│ ├── supabase/ # Supabase client + server helpers
|
│ ├── db/ # Drizzle schema, withUser/asAdmin, audit helper
|
||||||
│ ├── claude/ # Claude API wrappers (server-side)
|
│ ├── auth/ # bcryptjs passwords, jose sessions, roles
|
||||||
│ └── notifications/ # Resend + WhatsApp senders
|
│ ├── storage/ # evidence files on disk + signed URLs
|
||||||
├── supabase/
|
│ ├── claude/ # AI client (DeepSeek) + Google embeddings
|
||||||
│ └── migrations/ # SQL migration files
|
│ ├── notifications/ # Brevo email + WhatsApp senders, in-app
|
||||||
|
│ └── supabase/ # LEGACY, unused, to be removed
|
||||||
|
├── db/ # schema.sql, rls.sql, migration/ops scripts
|
||||||
|
├── supabase/ # LEGACY migrations, to be removed
|
||||||
└── public/
|
└── public/
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -62,6 +76,23 @@ IMS/
|
|||||||
- `[[phases]]` — 4 phases + deliverables, current phase
|
- `[[phases]]` — 4 phases + deliverables, current phase
|
||||||
- `[[compliance]]` — NADOPOD 2004, JKKP 6/7/8 rules
|
- `[[compliance]]` — NADOPOD 2004, JKKP 6/7/8 rules
|
||||||
|
|
||||||
|
## Design system (IMS Admin refresh)
|
||||||
|
|
||||||
|
Source of truth: `design-system/design.md`. Visual references: `design-system/IMS Admin.dc.html` (screens) and `design-system/IMS Admin Spec.dc.html` (patterns). Tokens live in `app/globals.css` (`@theme static`) and mirror design.md §2. The Modernist files under `design-system/_ds/` are retired; do not use them as a style reference.
|
||||||
|
|
||||||
|
- Neutral commerce-admin style: Geist (`--font-geist`, `--font-geist-mono`), ink `#1f1f1f` on `#f1f1f1` ground, white cards radius 12 with the `shadow-card` ring, one teal accent `#0f766e`. Rules are 1px (`border-rule`), never 2px.
|
||||||
|
- Use tokens, never hard-coded hex, font names or px values the tokens carry: `bg-ground`, `bg-surface`, `bg-surface-2`, `text-ink`, `text-muted`, `text-faint`, `border-rule`, `border-ring`, `bg-accent`, `bg-accent-tint`, `text-danger`, and the `st-*` status pairs. `gray-*`/`blue-*`/`red-*` remaps stay only until legacy pages are migrated.
|
||||||
|
- Radius comes from the scale: `rounded-md` (8) buttons, chips, inputs, pills; `rounded-xl` (12) cards and mobile controls; `rounded-[5px]` checkbox. Headings and labels are flush left.
|
||||||
|
- Status and priority colours only via `StatusTag` / `PriorityTag` (design.md §4.2): dark text on a light tint, text label always present, no icon required. Add new statuses in `components/ui/status-tag.tsx`, not per page.
|
||||||
|
- Every list is a `TableCard` (design.md §4.9): saved views, toolbar, sortable header, row hover quick actions, selected tint, footer pager, floating bulk bar, empty state, mobile stacked variant. Do not hand-build tables.
|
||||||
|
- Build UI with `components/ui/*`: `Button`, `StatusTag`, `PriorityTag`, `Checkbox`, `Field`/`Input`/`Select`/`Textarea`, `FilterChip`, `Segmented`, `Avatar`, `Card`, `Drawer`, `TableCard`; pages sit in `AppShell` (desktop) or `MobileShell` (reporter / CAPA owner).
|
||||||
|
- Icons: Lucide (`lucide-react`), 16px stroke 2 in UI, 12px stroke 2.5 inside chips and checks, 22px stroke 1.8 in the mobile tab bar.
|
||||||
|
- Interaction: hover/active values per component in design.md §4; `:focus-visible` 2px accent ring is global; transitions 120ms on bg/shadow only; mobile hit targets ≥ 44px.
|
||||||
|
- Incident evidence photos stay full colour.
|
||||||
|
- New pattern needed? Check design.md first. If it isn't there, design it in the design tool, then add it to design.md in the same PR as the component.
|
||||||
|
- Gotcha: never write `*/` inside a CSS comment in `globals.css`; it ends the comment and silently swallows the `@theme` block.
|
||||||
|
- Run `npm run check:design` before committing UI changes; it must print `design gates: clean`. The gate flags 2px borders, `Archivo`, hard-coded hex, `bg-white`, `shadow-xl/2xl`, centered button labels and off-palette hues; rounded corners are allowed. Extend `scripts/check-design-gates.mjs` when design.md adds a rule.
|
||||||
|
|
||||||
## graphify
|
## graphify
|
||||||
When graphify-out/graph.json exists:
|
When graphify-out/graph.json exists:
|
||||||
- Run `graphify query "<question>"` before browsing source.
|
- Run `graphify query "<question>"` before browsing source.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default function ForgotPasswordPage() {
|
|||||||
<p className="text-sm text-gray-500">
|
<p className="text-sm text-gray-500">
|
||||||
If an account exists for <strong>{email}</strong>, a password reset link has been sent.
|
If an account exists for <strong>{email}</strong>, a password reset link has been sent.
|
||||||
</p>
|
</p>
|
||||||
<Link href="/login" className="text-sm text-blue-600 hover:underline">
|
<Link href="/login" className="text-sm text-accent-700 hover:underline">
|
||||||
Back to sign in
|
Back to sign in
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,19 +57,19 @@ export default function ForgotPasswordPage() {
|
|||||||
onChange={e => setEmail(e.target.value)}
|
onChange={e => setEmail(e.target.value)}
|
||||||
required
|
required
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="border border-divider px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 rounded-md disabled:opacity-50 transition-colors"
|
className="bg-accent hover:bg-accent-600 text-white font-medium py-2 disabled:opacity-50 transition-colors"
|
||||||
>
|
>
|
||||||
{loading ? 'Sending…' : 'Send reset link'}
|
{loading ? 'Sending…' : 'Send reset link'}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p className="text-center text-sm text-gray-500">
|
<p className="text-center text-sm text-gray-500">
|
||||||
<Link href="/login" className="text-blue-600 hover:underline">
|
<Link href="/login" className="text-accent-700 hover:underline">
|
||||||
Back to sign in
|
Back to sign in
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ interface Props {
|
|||||||
export default async function LoginPage({ searchParams }: Props) {
|
export default async function LoginPage({ searchParams }: Props) {
|
||||||
const { message } = await searchParams
|
const { message } = await searchParams
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen flex items-center justify-center bg-gray-50 p-4">
|
<main className="min-h-screen flex items-center justify-center bg-ground p-4">
|
||||||
{message === 'password_reset' && (
|
{message === 'password_reset' && (
|
||||||
<div className="fixed top-4 left-1/2 -translate-x-1/2 bg-green-50 border border-green-200 text-green-700 text-sm rounded px-4 py-2 shadow">
|
<div className="fixed top-4 left-1/2 -translate-x-1/2 bg-st-green-bg text-st-green-fg text-[13px] px-4 py-2 rounded-md shadow-float">
|
||||||
Password updated — sign in with your new password.
|
Password updated — sign in with your new password.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="bg-white rounded-xl shadow-sm border p-8 w-full max-w-sm">
|
<div className="bg-surface rounded-xl shadow-card p-8 w-full max-w-sm">
|
||||||
<LoginForm />
|
<LoginForm />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export default function ResetPasswordPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<p className="bg-red-50 border border-red-200 text-red-700 text-sm rounded px-3 py-2">
|
<p className="bg-red-50 border border-red-200 text-red-700 text-sm px-3 py-2">
|
||||||
{error}{' '}
|
{error}{' '}
|
||||||
{error.includes('expired') && (
|
{error.includes('expired') && (
|
||||||
<Link href="/forgot-password" className="underline">
|
<Link href="/forgot-password" className="underline">
|
||||||
@@ -68,7 +68,7 @@ export default function ResetPasswordPage() {
|
|||||||
required
|
required
|
||||||
minLength={8}
|
minLength={8}
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="border border-divider px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
@@ -77,13 +77,13 @@ export default function ResetPasswordPage() {
|
|||||||
onChange={e => setConfirm(e.target.value)}
|
onChange={e => setConfirm(e.target.value)}
|
||||||
required
|
required
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
className="border border-gray-300 rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="border border-divider px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 rounded-md disabled:opacity-50 transition-colors"
|
className="bg-accent hover:bg-accent-600 text-white font-medium py-2 disabled:opacity-50 transition-colors"
|
||||||
>
|
>
|
||||||
{loading ? 'Saving…' : 'Set password'}
|
{loading ? 'Saving…' : 'Set password'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default async function AdminHome() {
|
|||||||
<p className="text-sm text-gray-500 mt-0.5">Manage users, sites, zones, and trucks</p>
|
<p className="text-sm text-gray-500 mt-0.5">Manage users, sites, zones, and trucks</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-6 flex gap-3">
|
<div className="mb-6 flex gap-3">
|
||||||
<Link href="/bulk-import" className="px-4 py-2 bg-green-600 text-white rounded-lg text-sm font-medium hover:bg-green-700">
|
<Link href="/bulk-import" className="px-4 py-2 bg-accent text-white text-sm font-medium hover:bg-accent-600">
|
||||||
Bulk Import Incidents
|
Bulk Import Incidents
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { eq, asc } from 'drizzle-orm'
|
|||||||
import { StatCard } from '@/components/dashboard/stat-card'
|
import { StatCard } from '@/components/dashboard/stat-card'
|
||||||
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
||||||
import { CapaOwnerNotesForm } from '@/components/capa/capa-owner-notes-form'
|
import { CapaOwnerNotesForm } from '@/components/capa/capa-owner-notes-form'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
open: 'Open',
|
open: 'Open',
|
||||||
@@ -20,16 +21,6 @@ const STATUS_LABELS: Record<string, string> = {
|
|||||||
closed: 'Closed',
|
closed: 'Closed',
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
open: 'bg-gray-100 text-gray-700',
|
|
||||||
in_progress: 'bg-blue-100 text-blue-700',
|
|
||||||
overdue: 'bg-red-100 text-red-700',
|
|
||||||
pending_verification: 'bg-purple-100 text-purple-700',
|
|
||||||
verified: 'bg-green-100 text-green-700',
|
|
||||||
reopened: 'bg-orange-100 text-orange-700',
|
|
||||||
closed: 'bg-gray-100 text-gray-500',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function CapaOwnerPage() {
|
export default async function CapaOwnerPage() {
|
||||||
const session = await getSession()
|
const session = await getSession()
|
||||||
if (!session) redirect('/login')
|
if (!session) redirect('/login')
|
||||||
@@ -63,9 +54,9 @@ export default async function CapaOwnerPage() {
|
|||||||
const doneCount = rows.filter(c => ['verified', 'closed'].includes(c.status)).length
|
const doneCount = rows.filter(c => ['verified', 'closed'].includes(c.status)).length
|
||||||
|
|
||||||
const PRIORITY_COLORS: Record<string, string> = {
|
const PRIORITY_COLORS: Record<string, string> = {
|
||||||
high: 'text-red-600 font-semibold',
|
high: 'text-accent-700 font-extrabold',
|
||||||
med: 'text-orange-500 font-medium',
|
med: 'text-accent-700 font-medium',
|
||||||
low: 'text-gray-400',
|
low: 'text-ink/50',
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeRows = rows.filter(c => !['verified', 'closed'].includes(c.status))
|
const activeRows = rows.filter(c => !['verified', 'closed'].includes(c.status))
|
||||||
@@ -82,11 +73,11 @@ export default async function CapaOwnerPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{activeRows.length === 0 ? (
|
{activeRows.length === 0 ? (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-8 text-center">
|
<div className="bg-surface shadow-sm p-8 text-center">
|
||||||
<p className="text-gray-400 text-sm">No active CAPAs assigned to you.</p>
|
<p className="text-gray-400 text-sm">No active CAPAs assigned to you.</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-white rounded-xl shadow-sm divide-y divide-gray-50">
|
<div className="bg-surface shadow-sm divide-y divide-gray-50">
|
||||||
{activeRows.map(capa => {
|
{activeRows.map(capa => {
|
||||||
const isOverdue = isCapaOverdue(capa)
|
const isOverdue = isCapaOverdue(capa)
|
||||||
return (
|
return (
|
||||||
@@ -95,15 +86,13 @@ export default async function CapaOwnerPage() {
|
|||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<p className="text-sm text-gray-800">{capa.description}</p>
|
<p className="text-sm text-gray-800">{capa.description}</p>
|
||||||
{capa.incidentRefNo && (
|
{capa.incidentRefNo && (
|
||||||
<Link href={`/hse/incidents/${capa.incidentId}`} className="text-xs text-blue-600 hover:underline mt-0.5 inline-block">
|
<Link href={`/hse/incidents/${capa.incidentId}`} className="text-xs text-accent-700 hover:underline mt-0.5 inline-block">
|
||||||
{capa.incidentRefNo}
|
{capa.incidentRefNo}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="shrink-0 text-right space-y-1">
|
<div className="shrink-0 text-right space-y-1">
|
||||||
<span className={`text-xs rounded-full px-2 py-0.5 ${STATUS_COLORS[capa.status] ?? 'bg-gray-100 text-gray-600'}`}>
|
<StatusTag status={capa.status}>{STATUS_LABELS[capa.status] ?? capa.status}</StatusTag>
|
||||||
{STATUS_LABELS[capa.status] ?? capa.status}
|
|
||||||
</span>
|
|
||||||
<p className={`text-xs ${isOverdue ? 'text-red-600 font-semibold' : 'text-gray-400'}`}>
|
<p className={`text-xs ${isOverdue ? 'text-red-600 font-semibold' : 'text-gray-400'}`}>
|
||||||
{capa.dueDate ? `Due ${new Date(capa.dueDate).toLocaleDateString('en-MY')}` : 'No due date'}
|
{capa.dueDate ? `Due ${new Date(capa.dueDate).toLocaleDateString('en-MY')}` : 'No due date'}
|
||||||
</p>
|
</p>
|
||||||
@@ -127,13 +116,11 @@ export default async function CapaOwnerPage() {
|
|||||||
{doneRows.length > 0 && (
|
{doneRows.length > 0 && (
|
||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<h2 className="text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2">Completed ({doneCount})</h2>
|
<h2 className="text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2">Completed ({doneCount})</h2>
|
||||||
<div className="bg-white rounded-xl shadow-sm divide-y divide-gray-50 opacity-60">
|
<div className="bg-surface shadow-sm divide-y divide-gray-50 opacity-60">
|
||||||
{doneRows.map(capa => (
|
{doneRows.map(capa => (
|
||||||
<div key={capa.id} className="p-4 flex items-center justify-between">
|
<div key={capa.id} className="p-4 flex items-center justify-between">
|
||||||
<p className="text-sm text-gray-500 line-clamp-1">{capa.description}</p>
|
<p className="text-sm text-gray-500 line-clamp-1">{capa.description}</p>
|
||||||
<span className={`text-xs rounded-full px-2 py-0.5 ml-4 shrink-0 ${STATUS_COLORS[capa.status] ?? 'bg-gray-100'}`}>
|
<span className="shrink-0"><StatusTag status={capa.status}>{STATUS_LABELS[capa.status] ?? capa.status}</StatusTag></span>
|
||||||
{STATUS_LABELS[capa.status] ?? capa.status}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export const dynamic = 'force-dynamic'
|
|||||||
|
|
||||||
import { notFound, redirect } from 'next/navigation'
|
import { notFound, redirect } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { ArrowLeft } from 'lucide-react'
|
||||||
import { asAdmin } from '@/lib/db/with-user'
|
import { asAdmin } from '@/lib/db/with-user'
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { capaActions, incidents, users } from '@/lib/db/schema'
|
import { capaActions, incidents, users } from '@/lib/db/schema'
|
||||||
@@ -10,15 +11,21 @@ import { aliasedTable } from 'drizzle-orm'
|
|||||||
import { VerifyForm } from '@/components/capa/verify-form'
|
import { VerifyForm } from '@/components/capa/verify-form'
|
||||||
import { CloseCapaButton } from '@/components/capa/close-capa-button'
|
import { CloseCapaButton } from '@/components/capa/close-capa-button'
|
||||||
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
import { CapaOwnerActions } from '@/components/capa/capa-owner-actions'
|
||||||
|
import { Avatar } from '@/components/ui/avatar'
|
||||||
|
import { PriorityTag, StatusTag } from '@/components/ui/status-tag'
|
||||||
|
import { daysLate } from '@/lib/capa/list'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: Promise<{ id: string }>
|
params: Promise<{ id: string }>
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRIORITY_BADGE: Record<string, string> = {
|
function Row({ label, children }: { label: string; children: React.ReactNode }) {
|
||||||
low: 'bg-gray-100 text-gray-600',
|
return (
|
||||||
med: 'bg-yellow-100 text-yellow-700',
|
<div className="flex items-center justify-between gap-3 border-b border-rule py-2.5 last:border-0">
|
||||||
high: 'bg-red-100 text-red-700',
|
<dt className="text-xs text-muted">{label}</dt>
|
||||||
|
<dd className="text-right text-[13px]">{children}</dd>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function CapaDetailPage({ params }: Props) {
|
export default async function CapaDetailPage({ params }: Props) {
|
||||||
@@ -55,77 +62,90 @@ export default async function CapaDetailPage({ params }: Props) {
|
|||||||
|
|
||||||
const isHse = session && ['hse', 'admin'].includes(session.role)
|
const isHse = session && ['hse', 'admin'].includes(session.role)
|
||||||
const status = capa.status
|
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 (
|
return (
|
||||||
<main className="max-w-2xl mx-auto px-4 py-6">
|
<div className="space-y-4 px-4 py-5 md:px-8 md:py-6">
|
||||||
<Link href="/hse/capa" className="text-sm text-blue-600 hover:underline mb-4 inline-block">
|
<Link href="/hse/capa" className="inline-flex items-center gap-1 text-[13px] text-accent hover:underline">
|
||||||
← CAPA Board
|
<ArrowLeft size={14} strokeWidth={2} aria-hidden />
|
||||||
|
CAPA
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4 space-y-4">
|
<div className="space-y-2">
|
||||||
<div className="flex items-start justify-between">
|
<h1 className="text-xl font-[650]">{capa.description}</h1>
|
||||||
<div>
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<p className="text-xs text-gray-500 mb-1">
|
<StatusTag status={shownStatus} />
|
||||||
Incident: {capa.incidentRefNo ?? '—'}
|
<PriorityTag priority={capa.priority} />
|
||||||
</p>
|
<span className="text-[13px] text-muted">
|
||||||
<p className="text-gray-900 font-medium">{capa.description}</p>
|
From{' '}
|
||||||
</div>
|
<Link href={`/hse/incidents/${capa.incidentId}`} className="font-mono text-[12.5px] text-accent hover:underline">
|
||||||
<span className={`px-2 py-1 rounded text-xs font-semibold ${PRIORITY_BADGE[capa.priority] ?? ''}`}>
|
{capa.incidentRefNo ?? '—'}
|
||||||
{capa.priority}
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{capa.rootCauseRef && <p className="text-[13px] text-muted">Root cause: {capa.rootCauseRef}</p>}
|
||||||
<div className="grid grid-cols-2 gap-3 text-sm">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs text-gray-500">Owner</p>
|
|
||||||
<p className="text-gray-800">{capa.ownerName ?? '—'}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs text-gray-500">Department</p>
|
|
||||||
<p className="text-gray-800">{capa.department}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs text-gray-500">Due Date</p>
|
|
||||||
<p className="text-gray-800">{capa.dueDate}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs text-gray-500">Status</p>
|
|
||||||
<p className="text-gray-800 capitalize">{status.replace(/_/g, ' ')}</p>
|
|
||||||
</div>
|
|
||||||
{capa.ownerNotes && (
|
|
||||||
<div className="col-span-2">
|
|
||||||
<p className="text-xs text-gray-500">Owner Notes</p>
|
|
||||||
<p className="text-sm text-gray-800 whitespace-pre-wrap">{capa.ownerNotes}</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{capa.rootCauseRef && (
|
<div className="grid gap-4 lg:grid-cols-[1fr_320px]">
|
||||||
|
<div className="space-y-4">
|
||||||
|
{canAct && (
|
||||||
<div>
|
<div>
|
||||||
<p className="text-xs text-gray-500">Root Cause Reference</p>
|
<CapaOwnerActions capaId={id} currentStatus={status} />
|
||||||
<p className="text-sm text-gray-800">{capa.rootCauseRef}</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isHse && status === 'pending_verification' && <VerifyForm capaId={id} />}
|
||||||
|
{isHse && status === 'verified' && <CloseCapaButton capaId={id} />}
|
||||||
|
|
||||||
|
{(capa.ownerNotes || capa.completedAt) && (
|
||||||
|
<section className="space-y-2 rounded-xl bg-surface p-5 shadow-card">
|
||||||
|
<h2 className="text-sm font-semibold">Completion report</h2>
|
||||||
{capa.completedAt && (
|
{capa.completedAt && (
|
||||||
<p className="text-xs text-gray-500">
|
<p className="text-xs text-muted">
|
||||||
Completed: {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
Completed {new Date(capa.completedAt).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
{capa.ownerNotes && (
|
||||||
|
<p className="whitespace-pre-wrap text-[13px] text-ink-3">{capa.ownerNotes}</p>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{['open', 'in_progress', 'overdue', 'reopened'].includes(status) &&
|
<aside>
|
||||||
(isHse || session?.sub === capa.ownerUserId) && (
|
<section className="rounded-xl bg-surface p-5 shadow-card">
|
||||||
<CapaOwnerActions capaId={id} currentStatus={status} />
|
<h2 className="mb-1 text-sm font-semibold">Details</h2>
|
||||||
|
<dl>
|
||||||
|
<Row label="Owner">
|
||||||
|
{capa.ownerName ? (
|
||||||
|
<span className="inline-flex items-center gap-2">
|
||||||
|
<Avatar name={capa.ownerName} />
|
||||||
|
{capa.ownerName}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
'—'
|
||||||
)}
|
)}
|
||||||
|
</Row>
|
||||||
{isHse && status === 'pending_verification' && (
|
<Row label="Department">{capa.department}</Row>
|
||||||
<VerifyForm capaId={id} />
|
<Row label="Priority"><PriorityTag priority={capa.priority} /></Row>
|
||||||
|
<Row label="Due">
|
||||||
|
{capa.dueDate}
|
||||||
|
{late > 0 && <span className="ml-1.5 text-xs text-danger">{`${late} day${late === 1 ? '' : 's'} late`}</span>}
|
||||||
|
</Row>
|
||||||
|
{capa.completedAt && (
|
||||||
|
<Row label="Completed">
|
||||||
|
{new Date(capa.completedAt).toLocaleDateString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||||
|
</Row>
|
||||||
)}
|
)}
|
||||||
|
</dl>
|
||||||
{isHse && status === 'verified' && (
|
</section>
|
||||||
<CloseCapaButton capaId={id} />
|
</aside>
|
||||||
)}
|
</div>
|
||||||
</main>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
|
||||||
import { asAdmin } from '@/lib/db/with-user'
|
import { asAdmin } from '@/lib/db/with-user'
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { capaActions, incidents, users } from '@/lib/db/schema'
|
import { capaActions, incidents, users } from '@/lib/db/schema'
|
||||||
import { eq, asc } from 'drizzle-orm'
|
import { eq, asc } from 'drizzle-orm'
|
||||||
import { aliasedTable } from 'drizzle-orm'
|
import { aliasedTable } from 'drizzle-orm'
|
||||||
import { CapaBoard } from '@/components/capa/capa-board'
|
import { CapaWorkspace } from '@/components/capa/capa-workspace'
|
||||||
|
import type { CapaRow, CapaStatus } from '@/lib/capa/list'
|
||||||
|
|
||||||
export default async function CapaListPage() {
|
export default async function CapaListPage() {
|
||||||
const session = await getSession()
|
const session = await getSession()
|
||||||
@@ -34,29 +34,23 @@ export default async function CapaListPage() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const today = new Date().toISOString().slice(0, 10)
|
const today = new Date().toISOString().slice(0, 10)
|
||||||
const capas = rows.map(r => ({
|
const capas: CapaRow[] = rows.map(r => ({
|
||||||
id: r.id,
|
id: r.id,
|
||||||
incident_id: r.incidentId,
|
incident_id: r.incidentId,
|
||||||
description: r.description,
|
description: r.description,
|
||||||
department: r.department,
|
department: r.department,
|
||||||
due_date: r.dueDate,
|
due_date: r.dueDate,
|
||||||
priority: r.priority,
|
priority: r.priority,
|
||||||
status: (r.status === 'open' || r.status === 'in_progress') && r.dueDate && r.dueDate < today
|
status: ((r.status === 'open' || r.status === 'in_progress') && r.dueDate && r.dueDate < today
|
||||||
? 'overdue' as const
|
? 'overdue'
|
||||||
: r.status,
|
: r.status) as CapaStatus,
|
||||||
incidents: { reference_no: r.incidentRefNo ?? null },
|
incident_ref: r.incidentRefNo ?? null,
|
||||||
owner: r.ownerName ? { name: r.ownerName } : null,
|
owner_name: r.ownerName ?? null,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-6xl mx-auto px-4 py-6">
|
<div className="px-4 py-5 md:px-8 md:py-6">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<CapaWorkspace capas={capas} today={today} />
|
||||||
<h1 className="text-2xl font-bold text-gray-900">CAPA Board</h1>
|
|
||||||
<Link href="/hse/incidents" className="text-sm text-blue-600 hover:underline">
|
|
||||||
← Incidents
|
|
||||||
</Link>
|
|
||||||
</div>
|
</div>
|
||||||
<CapaBoard capas={capas} />
|
|
||||||
</main>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,17 +165,17 @@ export default async function HseDashboardPage({
|
|||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
<a
|
<a
|
||||||
href="/api/dashboard/export?role=hse"
|
href="/api/dashboard/export?role=hse"
|
||||||
className="text-sm text-gray-500 hover:text-gray-700 border border-gray-200 rounded-lg px-3 py-1.5"
|
className="text-sm text-gray-500 hover:text-gray-700 border border-divider px-3 py-1.5"
|
||||||
>
|
>
|
||||||
Export CSV
|
Export CSV
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href={`/api/reports/jkkp8?year=${now.getFullYear()}`}
|
href={`/api/reports/jkkp8?year=${now.getFullYear()}`}
|
||||||
className="text-sm text-gray-500 hover:text-gray-700 border border-gray-200 rounded-lg px-3 py-1.5"
|
className="text-sm text-gray-500 hover:text-gray-700 border border-divider px-3 py-1.5"
|
||||||
>
|
>
|
||||||
JKKP 8
|
JKKP 8
|
||||||
</a>
|
</a>
|
||||||
<Link href="/hse/incidents" className="text-sm text-blue-600 hover:underline">
|
<Link href="/hse/incidents" className="text-sm text-accent-700 hover:underline">
|
||||||
All incidents →
|
All incidents →
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -187,8 +187,8 @@ export default async function HseDashboardPage({
|
|||||||
{(tab === 'overview') && (
|
{(tab === 'overview') && (
|
||||||
<>
|
<>
|
||||||
{now.getMonth() === 0 && (
|
{now.getMonth() === 0 && (
|
||||||
<div className="bg-amber-50 border border-amber-200 rounded-xl p-4 mb-6">
|
<div className="bg-st-amber-bg rounded-xl p-4 mb-6">
|
||||||
<p className="text-sm text-amber-800">
|
<p className="text-sm text-st-amber-fg">
|
||||||
<strong>JKKP 8 annual register due:</strong> the {now.getFullYear() - 1} register must be
|
<strong>JKKP 8 annual register due:</strong> the {now.getFullYear() - 1} register must be
|
||||||
submitted to DOSH before 31 January {now.getFullYear()}.{' '}
|
submitted to DOSH before 31 January {now.getFullYear()}.{' '}
|
||||||
<a href={`/api/reports/jkkp8?year=${now.getFullYear() - 1}`} className="underline font-medium">
|
<a href={`/api/reports/jkkp8?year=${now.getFullYear() - 1}`} className="underline font-medium">
|
||||||
@@ -210,7 +210,7 @@ export default async function HseDashboardPage({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-1">
|
<h2 className="text-sm font-semibold text-gray-900 mb-1">
|
||||||
Leading vs Lagging — Last 30 Days
|
Leading vs Lagging — Last 30 Days
|
||||||
</h2>
|
</h2>
|
||||||
@@ -218,18 +218,18 @@ export default async function HseDashboardPage({
|
|||||||
Leading: hazard + near-miss reports (predict risk) · Lagging: injuries (past harm)
|
Leading: hazard + near-miss reports (predict risk) · Lagging: injuries (past harm)
|
||||||
</p>
|
</p>
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<div className="flex-1 text-center bg-blue-50 rounded-lg p-4">
|
<div className="flex-1 text-center bg-neutral-100 p-4">
|
||||||
<p className="text-3xl font-bold text-blue-600">{leadingCount}</p>
|
<p className="text-3xl font-bold text-accent-700">{leadingCount}</p>
|
||||||
<p className="text-xs text-blue-700 mt-1">Leading (Hazards + Near Misses)</p>
|
<p className="text-xs text-accent-700 mt-1">Leading (Hazards + Near Misses)</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 text-center bg-red-50 rounded-lg p-4">
|
<div className="flex-1 text-center bg-red-50 p-4">
|
||||||
<p className="text-3xl font-bold text-red-600">{laggingCount}</p>
|
<p className="text-3xl font-bold text-red-600">{laggingCount}</p>
|
||||||
<p className="text-xs text-red-700 mt-1">Lagging (Injuries)</p>
|
<p className="text-xs text-red-700 mt-1">Lagging (Injuries)</p>
|
||||||
</div>
|
</div>
|
||||||
{capaOnTimeRate !== null && (
|
{capaOnTimeRate !== null && (
|
||||||
<div className="flex-1 text-center bg-green-50 rounded-lg p-4">
|
<div className="flex-1 text-center bg-neutral-100 p-4">
|
||||||
<p className="text-3xl font-bold text-green-600">{capaOnTimeRate}%</p>
|
<p className="text-3xl font-bold text-ink">{capaOnTimeRate}%</p>
|
||||||
<p className="text-xs text-green-700 mt-1">CAPA On-Time Rate</p>
|
<p className="text-xs text-ink mt-1">CAPA On-Time Rate</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -240,7 +240,7 @@ export default async function HseDashboardPage({
|
|||||||
{/* Trends tab */}
|
{/* Trends tab */}
|
||||||
{tab === 'trends' && (
|
{tab === 'trends' && (
|
||||||
<>
|
<>
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-1">
|
<h2 className="text-sm font-semibold text-gray-900 mb-1">
|
||||||
Incident Trend — Last 12 Months
|
Incident Trend — Last 12 Months
|
||||||
</h2>
|
</h2>
|
||||||
@@ -253,7 +253,7 @@ export default async function HseDashboardPage({
|
|||||||
return (
|
return (
|
||||||
<div key={m.month} className="flex-1 flex flex-col items-center gap-1">
|
<div key={m.month} className="flex-1 flex flex-col items-center gap-1">
|
||||||
<div className="w-full flex flex-col-reverse" style={{ height: '192px' }}>
|
<div className="w-full flex flex-col-reverse" style={{ height: '192px' }}>
|
||||||
<div className="w-full bg-blue-400" style={{ height: `${(m.leading / monthlyMax) * 192}px` }} />
|
<div className="w-full bg-accent-400" style={{ height: `${(m.leading / monthlyMax) * 192}px` }} />
|
||||||
<div className="w-full bg-red-400" style={{ height: `${(m.lagging / monthlyMax) * 192}px` }} />
|
<div className="w-full bg-red-400" style={{ height: `${(m.lagging / monthlyMax) * 192}px` }} />
|
||||||
<div className="w-full bg-gray-300" style={{ height: `${(Math.max(0, other) / monthlyMax) * 192}px` }} />
|
<div className="w-full bg-gray-300" style={{ height: `${(Math.max(0, other) / monthlyMax) * 192}px` }} />
|
||||||
</div>
|
</div>
|
||||||
@@ -266,7 +266,7 @@ export default async function HseDashboardPage({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{rootCauses.length > 0 && (
|
{rootCauses.length > 0 && (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-4">Top Root Causes</h2>
|
<h2 className="text-sm font-semibold text-gray-900 mb-4">Top Root Causes</h2>
|
||||||
<ol className="space-y-2">
|
<ol className="space-y-2">
|
||||||
{rootCauses.map((rc, i) => (
|
{rootCauses.map((rc, i) => (
|
||||||
@@ -288,7 +288,7 @@ export default async function HseDashboardPage({
|
|||||||
{tab === 'zones' && (
|
{tab === 'zones' && (
|
||||||
<>
|
<>
|
||||||
{by_zone.length > 0 && (
|
{by_zone.length > 0 && (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-4">
|
<h2 className="text-sm font-semibold text-gray-900 mb-4">
|
||||||
Zone Incident Heatmap — Last 90 Days
|
Zone Incident Heatmap — Last 90 Days
|
||||||
</h2>
|
</h2>
|
||||||
@@ -296,9 +296,9 @@ export default async function HseDashboardPage({
|
|||||||
{by_zone.map(({ name, count }) => (
|
{by_zone.map(({ name, count }) => (
|
||||||
<div key={name} className="flex items-center gap-3">
|
<div key={name} className="flex items-center gap-3">
|
||||||
<span className="text-sm text-gray-600 w-36 shrink-0 truncate">{name}</span>
|
<span className="text-sm text-gray-600 w-36 shrink-0 truncate">{name}</span>
|
||||||
<div className="flex-1 bg-gray-100 rounded-full h-3">
|
<div className="flex-1 bg-gray-100 h-3">
|
||||||
<div
|
<div
|
||||||
className="h-3 rounded-full"
|
className="h-3"
|
||||||
style={{
|
style={{
|
||||||
width: `${(count / zoneMax) * 100}%`,
|
width: `${(count / zoneMax) * 100}%`,
|
||||||
backgroundColor: `hsl(220, 70%, ${Math.max(30, 80 - Math.round((count / zoneMax) * 50))}%)`,
|
backgroundColor: `hsl(220, 70%, ${Math.max(30, 80 - Math.round((count / zoneMax) * 50))}%)`,
|
||||||
@@ -312,15 +312,15 @@ export default async function HseDashboardPage({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-4">By Incident Type</h2>
|
<h2 className="text-sm font-semibold text-gray-900 mb-4">By Incident Type</h2>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{Object.entries(by_type).sort((a, b) => b[1] - a[1]).map(([type, count]) => (
|
{Object.entries(by_type).sort((a, b) => b[1] - a[1]).map(([type, count]) => (
|
||||||
<div key={type} className="flex items-center gap-3">
|
<div key={type} className="flex items-center gap-3">
|
||||||
<span className="text-sm text-gray-600 w-32 shrink-0">{TYPE_LABELS[type] ?? type}</span>
|
<span className="text-sm text-gray-600 w-32 shrink-0">{TYPE_LABELS[type] ?? type}</span>
|
||||||
<div className="flex-1 bg-gray-100 rounded-full h-2">
|
<div className="flex-1 bg-gray-100 h-2">
|
||||||
<div
|
<div
|
||||||
className="bg-blue-500 h-2 rounded-full"
|
className="bg-accent h-2"
|
||||||
style={{ width: total > 0 ? `${(count / total) * 100}%` : '0%' }}
|
style={{ width: total > 0 ? `${(count / total) * 100}%` : '0%' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -333,7 +333,7 @@ export default async function HseDashboardPage({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-4">By Site</h2>
|
<h2 className="text-sm font-semibold text-gray-900 mb-4">By Site</h2>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{by_site.map(({ name, count }) => (
|
{by_site.map(({ name, count }) => (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { notFound, redirect } from 'next/navigation'
|
import { notFound, redirect } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { ArrowLeft } from 'lucide-react'
|
||||||
import { asAdmin } from '@/lib/db/with-user'
|
import { asAdmin } from '@/lib/db/with-user'
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { incidents } from '@/lib/db/schema'
|
import { incidents } from '@/lib/db/schema'
|
||||||
@@ -30,15 +31,18 @@ export default async function NewCapaPage({ params }: Props) {
|
|||||||
if (!incident) notFound()
|
if (!incident) notFound()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-lg mx-auto px-4 py-6">
|
<div className="max-w-xl space-y-4 px-4 py-5 md:px-8 md:py-6">
|
||||||
<Link href={`/hse/incidents/${id}`} className="text-sm text-blue-600 hover:underline mb-4 inline-block">
|
<Link href={`/hse/incidents/${id}`} className="inline-flex items-center gap-1 text-[13px] text-accent hover:underline">
|
||||||
← Back to incident
|
<ArrowLeft size={14} strokeWidth={2} aria-hidden />
|
||||||
|
Back to incident
|
||||||
</Link>
|
</Link>
|
||||||
<h1 className="text-xl font-bold text-gray-900 mb-1">Add CAPA Action</h1>
|
<div>
|
||||||
<p className="text-sm text-gray-500 mb-6">
|
<h1 className="text-xl font-[650]">Add CAPA action</h1>
|
||||||
{incident.referenceNo ?? id}
|
<p className="mt-0.5 font-mono text-[12.5px] text-muted">{incident.referenceNo ?? id}</p>
|
||||||
</p>
|
</div>
|
||||||
|
<div className="rounded-xl bg-surface p-5 shadow-card">
|
||||||
<CapaForm incidentId={id} />
|
<CapaForm incidentId={id} />
|
||||||
</main>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default async function InvestigationPage({ params }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-2xl mx-auto px-4 py-6">
|
<main className="max-w-2xl mx-auto px-4 py-6">
|
||||||
<Link href={`/hse/incidents/${id}`} className="text-sm text-blue-600 hover:underline mb-4 inline-block">
|
<Link href={`/hse/incidents/${id}`} className="text-sm text-accent-700 hover:underline mb-4 inline-block">
|
||||||
← Back to incident
|
← Back to incident
|
||||||
</Link>
|
</Link>
|
||||||
<h1 className="text-xl font-bold text-gray-900 mb-1">Investigation Workspace</h1>
|
<h1 className="text-xl font-bold text-gray-900 mb-1">Investigation Workspace</h1>
|
||||||
|
|||||||
@@ -175,14 +175,14 @@ export default async function HseIncidentDetailPage({ params }: Props) {
|
|||||||
<a
|
<a
|
||||||
href={`/api/incidents/${id}/jkkp-pdf?form=jkkp6`}
|
href={`/api/incidents/${id}/jkkp-pdf?form=jkkp6`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
className="inline-block bg-gray-800 text-white rounded-lg px-4 py-2 text-sm font-semibold hover:bg-gray-900"
|
className="inline-block bg-gray-800 text-white px-4 py-2 text-sm font-semibold hover:bg-gray-900"
|
||||||
>
|
>
|
||||||
Download JKKP 6 (PDF)
|
Download JKKP 6 (PDF)
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href={`/api/incidents/${id}/jkkp-pdf?form=jkkp7`}
|
href={`/api/incidents/${id}/jkkp-pdf?form=jkkp7`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
className="inline-block bg-gray-600 text-white rounded-lg px-4 py-2 text-sm font-semibold hover:bg-gray-700"
|
className="inline-block bg-gray-600 text-white px-4 py-2 text-sm font-semibold hover:bg-gray-700"
|
||||||
>
|
>
|
||||||
Download JKKP 7 (PDF)
|
Download JKKP 7 (PDF)
|
||||||
</a>
|
</a>
|
||||||
@@ -194,7 +194,7 @@ export default async function HseIncidentDetailPage({ params }: Props) {
|
|||||||
href={`/api/incidents/${id}/report-pdf`}
|
href={`/api/incidents/${id}/report-pdf`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-green-600 text-white text-xs font-semibold rounded-lg hover:bg-green-700 transition-colors"
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-accent text-white text-xs font-semibold hover:bg-accent-600 transition-colors"
|
||||||
>
|
>
|
||||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export default async function TriagePage({ params }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-lg mx-auto px-4 py-6">
|
<main className="max-w-lg mx-auto px-4 py-6">
|
||||||
<Link href={`/hse/incidents/${id}`} className="text-sm text-blue-600 hover:underline mb-4 inline-block">
|
<Link href={`/hse/incidents/${id}`} className="text-sm text-accent-700 hover:underline mb-4 inline-block">
|
||||||
← Back to incident
|
← Back to incident
|
||||||
</Link>
|
</Link>
|
||||||
<h1 className="text-xl font-bold text-gray-900 mb-1">Triage Incident</h1>
|
<h1 className="text-xl font-bold text-gray-900 mb-1">Triage Incident</h1>
|
||||||
|
|||||||
@@ -1,106 +1,39 @@
|
|||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
|
import Link from 'next/link'
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from 'next/navigation'
|
||||||
import { asAdmin } from '@/lib/db/with-user'
|
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { incidents, sites, zones, trucks, users } from '@/lib/db/schema'
|
import { buttonClass } from '@/components/ui/button'
|
||||||
import { eq, and, or, ilike, desc, asc, sql } from 'drizzle-orm'
|
import { IncidentTable } from '@/components/incidents/incident-table'
|
||||||
import { aliasedTable } from 'drizzle-orm'
|
import { loadIncidentList } from '@/lib/incidents/list-query'
|
||||||
import { IncidentList, type Incident } from '@/components/incidents/incident-list'
|
import { parseListParams } from '@/lib/incidents/list-params'
|
||||||
import { Pagination } from '@/components/incidents/pagination'
|
|
||||||
import { IncidentFilters, type SiteOption, type TruckOption } from '@/components/incidents/incident-filters'
|
|
||||||
|
|
||||||
const PAGE_SIZE = 25
|
|
||||||
|
|
||||||
export default async function HseInboxPage({
|
export default async function HseInboxPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{ page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string }>
|
searchParams: Promise<Record<string, string | undefined>>
|
||||||
}) {
|
}) {
|
||||||
const session = await getSession()
|
const session = await getSession()
|
||||||
if (!session) redirect('/login')
|
if (!session) redirect('/login')
|
||||||
|
|
||||||
const params = await searchParams
|
const params = parseListParams(await searchParams)
|
||||||
const page = Math.max(1, Number.parseInt(params.page ?? '1', 10) || 1)
|
const data = await loadIncidentList(params)
|
||||||
const from = (page - 1) * PAGE_SIZE
|
|
||||||
|
|
||||||
const reporterAlias = aliasedTable(users, 'reporter')
|
|
||||||
|
|
||||||
const conditions = []
|
|
||||||
if (params.q) conditions.push(or(ilike(incidents.referenceNo, `%${params.q}%`), ilike(incidents.description, `%${params.q}%`)))
|
|
||||||
if (params.status) conditions.push(eq(incidents.status, params.status as never))
|
|
||||||
if (params.type) conditions.push(eq(incidents.incidentType, params.type as never))
|
|
||||||
if (params.site_id) conditions.push(eq(incidents.siteId, params.site_id))
|
|
||||||
if (params.truck_id) conditions.push(eq(incidents.truckId, params.truck_id))
|
|
||||||
const where = conditions.length ? and(...conditions) : undefined
|
|
||||||
|
|
||||||
const [[countRow], incidentRows, siteRows, truckRows] = await Promise.all([
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ count: sql<number>`count(*)` })
|
|
||||||
.from(incidents)
|
|
||||||
.where(where)
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({
|
|
||||||
id: incidents.id,
|
|
||||||
referenceNo: incidents.referenceNo,
|
|
||||||
incidentType: incidents.incidentType,
|
|
||||||
status: incidents.status,
|
|
||||||
severity: incidents.severity,
|
|
||||||
reportedAt: incidents.reportedAt,
|
|
||||||
siteName: sites.name,
|
|
||||||
zoneName: zones.name,
|
|
||||||
reporterName: reporterAlias.name,
|
|
||||||
truckNo: trucks.truckNo,
|
|
||||||
})
|
|
||||||
.from(incidents)
|
|
||||||
.leftJoin(sites, eq(incidents.siteId, sites.id))
|
|
||||||
.leftJoin(zones, eq(incidents.zoneId, zones.id))
|
|
||||||
.leftJoin(reporterAlias, eq(incidents.reportedBy, reporterAlias.id))
|
|
||||||
.leftJoin(trucks, eq(incidents.truckId, trucks.id))
|
|
||||||
.where(where)
|
|
||||||
.orderBy(desc(incidents.reportedAt))
|
|
||||||
.limit(PAGE_SIZE)
|
|
||||||
.offset(from)
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ id: sites.id, name: sites.name }).from(sites).orderBy(asc(sites.name))
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ id: trucks.id, truckNo: trucks.truckNo })
|
|
||||||
.from(trucks)
|
|
||||||
.where(eq(trucks.active, true))
|
|
||||||
.orderBy(asc(trucks.truckNo))
|
|
||||||
),
|
|
||||||
])
|
|
||||||
|
|
||||||
const total = Number(countRow?.count ?? 0)
|
|
||||||
|
|
||||||
const incidentList: Incident[] = incidentRows.map(r => ({
|
|
||||||
id: r.id,
|
|
||||||
reference_no: r.referenceNo,
|
|
||||||
incident_type: r.incidentType,
|
|
||||||
status: r.status,
|
|
||||||
severity: r.severity,
|
|
||||||
reported_at: r.reportedAt.toISOString(),
|
|
||||||
sites: r.siteName ? { name: r.siteName } : null,
|
|
||||||
zones: r.zoneName ? { name: r.zoneName } : null,
|
|
||||||
trucks: r.truckNo ? { truck_no: r.truckNo } : null,
|
|
||||||
reporter: r.reporterName ? { name: r.reporterName } : null,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const siteOptions: SiteOption[] = siteRows.map(s => ({ id: s.id, name: s.name }))
|
|
||||||
const truckOptions: TruckOption[] = truckRows.map(t => ({ id: t.id, truck_no: t.truckNo }))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-4xl mx-auto px-4 py-6">
|
<div className="px-4 py-5 md:px-8 md:py-6 space-y-4">
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between">
|
||||||
<h1 className="text-2xl font-bold text-gray-900">Incident Inbox</h1>
|
<h1 className="text-[22px] md:text-xl font-[650]">Incidents</h1>
|
||||||
<span className="text-sm text-gray-500">{total} incidents</span>
|
<Link href="/report" className={buttonClass('primary')}>Report incident</Link>
|
||||||
|
</div>
|
||||||
|
<IncidentTable
|
||||||
|
incidents={data.incidents}
|
||||||
|
basePath="/hse"
|
||||||
|
total={data.total}
|
||||||
|
counts={data.counts}
|
||||||
|
params={params}
|
||||||
|
sites={data.sites}
|
||||||
|
trucks={data.trucks}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<IncidentFilters sites={siteOptions} trucks={truckOptions} />
|
|
||||||
<IncidentList incidents={incidentList} basePath="/hse" />
|
|
||||||
<Pagination page={page} pageSize={PAGE_SIZE} total={total} href="/hse/incidents" />
|
|
||||||
</main>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ export default async function HsePage() {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900 mb-1">HSE Officer Portal</h1>
|
<h1 className="text-2xl font-bold text-gray-900 mb-1">HSE Officer Portal</h1>
|
||||||
<p className="text-gray-500 text-sm mb-8">Welcome, {session.name}</p>
|
<p className="text-gray-500 text-sm mb-8">Welcome, {session.name}</p>
|
||||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3">
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3">
|
||||||
<Link href="/hse/incidents" className="bg-white rounded-xl shadow-sm p-5 hover:shadow-md transition-shadow border border-gray-100">
|
<Link href="/hse/incidents" className="bg-surface shadow-sm p-5 hover:shadow-md transition-shadow border border-divider">
|
||||||
<div className="text-2xl mb-2">📋</div>
|
<div className="text-2xl mb-2">📋</div>
|
||||||
<div className="font-semibold text-gray-900">Incident Inbox</div>
|
<div className="font-semibold text-gray-900">Incident Inbox</div>
|
||||||
<div className="text-xs text-gray-500 mt-1">View all incidents</div>
|
<div className="text-xs text-gray-500 mt-1">View all incidents</div>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/hse/dashboard" className="bg-white rounded-xl shadow-sm p-5 hover:shadow-md transition-shadow border border-gray-100">
|
<Link href="/hse/dashboard" className="bg-surface shadow-sm p-5 hover:shadow-md transition-shadow border border-divider">
|
||||||
<div className="text-2xl mb-2">📊</div>
|
<div className="text-2xl mb-2">📊</div>
|
||||||
<div className="font-semibold text-gray-900">Dashboard</div>
|
<div className="font-semibold text-gray-900">Dashboard</div>
|
||||||
<div className="text-xs text-gray-500 mt-1">Stats & overview</div>
|
<div className="text-xs text-gray-500 mt-1">Stats & overview</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ export const dynamic = 'force-dynamic'
|
|||||||
|
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from 'next/navigation'
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { Sidebar } from '@/components/layout/sidebar'
|
import { AppShell } from '@/components/layout/app-shell'
|
||||||
|
|
||||||
export default async function ProtectedLayout({
|
export default async function ProtectedLayout({
|
||||||
children,
|
children,
|
||||||
@@ -13,15 +13,8 @@ export default async function ProtectedLayout({
|
|||||||
if (!session) redirect('/login')
|
if (!session) redirect('/login')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<AppShell role={session.role} userName={session.name}>
|
||||||
<Sidebar
|
|
||||||
role={session.role}
|
|
||||||
userName={session.name}
|
|
||||||
userEmail=""
|
|
||||||
/>
|
|
||||||
<div className="sm:ml-60 pb-16 sm:pb-0">
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</AppShell>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export default async function ManagementPage() {
|
|||||||
|
|
||||||
const SEVERITY_LABELS: Record<number, string> = { 1: 'Minor', 2: 'Low', 3: 'Moderate', 4: 'Serious', 5: 'Critical' }
|
const SEVERITY_LABELS: Record<number, string> = { 1: 'Minor', 2: 'Low', 3: 'Moderate', 4: 'Serious', 5: 'Critical' }
|
||||||
const SEVERITY_COLORS: Record<number, string> = {
|
const SEVERITY_COLORS: Record<number, string> = {
|
||||||
1: 'bg-green-400', 2: 'bg-yellow-400', 3: 'bg-orange-400', 4: 'bg-red-500', 5: 'bg-red-700',
|
1: 'bg-neutral-300', 2: 'bg-neutral-500', 3: 'bg-accent-300', 4: 'bg-accent', 5: 'bg-accent-700',
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -97,7 +97,7 @@ export default async function ManagementPage() {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900">Management Dashboard</h1>
|
<h1 className="text-2xl font-bold text-gray-900">Management Dashboard</h1>
|
||||||
<a
|
<a
|
||||||
href="/api/dashboard/export?role=management"
|
href="/api/dashboard/export?role=management"
|
||||||
className="text-sm text-gray-500 hover:text-gray-700 border border-gray-200 rounded-lg px-3 py-1.5"
|
className="text-sm text-gray-500 hover:text-gray-700 border border-divider px-3 py-1.5"
|
||||||
>
|
>
|
||||||
Export CSV
|
Export CSV
|
||||||
</a>
|
</a>
|
||||||
@@ -119,15 +119,15 @@ export default async function ManagementPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Leading vs lagging */}
|
{/* Leading vs lagging */}
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-1">Leading vs Lagging — Last 30 Days</h2>
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-1">Leading vs Lagging — Last 30 Days</h2>
|
||||||
<p className="text-xs text-gray-400 mb-4">Leading: hazard + near-miss · Lagging: injuries</p>
|
<p className="text-xs text-gray-400 mb-4">Leading: hazard + near-miss · Lagging: injuries</p>
|
||||||
<div className="flex gap-6">
|
<div className="flex gap-6">
|
||||||
<div className="flex-1 text-center bg-blue-50 rounded-lg p-4">
|
<div className="flex-1 text-center bg-neutral-100 p-4">
|
||||||
<p className="text-3xl font-bold text-blue-600">{leadingCount}</p>
|
<p className="text-3xl font-bold text-accent-700">{leadingCount}</p>
|
||||||
<p className="text-xs text-blue-700 mt-1">Leading (Hazards + Near Misses)</p>
|
<p className="text-xs text-accent-700 mt-1">Leading (Hazards + Near Misses)</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 text-center bg-red-50 rounded-lg p-4">
|
<div className="flex-1 text-center bg-red-50 p-4">
|
||||||
<p className="text-3xl font-bold text-red-600">{laggingCount}</p>
|
<p className="text-3xl font-bold text-red-600">{laggingCount}</p>
|
||||||
<p className="text-xs text-red-700 mt-1">Lagging (Injuries)</p>
|
<p className="text-xs text-red-700 mt-1">Lagging (Injuries)</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -135,15 +135,15 @@ export default async function ManagementPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Severity distribution */}
|
{/* Severity distribution */}
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Severity Distribution (All Time)</h2>
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Severity Distribution (All Time)</h2>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{([5, 4, 3, 2, 1] as const).map(sev => (
|
{([5, 4, 3, 2, 1] as const).map(sev => (
|
||||||
<div key={sev} className="flex items-center gap-3">
|
<div key={sev} className="flex items-center gap-3">
|
||||||
<span className="text-sm text-gray-600 w-24 shrink-0">{SEVERITY_LABELS[sev]}</span>
|
<span className="text-sm text-gray-600 w-24 shrink-0">{SEVERITY_LABELS[sev]}</span>
|
||||||
<div className="flex-1 bg-gray-100 rounded-full h-3">
|
<div className="flex-1 bg-gray-100 h-3">
|
||||||
<div
|
<div
|
||||||
className={`h-3 rounded-full ${SEVERITY_COLORS[sev]}`}
|
className={`h-3 ${SEVERITY_COLORS[sev]}`}
|
||||||
style={{ width: severityMax > 0 ? `${(severityDist[sev] / severityMax) * 100}%` : '0%' }}
|
style={{ width: severityMax > 0 ? `${(severityDist[sev] / severityMax) * 100}%` : '0%' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -154,7 +154,7 @@ export default async function ManagementPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Site comparison */}
|
{/* Site comparison */}
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Incidents by Site</h2>
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Incidents by Site</h2>
|
||||||
{by_site.length === 0 ? (
|
{by_site.length === 0 ? (
|
||||||
<p className="text-sm text-gray-400">No data</p>
|
<p className="text-sm text-gray-400">No data</p>
|
||||||
|
|||||||
@@ -6,17 +6,12 @@ import { redirect, notFound } from 'next/navigation'
|
|||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { incidents, sites, zones, capaActions } from '@/lib/db/schema'
|
import { incidents, sites, zones, capaActions } from '@/lib/db/schema'
|
||||||
import { eq, and } from 'drizzle-orm'
|
import { eq, and } from 'drizzle-orm'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
reported: 'Reported', triaged: 'Triaged', investigating: 'Investigating',
|
reported: 'Reported', triaged: 'Triaged', investigating: 'Investigating',
|
||||||
capa_pending: 'CAPA Pending', verification: 'Verification', closed: 'Closed',
|
capa_pending: 'CAPA Pending', verification: 'Verification', closed: 'Closed',
|
||||||
}
|
}
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-gray-100 text-gray-600', triaged: 'bg-yellow-100 text-yellow-800',
|
|
||||||
investigating: 'bg-blue-100 text-blue-700', capa_pending: 'bg-orange-100 text-orange-700',
|
|
||||||
verification: 'bg-purple-100 text-purple-700', closed: 'bg-green-100 text-green-700',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function ReporterIncidentDetail({
|
export default async function ReporterIncidentDetail({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
@@ -65,18 +60,16 @@ export default async function ReporterIncidentDetail({
|
|||||||
return (
|
return (
|
||||||
<main className="max-w-2xl mx-auto px-4 py-6 space-y-4">
|
<main className="max-w-2xl mx-auto px-4 py-6 space-y-4">
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<Link href="/reporter" className="text-sm text-blue-600 hover:underline">← My Reports</Link>
|
<Link href="/reporter" className="text-sm text-accent-700 hover:underline">← My Reports</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<div className="flex items-start justify-between gap-3 mb-4">
|
<div className="flex items-start justify-between gap-3 mb-4">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-lg font-bold text-gray-900">{inc.referenceNo ?? inc.id.slice(0, 8)}</h1>
|
<h1 className="text-lg font-bold text-gray-900">{inc.referenceNo ?? inc.id.slice(0, 8)}</h1>
|
||||||
<p className="text-sm text-gray-500 capitalize">{inc.incidentType?.replace(/_/g, ' ')}</p>
|
<p className="text-sm text-gray-500 capitalize">{inc.incidentType?.replace(/_/g, ' ')}</p>
|
||||||
</div>
|
</div>
|
||||||
<span className={`text-xs rounded-full px-2 py-1 shrink-0 ${STATUS_COLORS[inc.status] ?? 'bg-gray-100 text-gray-600'}`}>
|
<span className="shrink-0"><StatusTag status={inc.status}>{STATUS_LABELS[inc.status] ?? inc.status}</StatusTag></span>
|
||||||
{STATUS_LABELS[inc.status] ?? inc.status}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-3 text-sm mb-4">
|
<div className="grid grid-cols-2 gap-3 text-sm mb-4">
|
||||||
@@ -98,7 +91,7 @@ export default async function ReporterIncidentDetail({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{inc.description && (
|
{inc.description && (
|
||||||
<div className="border-t border-gray-100 pt-4">
|
<div className="border-t border-divider pt-4">
|
||||||
<p className="text-xs text-gray-500 mb-1">Description</p>
|
<p className="text-xs text-gray-500 mb-1">Description</p>
|
||||||
<p className="text-sm text-gray-800 whitespace-pre-line">{inc.description}</p>
|
<p className="text-sm text-gray-800 whitespace-pre-line">{inc.description}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,16 +99,16 @@ export default async function ReporterIncidentDetail({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{capas.length > 0 && (
|
{capas.length > 0 && (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-3">Corrective Actions ({capas.length})</h2>
|
<h2 className="text-sm font-semibold text-gray-900 mb-3">Corrective Actions ({capas.length})</h2>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{capas.map(c => (
|
{capas.map(c => (
|
||||||
<div key={c.id} className="flex items-start justify-between gap-3 text-sm">
|
<div key={c.id} className="flex items-start justify-between gap-3 text-sm">
|
||||||
<p className="text-gray-700 flex-1">{c.description}</p>
|
<p className="text-gray-700 flex-1">{c.description}</p>
|
||||||
<span className={`text-xs rounded-full px-2 py-0.5 shrink-0 ${
|
<span className={`text-xs px-2 py-0.5 shrink-0 ${
|
||||||
c.status === 'verified' ? 'bg-green-100 text-green-700' :
|
c.status === 'verified' ? 'bg-st-green-bg text-st-green-fg' :
|
||||||
c.status === 'pending_verification' ? 'bg-purple-100 text-purple-700' :
|
c.status === 'pending_verification' ? 'bg-st-indigo-bg text-st-indigo-fg' :
|
||||||
'bg-gray-100 text-gray-600'
|
'bg-st-grey-bg text-st-grey-fg'
|
||||||
}`}>{c.status.replace(/_/g, ' ')}</span>
|
}`}>{c.status.replace(/_/g, ' ')}</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { redirect } from 'next/navigation'
|
|||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { incidents, sites } from '@/lib/db/schema'
|
import { incidents, sites } from '@/lib/db/schema'
|
||||||
import { eq, desc } from 'drizzle-orm'
|
import { eq, desc } from 'drizzle-orm'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
reported: 'Reported',
|
reported: 'Reported',
|
||||||
@@ -16,15 +17,6 @@ const STATUS_LABELS: Record<string, string> = {
|
|||||||
closed: 'Closed',
|
closed: 'Closed',
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-gray-100 text-gray-600',
|
|
||||||
triaged: 'bg-yellow-100 text-yellow-800',
|
|
||||||
investigating: 'bg-blue-100 text-blue-700',
|
|
||||||
capa_pending: 'bg-orange-100 text-orange-700',
|
|
||||||
verification: 'bg-purple-100 text-purple-700',
|
|
||||||
closed: 'bg-green-100 text-green-700',
|
|
||||||
}
|
|
||||||
|
|
||||||
const TYPE_LABELS: Record<string, string> = {
|
const TYPE_LABELS: Record<string, string> = {
|
||||||
injury: 'Injury', near_miss: 'Near Miss', hazard: 'Hazard',
|
injury: 'Injury', near_miss: 'Near Miss', hazard: 'Hazard',
|
||||||
asset_damage: 'Asset Damage', environmental: 'Environmental', security: 'Security', fire: 'Fire',
|
asset_damage: 'Asset Damage', environmental: 'Environmental', security: 'Security', fire: 'Fire',
|
||||||
@@ -62,34 +54,34 @@ export default async function ReporterPage() {
|
|||||||
</div>
|
</div>
|
||||||
<Link
|
<Link
|
||||||
href="/report"
|
href="/report"
|
||||||
className="bg-blue-600 text-white rounded-lg px-4 py-2 text-sm font-semibold hover:bg-blue-700"
|
className="bg-accent text-white px-4 py-2 text-sm font-semibold hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
+ New Report
|
+ New Report
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-4 mb-6 text-sm">
|
<div className="flex gap-4 mb-6 text-sm">
|
||||||
<div className="bg-white rounded-xl shadow-sm p-4 flex-1 text-center">
|
<div className="bg-surface shadow-sm p-4 flex-1 text-center">
|
||||||
<p className="text-2xl font-bold text-gray-900">{rows.length}</p>
|
<p className="text-2xl font-bold text-gray-900">{rows.length}</p>
|
||||||
<p className="text-xs text-gray-500 mt-1">Total Submitted</p>
|
<p className="text-xs text-gray-500 mt-1">Total Submitted</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white rounded-xl shadow-sm p-4 flex-1 text-center">
|
<div className="bg-surface shadow-sm p-4 flex-1 text-center">
|
||||||
<p className="text-2xl font-bold text-yellow-600">{openCount}</p>
|
<p className="text-2xl font-bold text-accent-700">{openCount}</p>
|
||||||
<p className="text-xs text-gray-500 mt-1">In Progress</p>
|
<p className="text-xs text-gray-500 mt-1">In Progress</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-white rounded-xl shadow-sm p-4 flex-1 text-center">
|
<div className="bg-surface shadow-sm p-4 flex-1 text-center">
|
||||||
<p className="text-2xl font-bold text-green-600">{closedCount}</p>
|
<p className="text-2xl font-bold text-ink">{closedCount}</p>
|
||||||
<p className="text-xs text-gray-500 mt-1">Closed</p>
|
<p className="text-xs text-gray-500 mt-1">Closed</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{rows.length === 0 ? (
|
{rows.length === 0 ? (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-8 text-center">
|
<div className="bg-surface shadow-sm p-8 text-center">
|
||||||
<p className="text-gray-400 text-sm mb-4">No incidents reported yet.</p>
|
<p className="text-gray-400 text-sm mb-4">No incidents reported yet.</p>
|
||||||
<Link href="/report" className="text-blue-600 text-sm hover:underline">Submit your first report →</Link>
|
<Link href="/report" className="text-accent-700 text-sm hover:underline">Submit your first report →</Link>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-white rounded-xl shadow-sm divide-y divide-gray-50">
|
<div className="bg-surface shadow-sm divide-y divide-gray-50">
|
||||||
{rows.map(inc => (
|
{rows.map(inc => (
|
||||||
<Link key={inc.id} href={`/reporter/incidents/${inc.id}`} className="block p-4 cursor-pointer hover:bg-gray-50 transition-colors">
|
<Link key={inc.id} href={`/reporter/incidents/${inc.id}`} className="block p-4 cursor-pointer hover:bg-gray-50 transition-colors">
|
||||||
<div className="flex items-start justify-between gap-3">
|
<div className="flex items-start justify-between gap-3">
|
||||||
@@ -110,9 +102,7 @@ export default async function ReporterPage() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<span className={`text-xs rounded-full px-2 py-0.5 shrink-0 ${STATUS_COLORS[inc.status] ?? 'bg-gray-100 text-gray-600'}`}>
|
<span className="shrink-0"><StatusTag status={inc.status}>{STATUS_LABELS[inc.status] ?? inc.status}</StatusTag></span>
|
||||||
{STATUS_LABELS[inc.status] ?? inc.status}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export default async function SupervisorIncidentDetailPage({ params }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-3xl mx-auto px-4 py-6">
|
<main className="max-w-3xl mx-auto px-4 py-6">
|
||||||
<Link href="/supervisor/incidents" className="text-sm text-blue-600 hover:underline mb-4 inline-block">
|
<Link href="/supervisor/incidents" className="text-sm text-accent-700 hover:underline mb-4 inline-block">
|
||||||
← Back to inbox
|
← Back to inbox
|
||||||
</Link>
|
</Link>
|
||||||
<IncidentDetail incident={incidentProp} />
|
<IncidentDetail incident={incidentProp} />
|
||||||
|
|||||||
@@ -1,106 +1,39 @@
|
|||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
|
import Link from 'next/link'
|
||||||
import { redirect } from 'next/navigation'
|
import { redirect } from 'next/navigation'
|
||||||
import { asAdmin } from '@/lib/db/with-user'
|
|
||||||
import { getSession } from '@/lib/auth/get-session'
|
import { getSession } from '@/lib/auth/get-session'
|
||||||
import { incidents, sites, zones, trucks, users } from '@/lib/db/schema'
|
import { buttonClass } from '@/components/ui/button'
|
||||||
import { eq, and, or, ilike, desc, asc, sql } from 'drizzle-orm'
|
import { IncidentTable } from '@/components/incidents/incident-table'
|
||||||
import { aliasedTable } from 'drizzle-orm'
|
import { loadIncidentList } from '@/lib/incidents/list-query'
|
||||||
import { IncidentList, type Incident } from '@/components/incidents/incident-list'
|
import { parseListParams } from '@/lib/incidents/list-params'
|
||||||
import { Pagination } from '@/components/incidents/pagination'
|
|
||||||
import { IncidentFilters, type SiteOption, type TruckOption } from '@/components/incidents/incident-filters'
|
|
||||||
|
|
||||||
const PAGE_SIZE = 25
|
|
||||||
|
|
||||||
export default async function SupervisorInboxPage({
|
export default async function SupervisorInboxPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{ page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string }>
|
searchParams: Promise<Record<string, string | undefined>>
|
||||||
}) {
|
}) {
|
||||||
const session = await getSession()
|
const session = await getSession()
|
||||||
if (!session) redirect('/login')
|
if (!session) redirect('/login')
|
||||||
|
|
||||||
const params = await searchParams
|
const params = parseListParams(await searchParams)
|
||||||
const page = Math.max(1, Number.parseInt(params.page ?? '1', 10) || 1)
|
const data = await loadIncidentList(params)
|
||||||
const from = (page - 1) * PAGE_SIZE
|
|
||||||
|
|
||||||
const reporterAlias = aliasedTable(users, 'reporter')
|
|
||||||
|
|
||||||
const conditions = []
|
|
||||||
if (params.q) conditions.push(or(ilike(incidents.referenceNo, `%${params.q}%`), ilike(incidents.description, `%${params.q}%`)))
|
|
||||||
if (params.status) conditions.push(eq(incidents.status, params.status as never))
|
|
||||||
if (params.type) conditions.push(eq(incidents.incidentType, params.type as never))
|
|
||||||
if (params.site_id) conditions.push(eq(incidents.siteId, params.site_id))
|
|
||||||
if (params.truck_id) conditions.push(eq(incidents.truckId, params.truck_id))
|
|
||||||
const where = conditions.length ? and(...conditions) : undefined
|
|
||||||
|
|
||||||
const [[countRow], incidentRows, siteRows, truckRows] = await Promise.all([
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ count: sql<number>`count(*)` })
|
|
||||||
.from(incidents)
|
|
||||||
.where(where)
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({
|
|
||||||
id: incidents.id,
|
|
||||||
referenceNo: incidents.referenceNo,
|
|
||||||
incidentType: incidents.incidentType,
|
|
||||||
status: incidents.status,
|
|
||||||
severity: incidents.severity,
|
|
||||||
reportedAt: incidents.reportedAt,
|
|
||||||
siteName: sites.name,
|
|
||||||
zoneName: zones.name,
|
|
||||||
reporterName: reporterAlias.name,
|
|
||||||
truckNo: trucks.truckNo,
|
|
||||||
})
|
|
||||||
.from(incidents)
|
|
||||||
.leftJoin(sites, eq(incidents.siteId, sites.id))
|
|
||||||
.leftJoin(zones, eq(incidents.zoneId, zones.id))
|
|
||||||
.leftJoin(reporterAlias, eq(incidents.reportedBy, reporterAlias.id))
|
|
||||||
.leftJoin(trucks, eq(incidents.truckId, trucks.id))
|
|
||||||
.where(where)
|
|
||||||
.orderBy(desc(incidents.reportedAt))
|
|
||||||
.limit(PAGE_SIZE)
|
|
||||||
.offset(from)
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ id: sites.id, name: sites.name }).from(sites).orderBy(asc(sites.name))
|
|
||||||
),
|
|
||||||
asAdmin(db =>
|
|
||||||
db.select({ id: trucks.id, truckNo: trucks.truckNo })
|
|
||||||
.from(trucks)
|
|
||||||
.where(eq(trucks.active, true))
|
|
||||||
.orderBy(asc(trucks.truckNo))
|
|
||||||
),
|
|
||||||
])
|
|
||||||
|
|
||||||
const total = Number(countRow?.count ?? 0)
|
|
||||||
|
|
||||||
const incidentList: Incident[] = incidentRows.map(r => ({
|
|
||||||
id: r.id,
|
|
||||||
reference_no: r.referenceNo,
|
|
||||||
incident_type: r.incidentType,
|
|
||||||
status: r.status,
|
|
||||||
severity: r.severity,
|
|
||||||
reported_at: r.reportedAt.toISOString(),
|
|
||||||
sites: r.siteName ? { name: r.siteName } : null,
|
|
||||||
zones: r.zoneName ? { name: r.zoneName } : null,
|
|
||||||
trucks: r.truckNo ? { truck_no: r.truckNo } : null,
|
|
||||||
reporter: r.reporterName ? { name: r.reporterName } : null,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const siteOptions: SiteOption[] = siteRows.map(s => ({ id: s.id, name: s.name }))
|
|
||||||
const truckOptions: TruckOption[] = truckRows.map(t => ({ id: t.id, truck_no: t.truckNo }))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="max-w-4xl mx-auto px-4 py-6">
|
<div className="px-4 py-5 md:px-8 md:py-6 space-y-4">
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between">
|
||||||
<h1 className="text-2xl font-bold text-gray-900">Incident Inbox</h1>
|
<h1 className="text-[22px] md:text-xl font-[650]">Incidents</h1>
|
||||||
<span className="text-sm text-gray-500">{total} incidents</span>
|
<Link href="/report" className={buttonClass('primary')}>Report incident</Link>
|
||||||
|
</div>
|
||||||
|
<IncidentTable
|
||||||
|
incidents={data.incidents}
|
||||||
|
basePath="/supervisor"
|
||||||
|
total={data.total}
|
||||||
|
counts={data.counts}
|
||||||
|
params={params}
|
||||||
|
sites={data.sites}
|
||||||
|
trucks={data.trucks}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<IncidentFilters sites={siteOptions} trucks={truckOptions} />
|
|
||||||
<IncidentList incidents={incidentList} basePath="/supervisor" />
|
|
||||||
<Pagination page={page} pageSize={PAGE_SIZE} total={total} href="/supervisor/incidents" />
|
|
||||||
</main>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { incidents, sites, capaActions, users } from '@/lib/db/schema'
|
|||||||
import { eq, not, and, inArray, sql, desc } from 'drizzle-orm'
|
import { eq, not, and, inArray, sql, desc } from 'drizzle-orm'
|
||||||
import { aliasedTable } from 'drizzle-orm'
|
import { aliasedTable } from 'drizzle-orm'
|
||||||
import { StatCard } from '@/components/dashboard/stat-card'
|
import { StatCard } from '@/components/dashboard/stat-card'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
reported: 'Reported',
|
reported: 'Reported',
|
||||||
@@ -18,15 +19,6 @@ const STATUS_LABELS: Record<string, string> = {
|
|||||||
closed: 'Closed',
|
closed: 'Closed',
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-gray-100 text-gray-700',
|
|
||||||
triaged: 'bg-yellow-100 text-yellow-800',
|
|
||||||
investigating: 'bg-blue-100 text-blue-700',
|
|
||||||
capa_pending: 'bg-orange-100 text-orange-700',
|
|
||||||
verification: 'bg-purple-100 text-purple-700',
|
|
||||||
closed: 'bg-green-100 text-green-700',
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function SupervisorPage() {
|
export default async function SupervisorPage() {
|
||||||
const session = await getSession()
|
const session = await getSession()
|
||||||
if (!session) redirect('/login')
|
if (!session) redirect('/login')
|
||||||
@@ -119,7 +111,7 @@ export default async function SupervisorPage() {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900">Supervisor Portal</h1>
|
<h1 className="text-2xl font-bold text-gray-900">Supervisor Portal</h1>
|
||||||
<p className="text-sm text-gray-500 mt-1">{siteName}</p>
|
<p className="text-sm text-gray-500 mt-1">{siteName}</p>
|
||||||
</div>
|
</div>
|
||||||
<Link href="/supervisor/incidents" className="text-sm text-blue-600 hover:underline">
|
<Link href="/supervisor/incidents" className="text-sm text-accent-700 hover:underline">
|
||||||
All incidents →
|
All incidents →
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -133,7 +125,7 @@ export default async function SupervisorPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Open incidents */}
|
{/* Open incidents */}
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Open Incidents</h2>
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Open Incidents</h2>
|
||||||
{openIncidents.length === 0 ? (
|
{openIncidents.length === 0 ? (
|
||||||
<p className="text-sm text-gray-400">No open incidents.</p>
|
<p className="text-sm text-gray-400">No open incidents.</p>
|
||||||
@@ -143,15 +135,13 @@ export default async function SupervisorPage() {
|
|||||||
<Link
|
<Link
|
||||||
key={inc.id}
|
key={inc.id}
|
||||||
href={`/supervisor/incidents/${inc.id}`}
|
href={`/supervisor/incidents/${inc.id}`}
|
||||||
className="flex items-center justify-between py-2 border-b border-gray-50 last:border-0 hover:bg-gray-50 -mx-2 px-2 rounded"
|
className="flex items-center justify-between py-2 border-b border-gray-50 last:border-0 hover:bg-gray-50 -mx-2 px-2"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm font-medium text-gray-900">{inc.referenceNo ?? inc.id.slice(0, 8)}</p>
|
<p className="text-sm font-medium text-gray-900">{inc.referenceNo ?? inc.id.slice(0, 8)}</p>
|
||||||
<p className="text-xs text-gray-500">{TYPE_LABELS[inc.incidentType] ?? inc.incidentType}</p>
|
<p className="text-xs text-gray-500">{TYPE_LABELS[inc.incidentType] ?? inc.incidentType}</p>
|
||||||
</div>
|
</div>
|
||||||
<span className={`text-xs rounded-full px-2 py-0.5 font-medium ${STATUS_COLORS[inc.status] ?? 'bg-gray-100 text-gray-700'}`}>
|
<StatusTag status={inc.status}>{STATUS_LABELS[inc.status] ?? inc.status}</StatusTag>
|
||||||
{STATUS_LABELS[inc.status] ?? inc.status}
|
|
||||||
</span>
|
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -160,7 +150,7 @@ export default async function SupervisorPage() {
|
|||||||
|
|
||||||
{/* Overdue CAPAs */}
|
{/* Overdue CAPAs */}
|
||||||
{overdueCount > 0 && (
|
{overdueCount > 0 && (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-red-600 uppercase tracking-wide mb-4">Overdue CAPAs</h2>
|
<h2 className="text-sm font-semibold text-red-600 uppercase tracking-wide mb-4">Overdue CAPAs</h2>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{overdueCapas.map(capa => (
|
{overdueCapas.map(capa => (
|
||||||
|
|||||||
+160
-20
@@ -1,37 +1,177 @@
|
|||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
|
|
||||||
:root {
|
/* IMS Admin refresh tokens. Source of truth: design-system/design.md section 2.
|
||||||
--background: #ffffff;
|
Static emits every variable so plain CSS can use var(--color-*) too. */
|
||||||
--foreground: #171717;
|
@theme static {
|
||||||
|
--color-ink: #1f1f1f;
|
||||||
|
--color-ink-2: #303030;
|
||||||
|
--color-ink-3: #4a4a4a;
|
||||||
|
--color-muted: #616161;
|
||||||
|
--color-faint: #8a8a8a;
|
||||||
|
--color-rule: #ebebeb;
|
||||||
|
--color-rule-2: #e3e3e3;
|
||||||
|
--color-ring: #d4d4d4;
|
||||||
|
--color-surface: #ffffff;
|
||||||
|
--color-surface-2: #f7f7f7;
|
||||||
|
--color-ground: #f1f1f1;
|
||||||
|
--color-accent: #0f766e;
|
||||||
|
--color-accent-tint: #f2f7f6;
|
||||||
|
--color-accent-tint-2: #e6f4f1;
|
||||||
|
--color-danger: #b3261e;
|
||||||
|
--color-topbar: #1a1a1a;
|
||||||
|
|
||||||
|
/* Status pills: a dark step on a light tint, one pair per hue. */
|
||||||
|
--color-st-amber-bg: #fff1c2;
|
||||||
|
--color-st-amber-fg: #6b4a00;
|
||||||
|
--color-st-blue-bg: #e0efff;
|
||||||
|
--color-st-blue-fg: #00527c;
|
||||||
|
--color-st-violet-bg: #ede7ff;
|
||||||
|
--color-st-violet-fg: #4b2e99;
|
||||||
|
--color-st-orange-bg: #ffe6cf;
|
||||||
|
--color-st-orange-fg: #7a3a00;
|
||||||
|
--color-st-indigo-bg: #e3e8ff;
|
||||||
|
--color-st-indigo-fg: #2c3e8f;
|
||||||
|
--color-st-green-bg: #d7f4e3;
|
||||||
|
--color-st-green-fg: #0c5132;
|
||||||
|
--color-st-grey-bg: #ebebeb;
|
||||||
|
--color-st-grey-fg: #4a4a4a;
|
||||||
|
--color-st-red-bg: #fee3e0;
|
||||||
|
--color-st-red-fg: #8e1f0b;
|
||||||
|
|
||||||
|
/* Legacy names kept, re-valued, until every page is migrated. */
|
||||||
|
--color-divider: #e3e3e3;
|
||||||
|
--color-neutral-100: #f7f7f7;
|
||||||
|
--color-neutral-200: #ebebeb;
|
||||||
|
--color-neutral-300: #d4d4d4;
|
||||||
|
--color-neutral-400: #c4c4c4;
|
||||||
|
--color-neutral-500: #8a8a8a;
|
||||||
|
--color-neutral-600: #616161;
|
||||||
|
--color-neutral-700: #4a4a4a;
|
||||||
|
--color-neutral-800: #303030;
|
||||||
|
--color-neutral-900: #1f1f1f;
|
||||||
|
|
||||||
|
--color-accent-100: #e6f4f1;
|
||||||
|
--color-accent-200: #c5e8e0;
|
||||||
|
--color-accent-300: #9fd3c7;
|
||||||
|
--color-accent-400: #5fb3a5;
|
||||||
|
--color-accent-500: #2b9488;
|
||||||
|
--color-accent-600: #0c615a;
|
||||||
|
--color-accent-700: #0b4f47;
|
||||||
|
--color-accent-800: #083b36;
|
||||||
|
--color-accent-900: #052a26;
|
||||||
|
|
||||||
|
--color-gray-50: var(--color-neutral-100);
|
||||||
|
--color-gray-100: var(--color-neutral-200);
|
||||||
|
--color-gray-200: var(--color-neutral-300);
|
||||||
|
--color-gray-300: var(--color-neutral-400);
|
||||||
|
--color-gray-400: var(--color-neutral-500);
|
||||||
|
--color-gray-500: var(--color-neutral-600);
|
||||||
|
--color-gray-600: var(--color-neutral-700);
|
||||||
|
--color-gray-700: var(--color-neutral-800);
|
||||||
|
--color-gray-800: var(--color-neutral-900);
|
||||||
|
--color-gray-900: var(--color-ink);
|
||||||
|
--color-gray-950: var(--color-ink);
|
||||||
|
|
||||||
|
--color-blue-50: var(--color-accent-100);
|
||||||
|
--color-blue-100: var(--color-accent-100);
|
||||||
|
--color-blue-200: var(--color-accent-200);
|
||||||
|
--color-blue-300: var(--color-accent-300);
|
||||||
|
--color-blue-400: var(--color-accent-400);
|
||||||
|
--color-blue-500: var(--color-accent-500);
|
||||||
|
--color-blue-600: var(--color-accent);
|
||||||
|
--color-blue-700: var(--color-accent-700);
|
||||||
|
--color-blue-800: var(--color-accent-800);
|
||||||
|
--color-blue-900: var(--color-accent-900);
|
||||||
|
--color-blue-950: var(--color-accent-900);
|
||||||
|
|
||||||
|
--color-red-50: #fee3e0;
|
||||||
|
--color-red-100: #fee3e0;
|
||||||
|
--color-red-200: #f9c4bd;
|
||||||
|
--color-red-300: #f2a198;
|
||||||
|
--color-red-400: #e06a5a;
|
||||||
|
--color-red-500: #c9382a;
|
||||||
|
--color-red-600: var(--color-danger);
|
||||||
|
--color-red-700: #8e1f0b;
|
||||||
|
--color-red-800: #6b1708;
|
||||||
|
--color-red-900: #4a1005;
|
||||||
|
|
||||||
|
/* Radius scale: 8 buttons, chips, inputs, pills; 12 cards; 14 drawer. */
|
||||||
|
--radius: 8px;
|
||||||
|
--radius-xs: 4px;
|
||||||
|
--radius-sm: 6px;
|
||||||
|
--radius-md: 8px;
|
||||||
|
--radius-lg: 8px;
|
||||||
|
--radius-xl: 12px;
|
||||||
|
--radius-2xl: 14px;
|
||||||
|
--radius-3xl: 14px;
|
||||||
|
--radius-4xl: 14px;
|
||||||
|
|
||||||
|
--shadow-card: 0 0 0 1px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
|
||||||
|
--shadow-float: 0 0 0 1px rgba(0,0,0,.1), 0 12px 32px rgba(0,0,0,.18);
|
||||||
|
--shadow-drawer: 0 0 0 1px rgba(0,0,0,.1), 0 24px 60px rgba(0,0,0,.24);
|
||||||
|
--shadow-primary: inset 0 -1px 0 #000, inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.2);
|
||||||
|
--shadow-secondary: inset 0 0 0 1px var(--color-ring), 0 1px 0 rgba(0,0,0,.05);
|
||||||
|
--shadow-input: inset 0 0 0 1px var(--color-faint);
|
||||||
|
--shadow-chip: inset 0 0 0 1px var(--color-ring);
|
||||||
|
--shadow-chip-set: inset 0 0 0 1px var(--color-accent-300);
|
||||||
|
--shadow-sm: 0 1px 2px rgba(0,0,0,.06);
|
||||||
|
--shadow-md: 0 3px 10px rgba(0,0,0,.12);
|
||||||
|
--shadow-lg: var(--shadow-float);
|
||||||
|
--shadow-xl: var(--shadow-float);
|
||||||
|
--shadow-2xl: var(--shadow-float);
|
||||||
|
|
||||||
|
--font-sans: var(--font-geist), system-ui, sans-serif;
|
||||||
|
--font-mono: var(--font-geist-mono), ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@theme inline {
|
@layer base {
|
||||||
--color-background: var(--background);
|
html {
|
||||||
--color-foreground: var(--foreground);
|
background: var(--color-ground);
|
||||||
--font-sans: var(--font-geist-sans);
|
|
||||||
--font-mono: var(--font-geist-mono);
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
:root {
|
|
||||||
--background: #0a0a0a;
|
|
||||||
--foreground: #ededed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: var(--background);
|
background: var(--color-ground);
|
||||||
color: var(--foreground);
|
color: var(--color-ink);
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: var(--font-sans);
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
font-weight: 650;
|
||||||
|
line-height: 1.25;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
|
||||||
|
:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:focus-visible {
|
||||||
|
outline: 2px solid var(--color-accent);
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::selection {
|
||||||
|
background: color-mix(in srgb, var(--color-accent) 25%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
input,
|
input,
|
||||||
textarea,
|
textarea,
|
||||||
select {
|
select {
|
||||||
color: #111827; /* gray-900 — dark typed text */
|
color: var(--color-ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
input::placeholder,
|
input::placeholder,
|
||||||
textarea::placeholder {
|
textarea::placeholder {
|
||||||
color: #6b7280; /* gray-500 — readable placeholder */
|
color: var(--color-faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled,
|
||||||
|
input:disabled,
|
||||||
|
select:disabled,
|
||||||
|
textarea:disabled {
|
||||||
|
opacity: 0.45;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -4,8 +4,8 @@ import './globals.css'
|
|||||||
import { I18nProvider } from '@/lib/i18n/context'
|
import { I18nProvider } from '@/lib/i18n/context'
|
||||||
import { getLocale, loadMessages } from '@/lib/i18n/server'
|
import { getLocale, loadMessages } from '@/lib/i18n/server'
|
||||||
|
|
||||||
const geistSans = Geist({
|
const geist = Geist({
|
||||||
variable: '--font-geist-sans',
|
variable: '--font-geist',
|
||||||
subsets: ['latin'],
|
subsets: ['latin'],
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ export default async function RootLayout({
|
|||||||
return (
|
return (
|
||||||
<html
|
<html
|
||||||
lang={locale}
|
lang={locale}
|
||||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
className={`${geist.variable} ${geistMono.variable} h-full antialiased`}
|
||||||
>
|
>
|
||||||
<head>
|
<head>
|
||||||
<link rel="manifest" href="/manifest.json" />
|
<link rel="manifest" href="/manifest.json" />
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ export default async function ReportPage({ searchParams }: Props) {
|
|||||||
{siteName ?? 'Unknown Site'} — {zoneName}
|
{siteName ?? 'Unknown Site'} — {zoneName}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-sm text-amber-600 mt-1">No zone detected — zone will not be recorded</p>
|
<p className="text-sm text-accent-700 mt-1">No zone detected — zone will not be recorded</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ReportForm
|
<ReportForm
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default async function ReportSuccessPage({ searchParams }: Props) {
|
|||||||
const { ref } = await searchParams
|
const { ref } = await searchParams
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-gray-50 flex items-center justify-center px-4">
|
<main className="min-h-screen bg-gray-50 flex items-center justify-center px-4">
|
||||||
<div className="bg-white rounded-xl shadow-sm p-8 max-w-sm w-full text-center">
|
<div className="bg-surface shadow-sm p-8 max-w-sm w-full text-center">
|
||||||
<div className="text-4xl mb-4">✓</div>
|
<div className="text-4xl mb-4">✓</div>
|
||||||
<h1 className="text-xl font-bold text-gray-900 mb-2">Report submitted</h1>
|
<h1 className="text-xl font-bold text-gray-900 mb-2">Report submitted</h1>
|
||||||
{ref && (
|
{ref && (
|
||||||
@@ -21,7 +21,7 @@ export default async function ReportSuccessPage({ searchParams }: Props) {
|
|||||||
<p className="text-sm text-gray-500 mb-6">
|
<p className="text-sm text-gray-500 mb-6">
|
||||||
The supervisor and HSE officer have been notified.
|
The supervisor and HSE officer have been notified.
|
||||||
</p>
|
</p>
|
||||||
<Link href="/report" className="text-sm text-blue-600 hover:underline">
|
<Link href="/report" className="text-sm text-accent-700 hover:underline">
|
||||||
Submit another report
|
Submit another report
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export default function ChangePasswordForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-base font-semibold text-gray-900 mb-4">Change Password</h2>
|
<h2 className="text-base font-semibold text-gray-900 mb-4">Change Password</h2>
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
@@ -67,7 +67,7 @@ export default function ChangePasswordForm() {
|
|||||||
onChange={e => setCurrent(e.target.value)}
|
onChange={e => setCurrent(e.target.value)}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50"
|
className="w-full border border-divider px-3 py-2 text-sm focus:ring-2 focus:ring-accent focus:border-transparent disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -80,7 +80,7 @@ export default function ChangePasswordForm() {
|
|||||||
onChange={e => setNewPass(e.target.value)}
|
onChange={e => setNewPass(e.target.value)}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50"
|
className="w-full border border-divider px-3 py-2 text-sm focus:ring-2 focus:ring-accent focus:border-transparent disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -93,17 +93,17 @@ export default function ChangePasswordForm() {
|
|||||||
onChange={e => setConfirm(e.target.value)}
|
onChange={e => setConfirm(e.target.value)}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50"
|
className="w-full border border-divider px-3 py-2 text-sm focus:ring-2 focus:ring-accent focus:border-transparent disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && <p className="text-xs text-red-600 mt-1">{error}</p>}
|
{error && <p className="text-xs text-red-600 mt-1">{error}</p>}
|
||||||
{success && <p className="text-xs text-green-600 mt-1">Password changed successfully.</p>}
|
{success && <p className="text-xs text-ink mt-1">Password changed successfully.</p>}
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="bg-blue-600 text-white rounded-lg px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:bg-blue-700"
|
className="bg-accent text-white px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
{loading ? 'Saving…' : 'Update Password'}
|
{loading ? 'Saving…' : 'Update Password'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -25,20 +25,20 @@ export function AdminPanel({ users, sites, siteOptions, trucks }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex gap-1 border-b border-gray-200 mb-6">
|
<div className="flex gap-1 border-b border-divider mb-6">
|
||||||
{tabs.map(t => (
|
{tabs.map(t => (
|
||||||
<button
|
<button
|
||||||
key={t.id}
|
key={t.id}
|
||||||
onClick={() => setTab(t.id)}
|
onClick={() => setTab(t.id)}
|
||||||
className={`px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors cursor-pointer ${
|
className={`px-4 py-2.5 text-sm font-medium border-b -mb-px transition-colors cursor-pointer ${
|
||||||
tab === t.id
|
tab === t.id
|
||||||
? 'border-green-600 text-green-700'
|
? 'border-accent text-ink'
|
||||||
: 'border-transparent text-gray-500 hover:text-gray-700'
|
: 'border-transparent text-gray-500 hover:text-gray-700'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{t.label}
|
{t.label}
|
||||||
<span className={`ml-1.5 text-xs px-1.5 py-0.5 rounded-full ${
|
<span className={`ml-1.5 text-xs px-1.5 py-0.5 ${
|
||||||
tab === t.id ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-500'
|
tab === t.id ? 'bg-neutral-100 text-ink' : 'bg-gray-100 text-gray-500'
|
||||||
}`}>{t.count}</span>
|
}`}>{t.count}</span>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export function BulkImportForm() {
|
|||||||
if (stage === 'upload') {
|
if (stage === 'upload') {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<label className="block cursor-pointer rounded border-2 border-dashed border-gray-300 p-6 text-center hover:bg-gray-50">
|
<label className="block cursor-pointer border border-dashed border-divider p-6 text-center hover:bg-gray-50">
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
onChange={handleUpload}
|
onChange={handleUpload}
|
||||||
@@ -201,14 +201,14 @@ export function BulkImportForm() {
|
|||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button
|
<button
|
||||||
onClick={() => setStage('upload')}
|
onClick={() => setStage('upload')}
|
||||||
className="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded"
|
className="px-4 py-2 text-gray-600 hover:bg-gray-100"
|
||||||
>
|
>
|
||||||
Back
|
Back
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={handleImport}
|
onClick={handleImport}
|
||||||
disabled={!canImport || loading}
|
disabled={!canImport || loading}
|
||||||
className="px-4 py-2 bg-blue-600 text-white rounded disabled:opacity-50 disabled:cursor-not-allowed"
|
className="px-4 py-2 bg-accent text-white disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
{loading ? 'Importing...' : 'Import All'}
|
{loading ? 'Importing...' : 'Import All'}
|
||||||
</button>
|
</button>
|
||||||
@@ -220,9 +220,9 @@ export function BulkImportForm() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h3 className="font-bold text-green-600">✓ Import Complete</h3>
|
<h3 className="font-bold text-ink">✓ Import Complete</h3>
|
||||||
<p>{folders.length} incidents created</p>
|
<p>{folders.length} incidents created</p>
|
||||||
{message && <p className="text-green-600 text-sm">{message}</p>}
|
{message && <p className="text-ink text-sm">{message}</p>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { Modal } from '@/components/ui/modal'
|
import { Modal } from '@/components/ui/modal'
|
||||||
|
import { INPUT_CLASS as inp } from '@/components/ui/field'
|
||||||
|
|
||||||
export type SiteWithZones = {
|
export type SiteWithZones = {
|
||||||
id: string
|
id: string
|
||||||
@@ -16,7 +17,6 @@ interface Props {
|
|||||||
sites: SiteWithZones[]
|
sites: SiteWithZones[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const inp = 'w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500'
|
|
||||||
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
||||||
|
|
||||||
type DeleteTarget = { kind: 'site'; id: string; name: string } | { kind: 'zone'; id: string; name: string }
|
type DeleteTarget = { kind: 'site'; id: string; name: string } | { kind: 'zone'; id: string; name: string }
|
||||||
@@ -81,22 +81,22 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
const totalZones = sites.reduce((n, s) => n + s.zones.length, 0)
|
const totalZones = sites.reduce((n, s) => n + s.zones.length, 0)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
<div className="bg-surface border border-divider shadow-sm overflow-hidden">
|
||||||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
|
<div className="flex items-center justify-between px-5 py-4 border-b border-divider">
|
||||||
<div>
|
<div>
|
||||||
<h2 className="text-sm font-semibold text-gray-900">Sites & Zones</h2>
|
<h2 className="text-sm font-semibold text-gray-900">Sites & Zones</h2>
|
||||||
<p className="text-xs text-gray-400 mt-0.5">{sites.length} site{sites.length !== 1 ? 's' : ''} · {totalZones} zone{totalZones !== 1 ? 's' : ''}</p>
|
<p className="text-xs text-gray-400 mt-0.5">{sites.length} site{sites.length !== 1 ? 's' : ''} · {totalZones} zone{totalZones !== 1 ? 's' : ''}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button onClick={() => { setShowAddZone(true); setError(null) }}
|
<button onClick={() => { setShowAddZone(true); setError(null) }}
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-gray-100 text-gray-700 text-xs font-semibold rounded-lg hover:bg-gray-200 transition-colors cursor-pointer">
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-gray-100 text-gray-700 text-xs font-semibold hover:bg-gray-200 transition-colors cursor-pointer">
|
||||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
||||||
</svg>
|
</svg>
|
||||||
Add Zone
|
Add Zone
|
||||||
</button>
|
</button>
|
||||||
<button onClick={() => { setShowAddSite(true); setError(null) }}
|
<button onClick={() => { setShowAddSite(true); setError(null) }}
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-green-600 text-white text-xs font-semibold rounded-lg hover:bg-green-700 transition-colors cursor-pointer">
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-accent text-white text-xs font-semibold hover:bg-accent-600 transition-colors cursor-pointer">
|
||||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
||||||
</svg>
|
</svg>
|
||||||
@@ -118,10 +118,10 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<button disabled={busyId === site.id}
|
<button disabled={busyId === site.id}
|
||||||
onClick={() => send('PATCH', { kind: 'site', id: site.id, active: !site.active })}
|
onClick={() => send('PATCH', { kind: 'site', id: site.id, active: !site.active })}
|
||||||
className={`text-xs font-medium px-2.5 py-1 rounded-full border transition-colors cursor-pointer disabled:opacity-50 ${
|
className={`text-xs font-medium px-2.5 py-1 border transition-colors cursor-pointer disabled:opacity-50 ${
|
||||||
site.active
|
site.active
|
||||||
? 'bg-green-50 text-green-700 border-green-200 hover:bg-green-100'
|
? 'bg-neutral-100 text-ink border-divider hover:bg-neutral-200'
|
||||||
: 'bg-gray-50 text-gray-500 border-gray-200 hover:bg-gray-100'
|
: 'bg-gray-50 text-gray-500 border-divider hover:bg-gray-100'
|
||||||
}`}>
|
}`}>
|
||||||
{site.active ? 'Active' : 'Inactive'}
|
{site.active ? 'Active' : 'Inactive'}
|
||||||
</button>
|
</button>
|
||||||
@@ -134,21 +134,21 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{site.zones.length > 0 && (
|
{site.zones.length > 0 && (
|
||||||
<ul className="mt-3 space-y-1.5 pl-3 border-l-2 border-gray-100">
|
<ul className="mt-3 space-y-1.5 pl-3 border-l border-divider">
|
||||||
{site.zones.map(z => (
|
{site.zones.map(z => (
|
||||||
<li key={z.id} className={`flex items-center justify-between ${!z.active ? 'opacity-50' : ''}`}>
|
<li key={z.id} className={`flex items-center justify-between ${!z.active ? 'opacity-50' : ''}`}>
|
||||||
<span className="text-xs text-gray-700 font-medium">{z.name}</span>
|
<span className="text-xs text-gray-700 font-medium">{z.name}</span>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<a href={`/report?zone=${z.qr_code_token}`} target="_blank"
|
<a href={`/report?zone=${z.qr_code_token}`} target="_blank"
|
||||||
className="text-xs text-blue-600 hover:underline cursor-pointer">
|
className="text-xs text-accent-700 hover:underline cursor-pointer">
|
||||||
Report link
|
Report link
|
||||||
</a>
|
</a>
|
||||||
<button disabled={busyId === z.id}
|
<button disabled={busyId === z.id}
|
||||||
onClick={() => send('PATCH', { kind: 'zone', id: z.id, active: !z.active })}
|
onClick={() => send('PATCH', { kind: 'zone', id: z.id, active: !z.active })}
|
||||||
className={`text-xs font-medium px-2 py-0.5 rounded-full border transition-colors cursor-pointer disabled:opacity-50 ${
|
className={`text-xs font-medium px-2 py-0.5 border transition-colors cursor-pointer disabled:opacity-50 ${
|
||||||
z.active
|
z.active
|
||||||
? 'bg-green-50 text-green-700 border-green-200 hover:bg-green-100'
|
? 'bg-neutral-100 text-ink border-divider hover:bg-neutral-200'
|
||||||
: 'bg-gray-50 text-gray-500 border-gray-200 hover:bg-gray-100'
|
: 'bg-gray-50 text-gray-500 border-divider hover:bg-gray-100'
|
||||||
}`}>
|
}`}>
|
||||||
{z.active ? 'Active' : 'Inactive'}
|
{z.active ? 'Active' : 'Inactive'}
|
||||||
</button>
|
</button>
|
||||||
@@ -178,18 +178,18 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => { setShowAddSite(false); setSiteName(''); setError(null) }}
|
<button onClick={() => { setShowAddSite(false); setSiteName(''); setError(null) }}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={busy || !siteName.trim()}
|
<button disabled={busy || !siteName.trim()}
|
||||||
onClick={async () => { if (await post({ kind: 'site', name: siteName })) { setSiteName(''); setShowAddSite(false) } }}
|
onClick={async () => { if (await post({ kind: 'site', name: siteName })) { setSiteName(''); setShowAddSite(false) } }}
|
||||||
className="px-4 py-2 bg-green-600 text-white text-sm font-semibold rounded-lg hover:bg-green-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-accent text-white text-sm font-semibold hover:bg-accent-600 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{busy ? 'Adding…' : 'Add Site'}
|
{busy ? 'Adding…' : 'Add Site'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 rounded-lg mb-3">{error}</p>}
|
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 mb-3">{error}</p>}
|
||||||
<div>
|
<div>
|
||||||
<label className={lbl} htmlFor="add-site-name">Site Name *</label>
|
<label className={lbl} htmlFor="add-site-name">Site Name *</label>
|
||||||
<input id="add-site-name" type="text" placeholder="e.g. Setia Warehouse KL"
|
<input id="add-site-name" type="text" placeholder="e.g. Setia Warehouse KL"
|
||||||
@@ -205,7 +205,7 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => { setShowAddZone(false); setZoneName(''); setZoneSiteId(''); setError(null) }}
|
<button onClick={() => { setShowAddZone(false); setZoneName(''); setZoneSiteId(''); setError(null) }}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={busy || !zoneName.trim() || !zoneSiteId}
|
<button disabled={busy || !zoneName.trim() || !zoneSiteId}
|
||||||
@@ -214,13 +214,13 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
setZoneName(''); setZoneSiteId(''); setShowAddZone(false)
|
setZoneName(''); setZoneSiteId(''); setShowAddZone(false)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className="px-4 py-2 bg-green-600 text-white text-sm font-semibold rounded-lg hover:bg-green-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-accent text-white text-sm font-semibold hover:bg-accent-600 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{busy ? 'Adding…' : 'Add Zone'}
|
{busy ? 'Adding…' : 'Add Zone'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 rounded-lg mb-3">{error}</p>}
|
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 mb-3">{error}</p>}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className={lbl} htmlFor="add-zone-site">Site *</label>
|
<label className={lbl} htmlFor="add-zone-site">Site *</label>
|
||||||
@@ -243,12 +243,12 @@ export function SiteZoneManager({ sites }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => setConfirmDelete(null)}
|
<button onClick={() => setConfirmDelete(null)}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={!!(confirmDelete && busyId === confirmDelete.id)}
|
<button disabled={!!(confirmDelete && busyId === confirmDelete.id)}
|
||||||
onClick={() => confirmDelete && handleDelete(confirmDelete)}
|
onClick={() => confirmDelete && handleDelete(confirmDelete)}
|
||||||
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold rounded-lg hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { Modal } from '@/components/ui/modal'
|
import { Modal } from '@/components/ui/modal'
|
||||||
|
import { INPUT_CLASS as inp } from '@/components/ui/field'
|
||||||
|
|
||||||
export type Truck = {
|
export type Truck = {
|
||||||
id: string
|
id: string
|
||||||
@@ -15,7 +16,6 @@ interface Props {
|
|||||||
trucks: Truck[]
|
trucks: Truck[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const inp = 'w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500'
|
|
||||||
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
||||||
|
|
||||||
export function TruckManager({ trucks }: Props) {
|
export function TruckManager({ trucks }: Props) {
|
||||||
@@ -83,14 +83,14 @@ export function TruckManager({ trucks }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
<div className="bg-surface border border-divider shadow-sm overflow-hidden">
|
||||||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
|
<div className="flex items-center justify-between px-5 py-4 border-b border-divider">
|
||||||
<div>
|
<div>
|
||||||
<h2 className="text-sm font-semibold text-gray-900">Trucks</h2>
|
<h2 className="text-sm font-semibold text-gray-900">Trucks</h2>
|
||||||
<p className="text-xs text-gray-400 mt-0.5">{trucks.length} vehicle{trucks.length !== 1 ? 's' : ''}</p>
|
<p className="text-xs text-gray-400 mt-0.5">{trucks.length} vehicle{trucks.length !== 1 ? 's' : ''}</p>
|
||||||
</div>
|
</div>
|
||||||
<button onClick={() => { setShowAdd(true); setError(null) }}
|
<button onClick={() => { setShowAdd(true); setError(null) }}
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-green-600 text-white text-xs font-semibold rounded-lg hover:bg-green-700 transition-colors cursor-pointer">
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-accent text-white text-xs font-semibold hover:bg-accent-600 transition-colors cursor-pointer">
|
||||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
||||||
</svg>
|
</svg>
|
||||||
@@ -109,15 +109,15 @@ export function TruckManager({ trucks }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<a href={`/report?truck_id=${tk.id}`} target="_blank"
|
<a href={`/report?truck_id=${tk.id}`} target="_blank"
|
||||||
className="text-xs text-blue-600 hover:underline cursor-pointer">
|
className="text-xs text-accent-700 hover:underline cursor-pointer">
|
||||||
Report link
|
Report link
|
||||||
</a>
|
</a>
|
||||||
<button disabled={busyId === tk.id}
|
<button disabled={busyId === tk.id}
|
||||||
onClick={() => send('PATCH', { id: tk.id, active: !tk.active })}
|
onClick={() => send('PATCH', { id: tk.id, active: !tk.active })}
|
||||||
className={`text-xs font-medium px-2.5 py-1 rounded-full border transition-colors cursor-pointer disabled:opacity-50 ${
|
className={`text-xs font-medium px-2.5 py-1 border transition-colors cursor-pointer disabled:opacity-50 ${
|
||||||
tk.active
|
tk.active
|
||||||
? 'bg-green-50 text-green-700 border-green-200 hover:bg-green-100'
|
? 'bg-neutral-100 text-ink border-divider hover:bg-neutral-200'
|
||||||
: 'bg-gray-50 text-gray-500 border-gray-200 hover:bg-gray-100'
|
: 'bg-gray-50 text-gray-500 border-divider hover:bg-gray-100'
|
||||||
}`}>
|
}`}>
|
||||||
{tk.active ? 'Active' : 'Inactive'}
|
{tk.active ? 'Active' : 'Inactive'}
|
||||||
</button>
|
</button>
|
||||||
@@ -139,17 +139,17 @@ export function TruckManager({ trucks }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => { setShowAdd(false); setTruckNo(''); setCarrier(''); setError(null) }}
|
<button onClick={() => { setShowAdd(false); setTruckNo(''); setCarrier(''); setError(null) }}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={submitting || !truckNo.trim()} onClick={handleAdd}
|
<button disabled={submitting || !truckNo.trim()} onClick={handleAdd}
|
||||||
className="px-4 py-2 bg-green-600 text-white text-sm font-semibold rounded-lg hover:bg-green-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-accent text-white text-sm font-semibold hover:bg-accent-600 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{submitting ? 'Adding…' : 'Add Truck'}
|
{submitting ? 'Adding…' : 'Add Truck'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 rounded-lg mb-3">{error}</p>}
|
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 mb-3">{error}</p>}
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className={lbl} htmlFor="add-truck-no">Truck Number *</label>
|
<label className={lbl} htmlFor="add-truck-no">Truck Number *</label>
|
||||||
@@ -173,12 +173,12 @@ export function TruckManager({ trucks }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => setConfirmDelete(null)}
|
<button onClick={() => setConfirmDelete(null)}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={busyId === confirmDelete?.id}
|
<button disabled={busyId === confirmDelete?.id}
|
||||||
onClick={() => confirmDelete && handleDelete(confirmDelete)}
|
onClick={() => confirmDelete && handleDelete(confirmDelete)}
|
||||||
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold rounded-lg hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{busyId === confirmDelete?.id ? 'Deleting…' : 'Delete'}
|
{busyId === confirmDelete?.id ? 'Deleting…' : 'Delete'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useState } from 'react'
|
|||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import { ALL_ROLES, type UserRole } from '@/lib/auth/roles'
|
import { ALL_ROLES, type UserRole } from '@/lib/auth/roles'
|
||||||
import { Modal } from '@/components/ui/modal'
|
import { Modal } from '@/components/ui/modal'
|
||||||
|
import { INPUT_CLASS as inp } from '@/components/ui/field'
|
||||||
|
|
||||||
export type AdminUser = {
|
export type AdminUser = {
|
||||||
id: string
|
id: string
|
||||||
@@ -24,7 +25,6 @@ interface Props {
|
|||||||
|
|
||||||
const EMPTY = { email: '', name: '', phone: '', role: 'reporter' as UserRole, site_id: '', password: '' }
|
const EMPTY = { email: '', name: '', phone: '', role: 'reporter' as UserRole, site_id: '', password: '' }
|
||||||
|
|
||||||
const inp = 'w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500'
|
|
||||||
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
||||||
|
|
||||||
export function UserManager({ users, sites }: Props) {
|
export function UserManager({ users, sites }: Props) {
|
||||||
@@ -95,15 +95,15 @@ export function UserManager({ users, sites }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
<div className="bg-surface border border-divider shadow-sm overflow-hidden">
|
||||||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
|
<div className="flex items-center justify-between px-5 py-4 border-b border-divider">
|
||||||
<div>
|
<div>
|
||||||
<h2 className="text-sm font-semibold text-gray-900">Users</h2>
|
<h2 className="text-sm font-semibold text-gray-900">Users</h2>
|
||||||
<p className="text-xs text-gray-400 mt-0.5">{users.length} account{users.length !== 1 ? 's' : ''}</p>
|
<p className="text-xs text-gray-400 mt-0.5">{users.length} account{users.length !== 1 ? 's' : ''}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => { setShowAdd(true); setError(null) }}
|
onClick={() => { setShowAdd(true); setError(null) }}
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-green-600 text-white text-xs font-semibold rounded-lg hover:bg-green-700 transition-colors cursor-pointer"
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-accent text-white text-xs font-semibold hover:bg-accent-600 transition-colors cursor-pointer"
|
||||||
>
|
>
|
||||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
||||||
@@ -134,14 +134,14 @@ export function UserManager({ users, sites }: Props) {
|
|||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
<select value={u.role} disabled={busyId === u.id}
|
<select value={u.role} disabled={busyId === u.id}
|
||||||
onChange={e => patchUser(u.id, { role: e.target.value })}
|
onChange={e => patchUser(u.id, { role: e.target.value })}
|
||||||
className="border border-gray-200 rounded-lg px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-green-500 cursor-pointer">
|
className="border border-divider px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer">
|
||||||
{ALL_ROLES.map(r => <option key={r} value={r}>{r.replace(/_/g, ' ')}</option>)}
|
{ALL_ROLES.map(r => <option key={r} value={r}>{r.replace(/_/g, ' ')}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
<select value={u.site_id ?? ''} disabled={busyId === u.id}
|
<select value={u.site_id ?? ''} disabled={busyId === u.id}
|
||||||
onChange={e => patchUser(u.id, { site_id: e.target.value || null })}
|
onChange={e => patchUser(u.id, { site_id: e.target.value || null })}
|
||||||
className="border border-gray-200 rounded-lg px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-green-500 cursor-pointer">
|
className="border border-divider px-2 py-1 text-xs focus:outline-none focus:ring-1 focus:ring-accent cursor-pointer">
|
||||||
<option value="">No site</option>
|
<option value="">No site</option>
|
||||||
{sites.map(s => <option key={s.id} value={s.id}>{s.name}</option>)}
|
{sites.map(s => <option key={s.id} value={s.id}>{s.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
@@ -149,10 +149,10 @@ export function UserManager({ users, sites }: Props) {
|
|||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
<button disabled={busyId === u.id}
|
<button disabled={busyId === u.id}
|
||||||
onClick={() => patchUser(u.id, { active: !u.active })}
|
onClick={() => patchUser(u.id, { active: !u.active })}
|
||||||
className={`text-xs px-2.5 py-1 rounded-full font-medium border transition-colors cursor-pointer ${
|
className={`text-xs px-2.5 py-1 font-medium border transition-colors cursor-pointer ${
|
||||||
u.active
|
u.active
|
||||||
? 'bg-green-50 text-green-700 border-green-200 hover:bg-green-100'
|
? 'bg-neutral-100 text-ink border-divider hover:bg-neutral-200'
|
||||||
: 'bg-gray-50 text-gray-500 border-gray-200 hover:bg-gray-100'
|
: 'bg-gray-50 text-gray-500 border-divider hover:bg-gray-100'
|
||||||
}`}>
|
}`}>
|
||||||
{u.active ? 'Active' : 'Inactive'}
|
{u.active ? 'Active' : 'Inactive'}
|
||||||
</button>
|
</button>
|
||||||
@@ -178,18 +178,18 @@ export function UserManager({ users, sites }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button type="button" onClick={() => { setShowAdd(false); setForm(EMPTY); setError(null) }}
|
<button type="button" onClick={() => { setShowAdd(false); setForm(EMPTY); setError(null) }}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button form="add-user-form" type="submit" disabled={submitting}
|
<button form="add-user-form" type="submit" disabled={submitting}
|
||||||
className="px-4 py-2 bg-green-600 text-white text-sm font-semibold rounded-lg hover:bg-green-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-accent text-white text-sm font-semibold hover:bg-accent-600 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{submitting ? 'Adding…' : 'Add User'}
|
{submitting ? 'Adding…' : 'Add User'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<form id="add-user-form" onSubmit={handleSubmit} className="space-y-4">
|
<form id="add-user-form" onSubmit={handleSubmit} className="space-y-4">
|
||||||
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 rounded-lg">{error}</p>}
|
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2">{error}</p>}
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className={lbl} htmlFor="au-email">Email *</label>
|
<label className={lbl} htmlFor="au-email">Email *</label>
|
||||||
@@ -245,12 +245,12 @@ export function UserManager({ users, sites }: Props) {
|
|||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
<button onClick={() => setConfirmDelete(null)}
|
<button onClick={() => setConfirmDelete(null)}
|
||||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
className="px-4 py-2 text-sm font-medium border border-divider text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button disabled={busyId === confirmDelete?.id}
|
<button disabled={busyId === confirmDelete?.id}
|
||||||
onClick={() => confirmDelete && deleteUser(confirmDelete)}
|
onClick={() => confirmDelete && deleteUser(confirmDelete)}
|
||||||
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold rounded-lg hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
||||||
{busyId === confirmDelete?.id ? 'Deleting…' : 'Delete'}
|
{busyId === confirmDelete?.id ? 'Deleting…' : 'Delete'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Input } from '@/components/ui/field'
|
||||||
|
|
||||||
export function LoginForm() {
|
export function LoginForm() {
|
||||||
const [email, setEmail] = useState('')
|
const [email, setEmail] = useState('')
|
||||||
@@ -37,44 +39,38 @@ export function LoginForm() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="flex flex-col gap-4 w-full max-w-sm">
|
<form onSubmit={handleSubmit} className="flex flex-col gap-4 w-full max-w-sm">
|
||||||
<div className="text-center">
|
<div className="pb-3 border-b border-rule">
|
||||||
<h1 className="text-2xl font-bold">IMS</h1>
|
<h1 className="text-[22px] font-[650]">IMS</h1>
|
||||||
<p className="text-sm text-gray-500 mt-1">HSE Incident Management</p>
|
<p className="text-sm text-ink/60 mt-1">HSE Incident Management</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<p className="bg-red-50 border border-red-200 text-red-700 text-sm rounded px-3 py-2">
|
<p className="bg-st-red-bg text-st-red-fg text-[13px] px-3 py-2 rounded-md">
|
||||||
{error}
|
{error}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<input
|
<Input
|
||||||
type="email"
|
type="email"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
required
|
required
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
className="border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
/>
|
/>
|
||||||
<input
|
<Input
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
required
|
required
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
className="border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
/>
|
/>
|
||||||
<button
|
<Button type="submit" variant="primary" block disabled={loading}>
|
||||||
type="submit"
|
|
||||||
disabled={loading}
|
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 rounded-md disabled:opacity-50 transition-colors"
|
|
||||||
>
|
|
||||||
{loading ? 'Signing in…' : 'Sign in'}
|
{loading ? 'Signing in…' : 'Sign in'}
|
||||||
</button>
|
</Button>
|
||||||
<p className="text-center text-sm text-gray-500">
|
<p className="text-sm text-ink/60">
|
||||||
<Link href="/forgot-password" className="text-blue-600 hover:underline">
|
<Link href="/forgot-password" className="text-accent-700 hover:underline">
|
||||||
Forgot password?
|
Forgot password?
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import Link from 'next/link'
|
||||||
|
import { Avatar } from '@/components/ui/avatar'
|
||||||
|
import { PriorityTag, StatusTag } from '@/components/ui/status-tag'
|
||||||
|
import { STATUS_ORDER, type CapaRow } from '@/lib/capa/list'
|
||||||
|
|
||||||
|
export function CapaBoardView({ capas }: { capas: CapaRow[] }) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-3 overflow-x-auto pb-2">
|
||||||
|
{STATUS_ORDER.map(status => {
|
||||||
|
const items = capas.filter(c => c.status === status)
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
key={status}
|
||||||
|
aria-label={`${status.replace(/_/g, ' ')} column`}
|
||||||
|
className="w-72 shrink-0 rounded-xl bg-surface-2 p-2"
|
||||||
|
>
|
||||||
|
<header className="flex items-center gap-2 px-1.5 pb-2">
|
||||||
|
<StatusTag status={status} />
|
||||||
|
<span className="text-xs text-faint">{items.length}</span>
|
||||||
|
</header>
|
||||||
|
<div className="space-y-2 max-h-[70vh] overflow-y-auto">
|
||||||
|
{items.map(c => (
|
||||||
|
<Link
|
||||||
|
key={c.id}
|
||||||
|
href={`/hse/capa/${c.id}`}
|
||||||
|
className="block rounded-md bg-surface p-3 shadow-card transition-shadow hover:shadow-float"
|
||||||
|
>
|
||||||
|
<p className="text-[13px] font-medium line-clamp-2">{c.description}</p>
|
||||||
|
<p className="mt-1 font-mono text-[12px] text-accent">{c.incident_ref ?? '—'}</p>
|
||||||
|
<div className="mt-2 flex items-center justify-between gap-2">
|
||||||
|
<span className="flex min-w-0 items-center gap-1.5 text-xs text-muted">
|
||||||
|
{c.owner_name && <Avatar name={c.owner_name} />}
|
||||||
|
<span className="truncate">{c.owner_name ?? '—'}</span>
|
||||||
|
</span>
|
||||||
|
<PriorityTag priority={c.priority} />
|
||||||
|
</div>
|
||||||
|
<p className="mt-1.5 text-xs text-faint">Due {c.due_date}</p>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
{items.length === 0 && <p className="px-1.5 py-3 text-xs text-faint">Empty</p>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useState } from 'react'
|
|
||||||
import Link from 'next/link'
|
|
||||||
|
|
||||||
type CapaStatus = 'open' | 'in_progress' | 'overdue' | 'pending_verification' | 'verified' | 'reopened' | 'closed'
|
|
||||||
|
|
||||||
type CapaAction = {
|
|
||||||
id: string
|
|
||||||
incident_id: string
|
|
||||||
description: string
|
|
||||||
department: string
|
|
||||||
due_date: string
|
|
||||||
priority: 'low' | 'med' | 'high'
|
|
||||||
status: CapaStatus
|
|
||||||
incidents: { reference_no: string | null } | null
|
|
||||||
owner: { name: string } | null
|
|
||||||
}
|
|
||||||
|
|
||||||
const STATUS_ORDER: CapaStatus[] = ['open', 'in_progress', 'overdue', 'pending_verification', 'verified', 'closed']
|
|
||||||
const STATUS_LABELS: Record<CapaStatus, string> = {
|
|
||||||
open: 'Open',
|
|
||||||
in_progress: 'In Progress',
|
|
||||||
overdue: 'Overdue',
|
|
||||||
pending_verification: 'Pending Verification',
|
|
||||||
verified: 'Verified',
|
|
||||||
reopened: 'Reopened',
|
|
||||||
closed: 'Closed',
|
|
||||||
}
|
|
||||||
const STATUS_COLORS: Record<CapaStatus, string> = {
|
|
||||||
open: 'bg-blue-50 border-blue-200',
|
|
||||||
in_progress: 'bg-yellow-50 border-yellow-200',
|
|
||||||
overdue: 'bg-red-50 border-red-200',
|
|
||||||
pending_verification: 'bg-purple-50 border-purple-200',
|
|
||||||
verified: 'bg-green-50 border-green-200',
|
|
||||||
reopened: 'bg-orange-50 border-orange-200',
|
|
||||||
closed: 'bg-gray-50 border-gray-200',
|
|
||||||
}
|
|
||||||
const PRIORITY_BADGE: Record<'low' | 'med' | 'high', string> = {
|
|
||||||
low: 'bg-gray-100 text-gray-600',
|
|
||||||
med: 'bg-yellow-100 text-yellow-700',
|
|
||||||
high: 'bg-red-100 text-red-700',
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
capas: CapaAction[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CapaBoard({ capas }: Props) {
|
|
||||||
const [view, setView] = useState<'board' | 'table'>('board')
|
|
||||||
|
|
||||||
const byStatus = STATUS_ORDER.reduce<Record<CapaStatus, CapaAction[]>>((acc, s) => {
|
|
||||||
acc[s] = capas.filter(c => c.status === s)
|
|
||||||
return acc
|
|
||||||
}, {} as Record<CapaStatus, CapaAction[]>)
|
|
||||||
|
|
||||||
if (view === 'table') {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="flex justify-end mb-3">
|
|
||||||
<button onClick={() => setView('board')} className="text-sm text-blue-600 hover:underline">Board view</button>
|
|
||||||
</div>
|
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<table className="w-full text-sm">
|
|
||||||
<thead>
|
|
||||||
<tr className="text-left text-xs text-gray-500 uppercase border-b">
|
|
||||||
<th className="pb-2 pr-4">Ref</th>
|
|
||||||
<th className="pb-2 pr-4">Action</th>
|
|
||||||
<th className="pb-2 pr-4">Owner</th>
|
|
||||||
<th className="pb-2 pr-4">Due</th>
|
|
||||||
<th className="pb-2 pr-4">Priority</th>
|
|
||||||
<th className="pb-2">Status</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody className="divide-y divide-gray-100">
|
|
||||||
{capas.map(c => (
|
|
||||||
<tr key={c.id}>
|
|
||||||
<td className="py-2 pr-4 text-gray-500 text-xs">
|
|
||||||
{(c.incidents as { reference_no: string | null } | null)?.reference_no ?? '—'}
|
|
||||||
</td>
|
|
||||||
<td className="py-2 pr-4">
|
|
||||||
<Link href={`/hse/capa/${c.id}`} className="text-blue-600 hover:underline line-clamp-2">
|
|
||||||
{c.description}
|
|
||||||
</Link>
|
|
||||||
</td>
|
|
||||||
<td className="py-2 pr-4 text-gray-600">{(c.owner as { name: string } | null)?.name ?? '—'}</td>
|
|
||||||
<td className="py-2 pr-4 text-gray-600">{c.due_date}</td>
|
|
||||||
<td className="py-2 pr-4">
|
|
||||||
<span className={`px-2 py-0.5 rounded text-xs font-medium ${PRIORITY_BADGE[c.priority]}`}>
|
|
||||||
{c.priority}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td className="py-2 text-gray-600 text-xs">{STATUS_LABELS[c.status]}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="flex justify-end mb-3">
|
|
||||||
<button onClick={() => setView('table')} className="text-sm text-blue-600 hover:underline">Table view</button>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{STATUS_ORDER.filter(s => s !== 'reopened').map(status => (
|
|
||||||
<div key={status} className={`rounded-xl border p-4 ${STATUS_COLORS[status]}`}>
|
|
||||||
<h3 className="text-xs font-semibold uppercase tracking-wide text-gray-600 mb-3">
|
|
||||||
{STATUS_LABELS[status]} ({byStatus[status].length})
|
|
||||||
</h3>
|
|
||||||
<div className="space-y-2 max-h-96 overflow-y-auto pr-2">
|
|
||||||
{byStatus[status].map(c => (
|
|
||||||
<Link key={c.id} href={`/hse/capa/${c.id}`}
|
|
||||||
className="block bg-white rounded-lg p-3 shadow-sm hover:shadow-md transition-shadow border border-gray-100">
|
|
||||||
<p className="text-sm text-gray-800 line-clamp-2 mb-1">{c.description}</p>
|
|
||||||
<div className="flex items-center justify-between text-xs text-gray-500">
|
|
||||||
<span>{(c.owner as { name: string } | null)?.name ?? '—'}</span>
|
|
||||||
<span className={`px-1.5 py-0.5 rounded ${PRIORITY_BADGE[c.priority]}`}>{c.priority}</span>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-gray-400 mt-1">Due {c.due_date}</p>
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
{byStatus[status].length === 0 && (
|
|
||||||
<p className="text-xs text-gray-400 text-center py-3">Empty</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Field, Input, Select, Textarea } from '@/components/ui/field'
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
id: string
|
id: string
|
||||||
@@ -71,59 +73,62 @@ export function CapaForm({ incidentId }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
<div>
|
<Field label="Action Description *" htmlFor="capa-description">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Action Description *</label>
|
<Textarea
|
||||||
<textarea
|
id="capa-description"
|
||||||
value={description}
|
value={description}
|
||||||
onChange={e => setDescription(e.target.value)}
|
onChange={e => setDescription(e.target.value)}
|
||||||
rows={3} required
|
rows={3}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
required
|
||||||
placeholder="What corrective action will be taken?"
|
placeholder="What corrective action will be taken?"
|
||||||
/>
|
/>
|
||||||
</div>
|
</Field>
|
||||||
|
|
||||||
<div>
|
<Field label="Root Cause Reference" htmlFor="capa-root-cause">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Root Cause Reference</label>
|
<Input
|
||||||
<input type="text" value={rootCauseRef}
|
id="capa-root-cause"
|
||||||
|
type="text"
|
||||||
|
value={rootCauseRef}
|
||||||
onChange={e => setRootCauseRef(e.target.value)}
|
onChange={e => setRootCauseRef(e.target.value)}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
placeholder="e.g. Why #3 — inadequate training"
|
||||||
placeholder="e.g. Why #3 — inadequate training" />
|
/>
|
||||||
</div>
|
</Field>
|
||||||
|
|
||||||
<div>
|
<Field label="Assigned To *" htmlFor="capa-owner">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Assigned To *</label>
|
<Select id="capa-owner" value={ownerId} onChange={e => handleOwnerChange(e.target.value)} required>
|
||||||
<select value={ownerId} onChange={e => handleOwnerChange(e.target.value)} required
|
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm">
|
|
||||||
<option value="">Select owner…</option>
|
<option value="">Select owner…</option>
|
||||||
{users.map(u => (
|
{users.map(u => (
|
||||||
<option key={u.id} value={u.id}>{u.name} ({u.department})</option>
|
<option key={u.id} value={u.id}>{u.name} ({u.department})</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</Select>
|
||||||
</div>
|
</Field>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<Field label="Due Date *" htmlFor="capa-due">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Due Date *</label>
|
<Input id="capa-due" type="date" value={dueDate} onChange={e => setDueDate(e.target.value)} required />
|
||||||
<input type="date" value={dueDate} onChange={e => setDueDate(e.target.value)} required
|
</Field>
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm" />
|
<Field label="Priority" htmlFor="capa-priority">
|
||||||
</div>
|
<Select
|
||||||
<div>
|
id="capa-priority"
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Priority</label>
|
value={priority}
|
||||||
<select value={priority} onChange={e => setPriority(e.target.value as 'low' | 'med' | 'high')}
|
onChange={e => setPriority(e.target.value as 'low' | 'med' | 'high')}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm">
|
>
|
||||||
<option value="low">Low</option>
|
<option value="low">Low</option>
|
||||||
<option value="med">Medium</option>
|
<option value="med">Medium</option>
|
||||||
<option value="high">High</option>
|
<option value="high">High</option>
|
||||||
</select>
|
</Select>
|
||||||
</div>
|
</Field>
|
||||||
</div>
|
</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}
|
<Button type="submit" block disabled={saving}>
|
||||||
className="w-full bg-amber-600 text-white rounded-lg py-2 text-sm font-semibold disabled:opacity-50">
|
|
||||||
{saving ? 'Creating…' : 'Create CAPA Action'}
|
{saving ? 'Creating…' : 'Create CAPA Action'}
|
||||||
</button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
capaId: string
|
capaId: string
|
||||||
@@ -33,25 +34,17 @@ export function CapaOwnerActions({ capaId, currentStatus }: Props) {
|
|||||||
|
|
||||||
if (currentStatus === 'open' || currentStatus === 'reopened' || currentStatus === 'overdue') {
|
if (currentStatus === 'open' || currentStatus === 'reopened' || currentStatus === 'overdue') {
|
||||||
return (
|
return (
|
||||||
<button
|
<Button variant="secondary" onClick={() => updateStatus('in_progress')} disabled={loading}>
|
||||||
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'}
|
{loading ? '…' : 'Mark In Progress'}
|
||||||
</button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentStatus === 'in_progress') {
|
if (currentStatus === 'in_progress') {
|
||||||
return (
|
return (
|
||||||
<button
|
<Button onClick={() => updateStatus('pending_verification')} disabled={loading}>
|
||||||
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'}
|
{loading ? '…' : 'Submit for Verification'}
|
||||||
</button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Field, Textarea } from '@/components/ui/field'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
capaId: string
|
capaId: string
|
||||||
@@ -32,25 +34,22 @@ export function CapaOwnerNotesForm({ capaId, initialNotes }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-3 space-y-1">
|
<div className="mt-3 space-y-2">
|
||||||
<label className="text-xs text-gray-500 font-medium">Remarks / Notes</label>
|
<Field label="Remarks / Notes" htmlFor={`notes-${capaId}`}>
|
||||||
<textarea
|
<Textarea
|
||||||
|
id={`notes-${capaId}`}
|
||||||
value={notes}
|
value={notes}
|
||||||
onChange={e => { setNotes(e.target.value); setSaved(false) }}
|
onChange={e => { setNotes(e.target.value); setSaved(false) }}
|
||||||
rows={2}
|
rows={2}
|
||||||
placeholder="Add any notes or updates for this action…"
|
placeholder="Add any notes or updates for this action…"
|
||||||
className="w-full rounded-md border border-gray-200 px-3 py-2 text-sm text-gray-800 resize-none focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
/>
|
/>
|
||||||
{error && <p className="text-xs text-red-600">{error}</p>}
|
</Field>
|
||||||
|
{error && <p role="alert" className="text-xs text-danger">{error}</p>}
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<button
|
<Button variant="secondary" onClick={handleSave} disabled={saving}>
|
||||||
onClick={handleSave}
|
|
||||||
disabled={saving}
|
|
||||||
className="text-xs px-3 py-1 bg-gray-800 text-white rounded-md hover:bg-gray-700 disabled:opacity-50"
|
|
||||||
>
|
|
||||||
{saving ? 'Saving…' : 'Save Notes'}
|
{saving ? 'Saving…' : 'Save Notes'}
|
||||||
</button>
|
</Button>
|
||||||
{saved && <span className="text-xs text-green-600">Saved</span>}
|
{saved && <span className="text-xs text-st-green-fg">Saved</span>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useMemo, useState } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { ChevronRight, Columns3, List, Search } from 'lucide-react'
|
||||||
|
import { Avatar } from '@/components/ui/avatar'
|
||||||
|
import { FilterChip } from '@/components/ui/filter-chip'
|
||||||
|
import { Segmented } from '@/components/ui/segmented'
|
||||||
|
import { PriorityTag, StatusTag } from '@/components/ui/status-tag'
|
||||||
|
import { TableCard, type Column } from '@/components/ui/table-card'
|
||||||
|
import {
|
||||||
|
EMPTY_FILTERS, PAGE_SIZE, VIEWS, daysLate, distinct, filterCapas, nextSort, paginate, sortCapas, viewCounts,
|
||||||
|
type CapaFilters, type CapaRow, type CapaSort, type CapaSortKey, type CapaViewKey,
|
||||||
|
} from '@/lib/capa/list'
|
||||||
|
import { CapaBoardView } from './capa-board-view'
|
||||||
|
|
||||||
|
const PRIORITY_OPTIONS = [
|
||||||
|
{ value: 'high', label: 'High' },
|
||||||
|
{ value: 'med', label: 'Medium' },
|
||||||
|
{ value: 'low', label: 'Low' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const toOptions = (values: string[]) => values.map(v => ({ value: v, label: v }))
|
||||||
|
|
||||||
|
function Owner({ name }: { name: string | null }) {
|
||||||
|
if (!name) return <span className="text-faint">—</span>
|
||||||
|
return (
|
||||||
|
<span className="inline-flex items-center gap-2">
|
||||||
|
<Avatar name={name} />
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Due({ row, today }: { row: CapaRow; today: string }) {
|
||||||
|
const late = row.status === 'overdue' ? daysLate(row.due_date, today) : 0
|
||||||
|
return (
|
||||||
|
<span className="whitespace-nowrap">
|
||||||
|
{row.due_date}
|
||||||
|
{late > 0 && <span className="ml-1.5 text-xs text-danger">{`${late} day${late === 1 ? '' : 's'} late`}</span>}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CapaWorkspace({ capas, today }: { capas: CapaRow[]; today: string }) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [mode, setMode] = useState<'list' | 'board'>('list')
|
||||||
|
const [filters, setFilters] = useState<CapaFilters>(EMPTY_FILTERS)
|
||||||
|
const [sort, setSort] = useState<CapaSort>({ key: 'due_date', dir: 'asc' })
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
|
||||||
|
const patch = (next: Partial<CapaFilters>) => {
|
||||||
|
setFilters(f => ({ ...f, ...next }))
|
||||||
|
setPage(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const owners = useMemo(() => distinct(capas.map(c => c.owner_name)), [capas])
|
||||||
|
const departments = useMemo(() => distinct(capas.map(c => c.department)), [capas])
|
||||||
|
const counts = useMemo(() => viewCounts(capas, filters), [capas, filters])
|
||||||
|
const sorted = useMemo(() => sortCapas(filterCapas(capas, filters), sort), [capas, filters, sort])
|
||||||
|
const boardRows = useMemo(
|
||||||
|
() => sortCapas(filterCapas(capas, { ...filters, view: 'all' }), { key: 'due_date', dir: 'asc' }),
|
||||||
|
[capas, filters],
|
||||||
|
)
|
||||||
|
const pageData = paginate(sorted, page, PAGE_SIZE)
|
||||||
|
const clearable = Boolean(filters.q || filters.owner || filters.department || filters.priority)
|
||||||
|
|
||||||
|
const columns: Column<CapaRow>[] = [
|
||||||
|
{ key: 'action', header: 'Action', cell: r => <span className="line-clamp-2 font-medium">{r.description}</span> },
|
||||||
|
{ key: 'incident', header: 'Incident', cell: r => <span className="font-mono text-[12.5px] text-accent">{r.incident_ref ?? '—'}</span> },
|
||||||
|
{ key: 'owner', header: 'Owner', cell: r => <Owner name={r.owner_name} /> },
|
||||||
|
{ key: 'department', header: 'Department', cell: r => r.department },
|
||||||
|
{ key: 'priority', header: 'Priority', sortKey: 'priority', cell: r => <PriorityTag priority={r.priority} /> },
|
||||||
|
{ key: 'due', header: 'Due', sortKey: 'due_date', cell: r => <Due row={r} today={today} /> },
|
||||||
|
{ key: 'status', header: 'Status', sortKey: 'status', cell: r => <StatusTag status={r.status} /> },
|
||||||
|
]
|
||||||
|
|
||||||
|
const toolbar = (
|
||||||
|
<>
|
||||||
|
<label className="flex h-8 min-w-[260px] items-center gap-2 rounded-md bg-surface px-2.5 text-[13px] shadow-input">
|
||||||
|
<Search size={16} strokeWidth={2} className="text-muted" aria-hidden />
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
aria-label="Search actions"
|
||||||
|
placeholder="Search action, incident or owner"
|
||||||
|
value={filters.q}
|
||||||
|
onChange={e => patch({ q: e.target.value })}
|
||||||
|
className="flex-1 bg-transparent outline-none placeholder:text-faint"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<FilterChip label="Owner" value={filters.owner} options={toOptions(owners)} onChange={v => patch({ owner: v })} />
|
||||||
|
<FilterChip label="Department" value={filters.department} options={toOptions(departments)} onChange={v => patch({ department: v })} />
|
||||||
|
<FilterChip label="Priority" value={filters.priority} options={PRIORITY_OPTIONS} onChange={v => patch({ priority: v })} />
|
||||||
|
{clearable && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => patch({ q: '', owner: '', department: '', priority: '' })}
|
||||||
|
className="cursor-pointer text-[12.5px] text-muted hover:text-ink"
|
||||||
|
>
|
||||||
|
Clear filters
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h1 className="text-[22px] font-[650] md:text-xl">CAPA</h1>
|
||||||
|
<Segmented
|
||||||
|
value={mode}
|
||||||
|
onChange={v => setMode(v as 'list' | 'board')}
|
||||||
|
options={[
|
||||||
|
{ value: 'list', label: <><List size={14} strokeWidth={2} aria-hidden />List</> },
|
||||||
|
{ value: 'board', label: <><Columns3 size={14} strokeWidth={2} aria-hidden />Board</> },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{mode === 'list' ? (
|
||||||
|
<TableCard
|
||||||
|
columns={columns}
|
||||||
|
rows={pageData.items}
|
||||||
|
rowKey={r => r.id}
|
||||||
|
onRowOpen={r => router.push(`/hse/capa/${r.id}`)}
|
||||||
|
views={{
|
||||||
|
items: VIEWS.map(v => ({ key: v.key, label: v.label, count: counts[v.key] })),
|
||||||
|
active: filters.view,
|
||||||
|
onChange: key => patch({ view: key as CapaViewKey }),
|
||||||
|
}}
|
||||||
|
toolbar={toolbar}
|
||||||
|
sort={sort}
|
||||||
|
onSortChange={key => {
|
||||||
|
setSort(nextSort(sort, key as CapaSortKey))
|
||||||
|
setPage(1)
|
||||||
|
}}
|
||||||
|
footer={
|
||||||
|
pageData.total > 0
|
||||||
|
? { from: pageData.from, to: pageData.to, total: pageData.total, page: pageData.page, pageCount: pageData.pageCount, onPage: setPage }
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
empty={{ title: 'No CAPA actions match' }}
|
||||||
|
mobileRow={r => (
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<div className="min-w-0 flex-1 space-y-1">
|
||||||
|
<p className="line-clamp-2 text-[13px] font-medium">{r.description}</p>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<StatusTag status={r.status} />
|
||||||
|
<PriorityTag priority={r.priority} />
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-faint">
|
||||||
|
{[r.incident_ref, r.owner_name, `Due ${r.due_date}`].filter(Boolean).join(' · ')}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ChevronRight size={16} strokeWidth={2} className="mt-1 text-faint" aria-hidden />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex flex-wrap items-center gap-2">{toolbar}</div>
|
||||||
|
<CapaBoardView capas={boardRows} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
capaId: string
|
capaId: string
|
||||||
@@ -31,19 +32,21 @@ export function CloseCapaButton({ capaId }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border border-gray-200 rounded-xl p-5 space-y-3 bg-green-50">
|
<div className="space-y-3 rounded-xl bg-surface p-5 shadow-card">
|
||||||
<h3 className="text-sm font-semibold text-gray-800">Close CAPA</h3>
|
<div>
|
||||||
<p className="text-sm text-gray-600">
|
<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.
|
This CAPA has been verified as effective. Close it to mark it fully resolved.
|
||||||
</p>
|
</p>
|
||||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
</div>
|
||||||
<button
|
{error && (
|
||||||
onClick={handleClose}
|
<p role="alert" className="rounded-md bg-st-red-bg px-3 py-2 text-[13px] text-st-red-fg">
|
||||||
disabled={loading}
|
{error}
|
||||||
className="w-full bg-green-700 text-white rounded-lg py-2 text-sm font-semibold hover:bg-green-800 disabled:opacity-50"
|
</p>
|
||||||
>
|
)}
|
||||||
|
<Button onClick={handleClose} disabled={loading}>
|
||||||
{loading ? 'Closing…' : 'Close CAPA'}
|
{loading ? 'Closing…' : 'Close CAPA'}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,47 @@
|
|||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
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 {
|
interface Props {
|
||||||
capaId: string
|
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) {
|
export function VerifyForm({ capaId }: Props) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [verdict, setVerdict] = useState<'verified' | 'reopened' | null>(null)
|
const [verdict, setVerdict] = useState<Verdict | null>(null)
|
||||||
const [reopenReason, setReopenReason] = useState('')
|
const [reopenReason, setReopenReason] = useState('')
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
@@ -39,50 +72,50 @@ export function VerifyForm({ capaId }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="border border-gray-200 rounded-xl p-5 space-y-4 bg-purple-50">
|
<form onSubmit={handleSubmit} className="space-y-4 rounded-xl bg-surface p-5 shadow-card">
|
||||||
<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 rounded-lg text-sm font-medium border ${
|
|
||||||
verdict === 'verified'
|
|
||||||
? 'bg-green-600 text-white border-green-600'
|
|
||||||
: 'bg-white text-gray-700 border-gray-300 hover:border-green-500'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
Verified — Effective
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setVerdict('reopened')}
|
|
||||||
className={`flex-1 py-2 rounded-lg text-sm font-medium border ${
|
|
||||||
verdict === 'reopened'
|
|
||||||
? 'bg-orange-600 text-white border-orange-600'
|
|
||||||
: 'bg-white text-gray-700 border-gray-300 hover:border-orange-500'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
Reopen — Ineffective
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{verdict === 'reopened' && (
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">Why is the action ineffective? *</label>
|
<h3 className="text-sm font-semibold">Verify this action</h3>
|
||||||
<textarea
|
<p className="mt-0.5 text-xs text-muted">Confirm the corrective action fixed the root cause, or send it back.</p>
|
||||||
value={reopenReason}
|
</div>
|
||||||
onChange={e => setReopenReason(e.target.value)}
|
|
||||||
rows={2} required
|
<div role="radiogroup" aria-label="Verification verdict" className="grid gap-3 sm:grid-cols-2">
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
<Choice
|
||||||
placeholder="Describe why the corrective action did not resolve the root cause…"
|
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>
|
</div>
|
||||||
|
|
||||||
|
{verdict === 'reopened' && (
|
||||||
|
<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
|
||||||
|
placeholder="Describe why the corrective action did not resolve the root cause…"
|
||||||
|
/>
|
||||||
|
</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 && (
|
{verdict && (
|
||||||
<button type="submit" disabled={saving}
|
<Button type="submit" disabled={saving}>
|
||||||
className="w-full bg-gray-900 text-white rounded-lg py-2 text-sm font-semibold disabled:opacity-50">
|
{saving ? 'Saving…' : verdict === 'verified' ? 'Confirm verification' : 'Reopen action'}
|
||||||
{saving ? 'Saving…' : 'Submit Verification'}
|
</Button>
|
||||||
</button>
|
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ function TabsInner({ activeTab }: { activeTab: string }) {
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex border-b border-gray-200 mb-6 overflow-x-auto -mx-4 px-4">
|
<div className="flex border-b border-divider mb-6 overflow-x-auto -mx-4 px-4">
|
||||||
{TABS.map(tab => (
|
{TABS.map(tab => (
|
||||||
<button
|
<button
|
||||||
key={tab.key}
|
key={tab.key}
|
||||||
onClick={() => router.replace(`${pathname}?tab=${tab.key}`)}
|
onClick={() => router.replace(`${pathname}?tab=${tab.key}`)}
|
||||||
className={`px-4 py-2.5 text-sm font-medium whitespace-nowrap border-b-2 transition-colors ${
|
className={`px-4 py-2.5 text-sm font-medium whitespace-nowrap border-b transition-colors ${
|
||||||
activeTab === tab.key
|
activeTab === tab.key
|
||||||
? 'border-blue-600 text-blue-600'
|
? 'border-accent text-accent-700'
|
||||||
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
|
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-divider'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{tab.label}
|
{tab.label}
|
||||||
@@ -35,7 +35,7 @@ function TabsInner({ activeTab }: { activeTab: string }) {
|
|||||||
|
|
||||||
export function DashboardTabs({ activeTab }: { activeTab: string }) {
|
export function DashboardTabs({ activeTab }: { activeTab: string }) {
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<div className="h-11 mb-6 border-b border-gray-200" />}>
|
<Suspense fallback={<div className="h-11 mb-6 border-b border-divider" />}>
|
||||||
<TabsInner activeTab={activeTab} />
|
<TabsInner activeTab={activeTab} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ type RiskFlag = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const LEVEL_COLORS: Record<RiskFlag['risk_level'], string> = {
|
const LEVEL_COLORS: Record<RiskFlag['risk_level'], string> = {
|
||||||
low: 'bg-yellow-50 text-yellow-700 border-yellow-200',
|
low: 'bg-st-grey-bg text-st-grey-fg border-transparent',
|
||||||
medium: 'bg-orange-50 text-orange-700 border-orange-200',
|
medium: 'bg-st-amber-bg text-st-amber-fg border-transparent',
|
||||||
high: 'bg-red-50 text-red-700 border-red-200',
|
high: 'bg-st-red-bg text-st-red-fg border-transparent',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RiskFlagsPanel() {
|
export function RiskFlagsPanel() {
|
||||||
@@ -43,7 +43,7 @@ export function RiskFlagsPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5 mb-4">
|
<div className="bg-surface shadow-sm p-5 mb-4">
|
||||||
<div className="flex items-center justify-between mb-1">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide">
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide">
|
||||||
Rising-Risk Zones (AI)
|
Rising-Risk Zones (AI)
|
||||||
@@ -51,7 +51,7 @@ export function RiskFlagsPanel() {
|
|||||||
<button
|
<button
|
||||||
onClick={analyze}
|
onClick={analyze}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="bg-purple-50 text-purple-700 border border-purple-300 rounded-lg px-3 py-1.5 text-xs font-semibold disabled:opacity-50 hover:bg-purple-100"
|
className="bg-accent-100 text-accent-700 border border-accent-300 px-3 py-1.5 text-xs font-semibold disabled:opacity-50 hover:bg-accent-200"
|
||||||
>
|
>
|
||||||
{loading ? 'Analyzing…' : flags ? 'Re-analyze' : 'Analyze 90-Day Risk'}
|
{loading ? 'Analyzing…' : flags ? 'Re-analyze' : 'Analyze 90-Day Risk'}
|
||||||
</button>
|
</button>
|
||||||
@@ -71,7 +71,7 @@ export function RiskFlagsPanel() {
|
|||||||
<p className="text-sm text-gray-700 mb-3">{summary}</p>
|
<p className="text-sm text-gray-700 mb-3">{summary}</p>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{flags.map(f => (
|
{flags.map(f => (
|
||||||
<div key={`${f.site}-${f.zone}`} className={`border rounded-lg p-3 ${LEVEL_COLORS[f.risk_level]}`}>
|
<div key={`${f.site}-${f.zone}`} className={`border rounded-md p-3 ${LEVEL_COLORS[f.risk_level]}`}>
|
||||||
<div className="flex items-center justify-between mb-1">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<span className="text-sm font-semibold">{f.zone} · {f.site}</span>
|
<span className="text-sm font-semibold">{f.zone} · {f.site}</span>
|
||||||
<span className="text-xs font-bold uppercase">{f.risk_level}</span>
|
<span className="text-xs font-bold uppercase">{f.risk_level}</span>
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ interface Props {
|
|||||||
|
|
||||||
const ACCENT = {
|
const ACCENT = {
|
||||||
default: 'border-gray-200',
|
default: 'border-gray-200',
|
||||||
green: 'border-green-400',
|
green: 'border-divider',
|
||||||
yellow: 'border-yellow-400',
|
yellow: 'border-accent-300',
|
||||||
red: 'border-red-400',
|
red: 'border-red-400',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StatCard({ label, value, sub, accent = 'default' }: Props) {
|
export function StatCard({ label, value, sub, accent = 'default' }: Props) {
|
||||||
return (
|
return (
|
||||||
<div className={`bg-white rounded-xl shadow-sm p-5 border-t-4 ${ACCENT[accent]}`}>
|
<div className={`bg-surface shadow-sm p-5 border-t-4 ${ACCENT[accent]}`}>
|
||||||
<p className="text-xs text-gray-500 uppercase tracking-wide font-medium">{label}</p>
|
<p className="text-xs text-gray-500 uppercase tracking-wide font-medium">{label}</p>
|
||||||
<p className="text-3xl font-bold text-gray-900 mt-1">{value}</p>
|
<p className="text-3xl font-bold text-gray-900 mt-1">{value}</p>
|
||||||
{sub && <p className="text-xs text-gray-400 mt-1">{sub}</p>}
|
{sub && <p className="text-xs text-gray-400 mt-1">{sub}</p>}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function ClosurePanel({ incidentId, status, canClose, canAddAddenda }: Pr
|
|||||||
<button
|
<button
|
||||||
onClick={closeIncident}
|
onClick={closeIncident}
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
className="bg-green-700 text-white rounded-lg px-4 py-2 text-sm font-semibold hover:bg-green-800 disabled:opacity-50"
|
className="bg-accent text-white px-4 py-2 text-sm font-semibold hover:bg-accent-700 disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{busy ? 'Closing…' : 'Close Incident'}
|
{busy ? 'Closing…' : 'Close Incident'}
|
||||||
</button>
|
</button>
|
||||||
@@ -89,7 +89,7 @@ export function ClosurePanel({ incidentId, status, canClose, canAddAddenda }: Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-6 bg-white rounded-xl shadow-sm p-5">
|
<div className="mt-6 bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-1">Addenda</h2>
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-1">Addenda</h2>
|
||||||
<p className="text-xs text-gray-400 mb-3">
|
<p className="text-xs text-gray-400 mb-3">
|
||||||
This incident is closed and locked. New information is recorded as addenda.
|
This incident is closed and locked. New information is recorded as addenda.
|
||||||
@@ -99,7 +99,7 @@ export function ClosurePanel({ incidentId, status, canClose, canAddAddenda }: Pr
|
|||||||
) : (
|
) : (
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{addenda.map(a => (
|
{addenda.map(a => (
|
||||||
<li key={a.id} className="border border-gray-100 rounded-lg p-3">
|
<li key={a.id} className="border border-divider p-3">
|
||||||
<p className="text-sm text-gray-800 whitespace-pre-wrap">{a.body}</p>
|
<p className="text-sm text-gray-800 whitespace-pre-wrap">{a.body}</p>
|
||||||
<p className="text-xs text-gray-400 mt-1">
|
<p className="text-xs text-gray-400 mt-1">
|
||||||
{a.author?.name ?? 'Unknown'} · {new Date(a.created_at).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
{a.author?.name ?? 'Unknown'} · {new Date(a.created_at).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })}
|
||||||
@@ -115,12 +115,12 @@ export function ClosurePanel({ incidentId, status, canClose, canAddAddenda }: Pr
|
|||||||
onChange={e => setDraft(e.target.value)}
|
onChange={e => setDraft(e.target.value)}
|
||||||
rows={3}
|
rows={3}
|
||||||
placeholder="Add an addendum…"
|
placeholder="Add an addendum…"
|
||||||
className="w-full border border-gray-200 rounded-lg p-2 text-sm"
|
className="w-full border border-divider p-2 text-sm"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={addAddendum}
|
onClick={addAddendum}
|
||||||
disabled={busy || !draft.trim()}
|
disabled={busy || !draft.trim()}
|
||||||
className="mt-2 bg-gray-800 text-white rounded-lg px-4 py-2 text-sm font-semibold hover:bg-gray-900 disabled:opacity-50"
|
className="mt-2 bg-gray-800 text-white px-4 py-2 text-sm font-semibold hover:bg-gray-900 disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{busy ? 'Saving…' : 'Add Addendum'}
|
{busy ? 'Saving…' : 'Add Addendum'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export function EvidenceGallery({ files, stage }: Props) {
|
|||||||
href={file.file_url}
|
href={file.file_url}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="block rounded-lg overflow-hidden bg-gray-100 aspect-square hover:opacity-90 transition-opacity"
|
className="block overflow-hidden bg-gray-100 aspect-square hover:opacity-90 transition-opacity"
|
||||||
>
|
>
|
||||||
{isImage(file.file_type) ? (
|
{isImage(file.file_type) ? (
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ export function FileUpload({ onFilesChange, disabled = false }: Props) {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div
|
<div
|
||||||
className={`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors
|
className={`border border-dashed p-6 text-center cursor-pointer transition-colors
|
||||||
${dragging ? 'border-blue-500 bg-blue-50' : 'border-gray-300 hover:border-gray-400'}
|
${dragging ? 'border-accent bg-accent-100' : 'border-divider hover:border-gray-400'}
|
||||||
${disabled ? 'opacity-50 pointer-events-none' : ''}`}
|
${disabled ? 'opacity-50 pointer-events-none' : ''}`}
|
||||||
onClick={() => inputRef.current?.click()}
|
onClick={() => inputRef.current?.click()}
|
||||||
onDragOver={e => { e.preventDefault(); setDragging(true) }}
|
onDragOver={e => { e.preventDefault(); setDragging(true) }}
|
||||||
@@ -94,7 +94,7 @@ export function FileUpload({ onFilesChange, disabled = false }: Props) {
|
|||||||
{files.length > 0 && (
|
{files.length > 0 && (
|
||||||
<ul className="space-y-1">
|
<ul className="space-y-1">
|
||||||
{files.map((f, i) => (
|
{files.map((f, i) => (
|
||||||
<li key={i} className="flex items-center justify-between bg-gray-50 rounded px-3 py-2 text-sm">
|
<li key={i} className="flex items-center justify-between bg-gray-50 px-3 py-2 text-sm">
|
||||||
<span className="truncate max-w-xs">{f.name}</span>
|
<span className="truncate max-w-xs">{f.name}</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { EvidenceGallery } from './evidence-gallery'
|
import { EvidenceGallery } from './evidence-gallery'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
const TYPE_LABELS: Record<string, string> = {
|
const TYPE_LABELS: Record<string, string> = {
|
||||||
injury: 'Injury / Medical',
|
injury: 'Injury / Medical',
|
||||||
@@ -11,15 +12,6 @@ const TYPE_LABELS: Record<string, string> = {
|
|||||||
transport: 'Transport / Vehicle',
|
transport: 'Transport / Vehicle',
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-yellow-100 text-yellow-800',
|
|
||||||
triaged: 'bg-blue-100 text-blue-800',
|
|
||||||
investigating: 'bg-purple-100 text-purple-800',
|
|
||||||
capa_pending: 'bg-orange-100 text-orange-800',
|
|
||||||
verification: 'bg-indigo-100 text-indigo-800',
|
|
||||||
closed: 'bg-green-100 text-green-800',
|
|
||||||
}
|
|
||||||
|
|
||||||
const MEDICAL_LABELS: Record<string, string> = {
|
const MEDICAL_LABELS: Record<string, string> = {
|
||||||
none: 'None',
|
none: 'None',
|
||||||
first_aid: 'First Aid',
|
first_aid: 'First Aid',
|
||||||
@@ -72,7 +64,7 @@ export function IncidentDetail({ incident }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<div className="flex items-start justify-between mb-4">
|
<div className="flex items-start justify-between mb-4">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-xl font-bold text-gray-900 font-mono">
|
<h1 className="text-xl font-bold text-gray-900 font-mono">
|
||||||
@@ -80,9 +72,7 @@ export function IncidentDetail({ incident }: Props) {
|
|||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm text-gray-600 mt-0.5">{TYPE_LABELS[incident.incident_type] ?? incident.incident_type}</p>
|
<p className="text-sm text-gray-600 mt-0.5">{TYPE_LABELS[incident.incident_type] ?? incident.incident_type}</p>
|
||||||
</div>
|
</div>
|
||||||
<span className={`text-xs px-2.5 py-1 rounded-full font-medium ${STATUS_COLORS[incident.status] ?? 'bg-gray-100'}`}>
|
<StatusTag status={incident.status}>{incident.status.replace(/_/g, ' ').toUpperCase()}</StatusTag>
|
||||||
{incident.status.replace(/_/g, ' ').toUpperCase()}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<dl className="grid grid-cols-2 gap-4 sm:grid-cols-3">
|
<dl className="grid grid-cols-2 gap-4 sm:grid-cols-3">
|
||||||
@@ -114,12 +104,12 @@ export function IncidentDetail({ incident }: Props) {
|
|||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-2">Description</h2>
|
<h2 className="text-sm font-semibold text-gray-900 mb-2">Description</h2>
|
||||||
<p className="text-sm text-gray-800 leading-relaxed whitespace-pre-wrap">{incident.description}</p>
|
<p className="text-sm text-gray-800 leading-relaxed whitespace-pre-wrap">{incident.description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="bg-white rounded-xl shadow-sm p-5">
|
<div className="bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-900 mb-3">
|
<h2 className="text-sm font-semibold text-gray-900 mb-3">
|
||||||
Evidence — Report Stage
|
Evidence — Report Stage
|
||||||
<span className="ml-2 text-gray-400 font-normal normal-case">
|
<span className="ml-2 text-gray-400 font-normal normal-case">
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useRouter, useSearchParams, usePathname } from 'next/navigation'
|
|
||||||
import { useCallback, useState, useTransition, Suspense } from 'react'
|
|
||||||
|
|
||||||
const STATUS_OPTIONS = [
|
|
||||||
{ value: '', label: 'All Statuses' },
|
|
||||||
{ value: 'reported', label: 'Reported' },
|
|
||||||
{ value: 'triaged', label: 'Triaged' },
|
|
||||||
{ value: 'investigating', label: 'Investigating' },
|
|
||||||
{ value: 'capa_pending', label: 'CAPA Pending' },
|
|
||||||
{ value: 'verification', label: 'Pending Verification' },
|
|
||||||
{ value: 'closed', label: 'Closed' },
|
|
||||||
]
|
|
||||||
|
|
||||||
const TYPE_OPTIONS = [
|
|
||||||
{ value: '', label: 'All Types' },
|
|
||||||
{ value: 'injury', label: 'Injury' },
|
|
||||||
{ value: 'near_miss', label: 'Near Miss' },
|
|
||||||
{ value: 'hazard', label: 'Hazard' },
|
|
||||||
{ value: 'asset_damage', label: 'Asset Damage' },
|
|
||||||
{ value: 'environmental', label: 'Environmental' },
|
|
||||||
{ value: 'security', label: 'Security' },
|
|
||||||
{ value: 'fire', label: 'Fire' },
|
|
||||||
{ value: 'transport', label: 'Transport' },
|
|
||||||
]
|
|
||||||
|
|
||||||
export interface SiteOption { id: string; name: string }
|
|
||||||
export interface TruckOption { id: string; truck_no: string }
|
|
||||||
|
|
||||||
interface FiltersProps {
|
|
||||||
sites: SiteOption[]
|
|
||||||
trucks: TruckOption[]
|
|
||||||
}
|
|
||||||
|
|
||||||
function FiltersInner({ sites, trucks }: FiltersProps) {
|
|
||||||
const router = useRouter()
|
|
||||||
const pathname = usePathname()
|
|
||||||
const searchParams = useSearchParams()
|
|
||||||
const [, startTransition] = useTransition()
|
|
||||||
const [search, setSearch] = useState(searchParams.get('q') ?? '')
|
|
||||||
|
|
||||||
const updateParam = useCallback((key: string, value: string) => {
|
|
||||||
const params = new URLSearchParams(searchParams.toString())
|
|
||||||
if (value) {
|
|
||||||
params.set(key, value)
|
|
||||||
} else {
|
|
||||||
params.delete(key)
|
|
||||||
}
|
|
||||||
params.delete('page')
|
|
||||||
startTransition(() => {
|
|
||||||
router.replace(`${pathname}?${params.toString()}`)
|
|
||||||
})
|
|
||||||
}, [router, pathname, searchParams])
|
|
||||||
|
|
||||||
const handleSearch = useCallback((value: string) => {
|
|
||||||
setSearch(value)
|
|
||||||
const timer = setTimeout(() => updateParam('q', value), 300)
|
|
||||||
return () => clearTimeout(timer)
|
|
||||||
}, [updateParam])
|
|
||||||
|
|
||||||
const hasFilters = searchParams.get('q') || searchParams.get('status') ||
|
|
||||||
searchParams.get('type') || searchParams.get('site_id') || searchParams.get('truck_id')
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex flex-wrap gap-2 mb-4">
|
|
||||||
<div className="relative flex-1 min-w-48">
|
|
||||||
<svg
|
|
||||||
className="absolute left-2.5 top-2 h-4 w-4 text-gray-400 pointer-events-none"
|
|
||||||
fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
|
||||||
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
|
||||||
</svg>
|
|
||||||
<input
|
|
||||||
type="search"
|
|
||||||
placeholder="Search reference or description..."
|
|
||||||
value={search}
|
|
||||||
onChange={e => handleSearch(e.target.value)}
|
|
||||||
className="w-full pl-8 pr-3 py-1.5 text-sm border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<select
|
|
||||||
value={searchParams.get('status') ?? ''}
|
|
||||||
onChange={e => updateParam('status', e.target.value)}
|
|
||||||
className="text-sm border border-gray-300 rounded-lg px-2 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white"
|
|
||||||
>
|
|
||||||
{STATUS_OPTIONS.map(o => <option key={o.value} value={o.value}>{o.label}</option>)}
|
|
||||||
</select>
|
|
||||||
<select
|
|
||||||
value={searchParams.get('type') ?? ''}
|
|
||||||
onChange={e => updateParam('type', e.target.value)}
|
|
||||||
className="text-sm border border-gray-300 rounded-lg px-2 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white"
|
|
||||||
>
|
|
||||||
{TYPE_OPTIONS.map(o => <option key={o.value} value={o.value}>{o.label}</option>)}
|
|
||||||
</select>
|
|
||||||
{sites.length > 0 && (
|
|
||||||
<select
|
|
||||||
value={searchParams.get('site_id') ?? ''}
|
|
||||||
onChange={e => updateParam('site_id', e.target.value)}
|
|
||||||
className="text-sm border border-gray-300 rounded-lg px-2 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white"
|
|
||||||
>
|
|
||||||
<option value="">All Sites</option>
|
|
||||||
{sites.map(s => <option key={s.id} value={s.id}>{s.name}</option>)}
|
|
||||||
</select>
|
|
||||||
)}
|
|
||||||
{trucks.length > 0 && (
|
|
||||||
<select
|
|
||||||
value={searchParams.get('truck_id') ?? ''}
|
|
||||||
onChange={e => updateParam('truck_id', e.target.value)}
|
|
||||||
className="text-sm border border-gray-300 rounded-lg px-2 py-1.5 focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white"
|
|
||||||
>
|
|
||||||
<option value="">All Trucks</option>
|
|
||||||
{trucks.map(tk => <option key={tk.id} value={tk.id}>{tk.truck_no}</option>)}
|
|
||||||
</select>
|
|
||||||
)}
|
|
||||||
{hasFilters && (
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
setSearch('')
|
|
||||||
router.replace(pathname)
|
|
||||||
}}
|
|
||||||
className="text-sm text-gray-500 hover:text-gray-700 px-2 py-1.5 underline"
|
|
||||||
>
|
|
||||||
Clear filters
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function IncidentFilters({ sites, trucks }: FiltersProps) {
|
|
||||||
return (
|
|
||||||
<Suspense fallback={<div className="h-10 mb-4" />}>
|
|
||||||
<FiltersInner sites={sites} trucks={trucks} />
|
|
||||||
</Suspense>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
incidentId: string
|
incidentId: string
|
||||||
@@ -12,15 +13,6 @@ interface Props {
|
|||||||
canAddCapa?: boolean
|
canAddCapa?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-yellow-100 text-yellow-800',
|
|
||||||
triaged: 'bg-blue-100 text-blue-800',
|
|
||||||
investigating: 'bg-purple-100 text-purple-800',
|
|
||||||
capa_pending: 'bg-orange-100 text-orange-800',
|
|
||||||
verification: 'bg-indigo-100 text-indigo-800',
|
|
||||||
closed: 'bg-green-100 text-green-800',
|
|
||||||
}
|
|
||||||
|
|
||||||
const STATUS_LABELS: Record<string, string> = {
|
const STATUS_LABELS: Record<string, string> = {
|
||||||
reported: 'Reported',
|
reported: 'Reported',
|
||||||
triaged: 'Triaged',
|
triaged: 'Triaged',
|
||||||
@@ -35,7 +27,7 @@ export function IncidentHeader({
|
|||||||
canTriage, canInvestigate, canAddCapa,
|
canTriage, canInvestigate, canAddCapa,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
<div className="sticky top-0 z-30 bg-white border-b border-gray-200 shadow-sm">
|
<div className="sticky top-0 z-30 bg-surface border-b border-divider shadow-sm">
|
||||||
<div className="max-w-3xl mx-auto px-4 py-3 flex items-center justify-between gap-4 flex-wrap">
|
<div className="max-w-3xl mx-auto px-4 py-3 flex items-center justify-between gap-4 flex-wrap">
|
||||||
<div className="flex items-center gap-3 min-w-0">
|
<div className="flex items-center gap-3 min-w-0">
|
||||||
<Link href={backHref} className="text-sm text-gray-500 hover:text-gray-700 shrink-0">
|
<Link href={backHref} className="text-sm text-gray-500 hover:text-gray-700 shrink-0">
|
||||||
@@ -45,15 +37,13 @@ export function IncidentHeader({
|
|||||||
<span className="text-sm font-mono font-semibold text-gray-900 truncate">
|
<span className="text-sm font-mono font-semibold text-gray-900 truncate">
|
||||||
{referenceNo ?? 'Pending'}
|
{referenceNo ?? 'Pending'}
|
||||||
</span>
|
</span>
|
||||||
<span className={`text-xs px-2 py-0.5 rounded-full font-medium shrink-0 ${STATUS_COLORS[status] ?? 'bg-gray-100 text-gray-800'}`}>
|
<span className="shrink-0"><StatusTag status={status}>{STATUS_LABELS[status] ?? status.replace(/_/g, ' ')}</StatusTag></span>
|
||||||
{STATUS_LABELS[status] ?? status.replace(/_/g, ' ')}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2 shrink-0">
|
<div className="flex gap-2 shrink-0">
|
||||||
{canTriage && (
|
{canTriage && (
|
||||||
<Link
|
<Link
|
||||||
href={`/hse/incidents/${incidentId}/triage`}
|
href={`/hse/incidents/${incidentId}/triage`}
|
||||||
className="text-xs px-3 py-1.5 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700"
|
className="text-xs px-3 py-1.5 bg-accent text-white font-medium hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
Triage
|
Triage
|
||||||
</Link>
|
</Link>
|
||||||
@@ -61,7 +51,7 @@ export function IncidentHeader({
|
|||||||
{canInvestigate && (
|
{canInvestigate && (
|
||||||
<Link
|
<Link
|
||||||
href={`/hse/incidents/${incidentId}/investigation`}
|
href={`/hse/incidents/${incidentId}/investigation`}
|
||||||
className="text-xs px-3 py-1.5 bg-indigo-600 text-white rounded-lg font-medium hover:bg-indigo-700"
|
className="text-xs px-3 py-1.5 bg-accent text-white font-medium hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
Investigate
|
Investigate
|
||||||
</Link>
|
</Link>
|
||||||
@@ -69,7 +59,7 @@ export function IncidentHeader({
|
|||||||
{canAddCapa && (
|
{canAddCapa && (
|
||||||
<Link
|
<Link
|
||||||
href={`/hse/incidents/${incidentId}/capa/new`}
|
href={`/hse/incidents/${incidentId}/capa/new`}
|
||||||
className="text-xs px-3 py-1.5 bg-amber-600 text-white rounded-lg font-medium hover:bg-amber-700"
|
className="text-xs px-3 py-1.5 bg-accent text-white font-medium hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
Add CAPA
|
Add CAPA
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,137 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import { useState } from 'react'
|
|
||||||
import Link from 'next/link'
|
|
||||||
|
|
||||||
const TYPE_LABELS: Record<string, string> = {
|
|
||||||
injury: 'Injury / Medical',
|
|
||||||
near_miss: 'Near Miss',
|
|
||||||
hazard: 'Hazard',
|
|
||||||
asset_damage: 'Asset Damage',
|
|
||||||
environmental: 'Environmental',
|
|
||||||
security: 'Security',
|
|
||||||
fire: 'Fire / Emergency',
|
|
||||||
transport: 'Transport / Vehicle',
|
|
||||||
}
|
|
||||||
|
|
||||||
const STATUS_COLORS: Record<string, string> = {
|
|
||||||
reported: 'bg-yellow-100 text-yellow-800',
|
|
||||||
triaged: 'bg-blue-100 text-blue-800',
|
|
||||||
investigating: 'bg-purple-100 text-purple-800',
|
|
||||||
capa_pending: 'bg-orange-100 text-orange-800',
|
|
||||||
verification: 'bg-indigo-100 text-indigo-800',
|
|
||||||
closed: 'bg-green-100 text-green-800',
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Incident = {
|
|
||||||
id: string
|
|
||||||
reference_no: string | null
|
|
||||||
incident_type: string
|
|
||||||
status: string
|
|
||||||
severity: number | null
|
|
||||||
reported_at: string
|
|
||||||
sites: { name: string } | null
|
|
||||||
zones: { name: string } | null
|
|
||||||
trucks: { truck_no: string } | null
|
|
||||||
reporter: { name: string } | null
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
incidents: Incident[]
|
|
||||||
basePath: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function IncidentList({ incidents, basePath }: Props) {
|
|
||||||
const [typeFilter, setTypeFilter] = useState('')
|
|
||||||
const [statusFilter, setStatusFilter] = useState('')
|
|
||||||
const [search, setSearch] = useState('')
|
|
||||||
|
|
||||||
const filtered = incidents.filter(inc => {
|
|
||||||
if (typeFilter && inc.incident_type !== typeFilter) return false
|
|
||||||
if (statusFilter && inc.status !== statusFilter) return false
|
|
||||||
if (search) {
|
|
||||||
const q = search.toLowerCase()
|
|
||||||
return (
|
|
||||||
inc.reference_no?.toLowerCase().includes(q) ||
|
|
||||||
inc.incident_type.includes(q) ||
|
|
||||||
(inc.sites?.name ?? '').toLowerCase().includes(q)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="flex flex-wrap gap-2">
|
|
||||||
<input
|
|
||||||
type="search"
|
|
||||||
placeholder="Search ref, type, site…"
|
|
||||||
className="border border-gray-300 rounded-lg px-3 py-2 text-sm w-48 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
value={search}
|
|
||||||
onChange={e => setSearch(e.target.value)}
|
|
||||||
/>
|
|
||||||
<select
|
|
||||||
className="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
value={typeFilter}
|
|
||||||
onChange={e => setTypeFilter(e.target.value)}
|
|
||||||
>
|
|
||||||
<option value="">All types</option>
|
|
||||||
{Object.entries(TYPE_LABELS).map(([v, l]) => (
|
|
||||||
<option key={v} value={v}>{l}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
<select
|
|
||||||
className="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
||||||
value={statusFilter}
|
|
||||||
onChange={e => setStatusFilter(e.target.value)}
|
|
||||||
>
|
|
||||||
<option value="">All statuses</option>
|
|
||||||
{Object.keys(STATUS_COLORS).map(s => (
|
|
||||||
<option key={s} value={s}>{s.replace(/_/g, ' ')}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{filtered.length === 0 ? (
|
|
||||||
<div className="text-center py-12 text-gray-500 text-sm">No incidents found</div>
|
|
||||||
) : (
|
|
||||||
<div className="divide-y divide-gray-100 bg-white rounded-xl shadow-sm overflow-hidden">
|
|
||||||
{filtered.map(inc => (
|
|
||||||
<Link
|
|
||||||
key={inc.id}
|
|
||||||
href={`${basePath}/incidents/${inc.id}`}
|
|
||||||
className="flex items-center justify-between px-4 py-3 hover:bg-gray-50 transition-colors"
|
|
||||||
>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<div className="flex items-center gap-2 mb-0.5">
|
|
||||||
<span className="font-mono text-sm font-semibold text-gray-900">
|
|
||||||
{inc.reference_no ?? '—'}
|
|
||||||
</span>
|
|
||||||
<span className={`text-xs px-2 py-0.5 rounded-full font-medium ${STATUS_COLORS[inc.status] ?? 'bg-gray-100 text-gray-700'}`}>
|
|
||||||
{inc.status.replace(/_/g, ' ').toUpperCase()}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="text-sm text-gray-600">
|
|
||||||
{TYPE_LABELS[inc.incident_type] ?? inc.incident_type}
|
|
||||||
{inc.zones?.name && ` · ${inc.zones.name}`}
|
|
||||||
{inc.sites?.name && ` · ${inc.sites.name}`}
|
|
||||||
{inc.trucks?.truck_no && (
|
|
||||||
<span className="ml-1 text-xs text-gray-400">· {inc.trucks.truck_no}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="ml-4 text-right">
|
|
||||||
<div className="text-xs text-gray-400">
|
|
||||||
{new Date(inc.reported_at).toLocaleDateString('en-MY')}
|
|
||||||
</div>
|
|
||||||
{inc.severity && (
|
|
||||||
<div className="text-xs text-gray-500 mt-0.5">Sev {inc.severity}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Link>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
|
||||||
|
import { ChevronRight, Eye, Search } from 'lucide-react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { FilterChip } from '@/components/ui/filter-chip'
|
||||||
|
import { StatusTag } from '@/components/ui/status-tag'
|
||||||
|
import { TableCard, type Column } from '@/components/ui/table-card'
|
||||||
|
import { PAGE_SIZE, nextSort, withParams, type ListParams, type SortKey } from '@/lib/incidents/list-params'
|
||||||
|
import type { Incident, SiteOption, TruckOption } from '@/lib/incidents/types'
|
||||||
|
|
||||||
|
const TYPE_LABELS: Record<string, string> = {
|
||||||
|
injury: 'Injury / Medical',
|
||||||
|
near_miss: 'Near Miss',
|
||||||
|
hazard: 'Hazard',
|
||||||
|
asset_damage: 'Asset Damage',
|
||||||
|
environmental: 'Environmental',
|
||||||
|
security: 'Security',
|
||||||
|
fire: 'Fire / Emergency',
|
||||||
|
transport: 'Transport / Vehicle',
|
||||||
|
}
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = [
|
||||||
|
{ value: 'reported', label: 'Reported' },
|
||||||
|
{ value: 'triaged', label: 'Triaged' },
|
||||||
|
{ value: 'investigating', label: 'Investigating' },
|
||||||
|
{ value: 'capa_pending', label: 'CAPA pending' },
|
||||||
|
{ value: 'verification', label: 'Verification' },
|
||||||
|
{ value: 'closed', label: 'Closed' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = Object.entries(TYPE_LABELS).map(([value, label]) => ({ value, label }))
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
incidents: Incident[]
|
||||||
|
basePath: string
|
||||||
|
total: number
|
||||||
|
counts: { all: number; open: number; closed: number }
|
||||||
|
params: ListParams
|
||||||
|
sites: SiteOption[]
|
||||||
|
trucks: TruckOption[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const fmtDate = (iso: string) => new Date(iso).toLocaleDateString('en-MY')
|
||||||
|
|
||||||
|
export function IncidentTable({ incidents, basePath, total, counts, params, sites, trucks }: Props) {
|
||||||
|
const router = useRouter()
|
||||||
|
const pathname = usePathname()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const search = searchParams.toString() ? `?${searchParams.toString()}` : ''
|
||||||
|
const [q, setQ] = useState(params.q)
|
||||||
|
|
||||||
|
const update = (updates: Record<string, string | null>) =>
|
||||||
|
router.replace(`${pathname}${withParams(search, updates)}`)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (q === params.q) return
|
||||||
|
const timer = setTimeout(() => update({ q: q || null }), 300)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [q])
|
||||||
|
|
||||||
|
const columns: Column<Incident>[] = [
|
||||||
|
{
|
||||||
|
key: 'reference',
|
||||||
|
header: 'Reference',
|
||||||
|
sortKey: 'reference_no',
|
||||||
|
cell: r => <span className="font-mono text-[12.5px] text-accent">{r.reference_no ?? '—'}</span>,
|
||||||
|
},
|
||||||
|
{ key: 'status', header: 'Status', sortKey: 'status', cell: r => <StatusTag status={r.status} /> },
|
||||||
|
{ key: 'type', header: 'Type', cell: r => TYPE_LABELS[r.incident_type] ?? r.incident_type },
|
||||||
|
{
|
||||||
|
key: 'location',
|
||||||
|
header: 'Location',
|
||||||
|
cell: r => [r.zones?.name, r.sites?.name, r.trucks?.truck_no].filter(Boolean).join(' · ') || '—',
|
||||||
|
},
|
||||||
|
{ key: 'severity', header: 'Severity', cell: r => (r.severity ? `Sev ${r.severity}` : '—') },
|
||||||
|
{ key: 'reported', header: 'Reported', sortKey: 'reported_at', cell: r => fmtDate(r.reported_at) },
|
||||||
|
]
|
||||||
|
|
||||||
|
const clearable = Boolean(params.q || params.status || params.type || params.siteId || params.truckId)
|
||||||
|
const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE))
|
||||||
|
const from = incidents.length === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
|
||||||
|
const to = incidents.length === 0 ? 0 : from + incidents.length - 1
|
||||||
|
|
||||||
|
const toolbar = (
|
||||||
|
<>
|
||||||
|
<label className="flex items-center gap-2 h-8 px-2.5 rounded-md bg-surface shadow-input text-[13px] min-w-[260px]">
|
||||||
|
<Search size={16} strokeWidth={2} className="text-muted" aria-hidden />
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
aria-label="Search incidents"
|
||||||
|
placeholder="Search reference or description"
|
||||||
|
value={q}
|
||||||
|
onChange={e => setQ(e.target.value)}
|
||||||
|
className="flex-1 bg-transparent outline-none placeholder:text-faint"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<FilterChip label="Status" value={params.status} options={STATUS_OPTIONS} onChange={v => update({ status: v || null })} />
|
||||||
|
<FilterChip label="Type" value={params.type} options={TYPE_OPTIONS} onChange={v => update({ type: v || null })} />
|
||||||
|
{sites.length > 0 && (
|
||||||
|
<FilterChip
|
||||||
|
label="Site"
|
||||||
|
value={params.siteId}
|
||||||
|
options={sites.map(s => ({ value: s.id, label: s.name }))}
|
||||||
|
onChange={v => update({ site_id: v || null })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{trucks.length > 0 && (
|
||||||
|
<FilterChip
|
||||||
|
label="Truck"
|
||||||
|
value={params.truckId}
|
||||||
|
options={trucks.map(t => ({ value: t.id, label: t.truck_no }))}
|
||||||
|
onChange={v => update({ truck_id: v || null })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{clearable && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setQ('')
|
||||||
|
router.replace(pathname)
|
||||||
|
}}
|
||||||
|
className="text-[12.5px] text-muted hover:text-ink cursor-pointer"
|
||||||
|
>
|
||||||
|
Clear filters
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableCard
|
||||||
|
columns={columns}
|
||||||
|
rows={incidents}
|
||||||
|
rowKey={r => r.id}
|
||||||
|
onRowOpen={r => router.push(`${basePath}/incidents/${r.id}`)}
|
||||||
|
rowActions={r => (
|
||||||
|
<Link
|
||||||
|
href={`${basePath}/incidents/${r.id}`}
|
||||||
|
aria-label="Open incident"
|
||||||
|
className="inline-grid place-items-center w-7 h-7 rounded-md text-ink-3 hover:bg-rule"
|
||||||
|
>
|
||||||
|
<Eye size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
views={{
|
||||||
|
items: [
|
||||||
|
{ key: 'all', label: 'All', count: counts.all },
|
||||||
|
{ key: 'open', label: 'Open', count: counts.open },
|
||||||
|
{ key: 'closed', label: 'Closed', count: counts.closed },
|
||||||
|
],
|
||||||
|
active: params.view,
|
||||||
|
onChange: key => update({ view: key === 'all' ? null : key }),
|
||||||
|
}}
|
||||||
|
toolbar={toolbar}
|
||||||
|
sort={{ key: params.sort, dir: params.dir }}
|
||||||
|
onSortChange={key => {
|
||||||
|
const next = nextSort({ key: params.sort, dir: params.dir }, key as SortKey)
|
||||||
|
update({ sort: next.key, dir: next.dir })
|
||||||
|
}}
|
||||||
|
footer={total > 0 ? { from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) } : undefined}
|
||||||
|
empty={{
|
||||||
|
title: 'No incidents found',
|
||||||
|
action: <Button onClick={() => router.push('/report')}>Report incident</Button>,
|
||||||
|
}}
|
||||||
|
mobileRow={r => (
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<div className="min-w-0 flex-1 space-y-1">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="font-mono text-[12.5px] text-accent">{r.reference_no ?? '—'}</span>
|
||||||
|
<StatusTag status={r.status} />
|
||||||
|
</div>
|
||||||
|
<p className="text-[13px] text-ink-3">
|
||||||
|
{[TYPE_LABELS[r.incident_type] ?? r.incident_type, r.zones?.name].filter(Boolean).join(' · ')}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-faint">{fmtDate(r.reported_at)}</p>
|
||||||
|
</div>
|
||||||
|
<ChevronRight size={16} strokeWidth={2} className="mt-1 text-faint" aria-hidden />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -136,7 +136,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={getAiDraft}
|
onClick={getAiDraft}
|
||||||
disabled={aiDraftLoading}
|
disabled={aiDraftLoading}
|
||||||
className="bg-purple-50 text-purple-700 border border-purple-300 rounded-lg px-3 py-1.5 text-xs font-semibold disabled:opacity-50 hover:bg-purple-100"
|
className="bg-accent-100 text-accent-700 border border-accent-300 px-3 py-1.5 text-xs font-semibold disabled:opacity-50 hover:bg-accent-200"
|
||||||
>
|
>
|
||||||
{aiDraftLoading ? 'Drafting…' : 'Get AI Draft'}
|
{aiDraftLoading ? 'Drafting…' : 'Get AI Draft'}
|
||||||
</button>
|
</button>
|
||||||
@@ -148,10 +148,10 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
<button
|
<button
|
||||||
key={m} type="button"
|
key={m} type="button"
|
||||||
onClick={() => setMethod(m)}
|
onClick={() => setMethod(m)}
|
||||||
className={`px-3 py-1.5 rounded-lg text-sm font-medium border ${
|
className={`px-3 py-1.5 text-sm font-medium border ${
|
||||||
method === m
|
method === m
|
||||||
? 'bg-blue-600 text-white border-blue-600'
|
? 'bg-accent text-white border-accent'
|
||||||
: 'bg-white text-gray-700 border-gray-300 hover:border-blue-400'
|
: 'bg-surface text-gray-700 border-divider hover:border-accent'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{m === 'five_why' ? '5-Why' : m === 'fishbone' ? 'Fishbone' : 'Other'}
|
{m === 'five_why' ? '5-Why' : m === 'fishbone' ? 'Fishbone' : 'Other'}
|
||||||
@@ -164,25 +164,25 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<p className="text-sm font-medium text-gray-700">5-Why Analysis</p>
|
<p className="text-sm font-medium text-gray-700">5-Why Analysis</p>
|
||||||
{fiveWhy.map((step, i) => (
|
{fiveWhy.map((step, i) => (
|
||||||
<div key={i} className="border border-gray-200 rounded-lg p-3 space-y-2">
|
<div key={i} className="border border-divider p-3 space-y-2">
|
||||||
<label className="block text-xs text-gray-500">Why #{i + 1}</label>
|
<label className="block text-xs text-gray-500">Why #{i + 1}</label>
|
||||||
<input
|
<input
|
||||||
type="text" value={step.why}
|
type="text" value={step.why}
|
||||||
onChange={e => updateWhyStep(i, 'why', e.target.value)}
|
onChange={e => updateWhyStep(i, 'why', e.target.value)}
|
||||||
placeholder="Why did this happen?"
|
placeholder="Why did this happen?"
|
||||||
className="w-full rounded border border-gray-300 px-2 py-1.5 text-sm"
|
className="w-full border border-divider px-2 py-1.5 text-sm"
|
||||||
/>
|
/>
|
||||||
<textarea
|
<textarea
|
||||||
value={step.answer}
|
value={step.answer}
|
||||||
onChange={e => updateWhyStep(i, 'answer', e.target.value)}
|
onChange={e => updateWhyStep(i, 'answer', e.target.value)}
|
||||||
rows={2} placeholder="Answer / finding…"
|
rows={2} placeholder="Answer / finding…"
|
||||||
className="w-full rounded border border-gray-300 px-2 py-1.5 text-sm"
|
className="w-full border border-divider px-2 py-1.5 text-sm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{fiveWhy.length < 5 && (
|
{fiveWhy.length < 5 && (
|
||||||
<button type="button" onClick={addWhyStep}
|
<button type="button" onClick={addWhyStep}
|
||||||
className="text-sm text-blue-600 hover:underline">
|
className="text-sm text-accent-700 hover:underline">
|
||||||
+ Add another Why
|
+ Add another Why
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -193,7 +193,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<p className="text-sm font-medium text-gray-700">Fishbone (Ishikawa) Analysis</p>
|
<p className="text-sm font-medium text-gray-700">Fishbone (Ishikawa) Analysis</p>
|
||||||
{fishbone.map((cat, catIdx) => (
|
{fishbone.map((cat, catIdx) => (
|
||||||
<div key={cat.category} className="border border-gray-200 rounded-lg p-3">
|
<div key={cat.category} className="border border-divider p-3">
|
||||||
<p className="text-xs font-semibold text-gray-600 mb-2">{CATEGORY_LABELS[cat.category]}</p>
|
<p className="text-xs font-semibold text-gray-600 mb-2">{CATEGORY_LABELS[cat.category]}</p>
|
||||||
{cat.causes.map((cause, causeIdx) => (
|
{cat.causes.map((cause, causeIdx) => (
|
||||||
<input
|
<input
|
||||||
@@ -201,11 +201,11 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
type="text" value={cause}
|
type="text" value={cause}
|
||||||
onChange={e => updateFishboneCause(catIdx, causeIdx, e.target.value)}
|
onChange={e => updateFishboneCause(catIdx, causeIdx, e.target.value)}
|
||||||
placeholder="Contributing cause…"
|
placeholder="Contributing cause…"
|
||||||
className="w-full rounded border border-gray-300 px-2 py-1.5 text-sm mb-1.5"
|
className="w-full border border-divider px-2 py-1.5 text-sm mb-1.5"
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<button type="button" onClick={() => addFishboneCause(catIdx)}
|
<button type="button" onClick={() => addFishboneCause(catIdx)}
|
||||||
className="text-xs text-blue-600 hover:underline">
|
className="text-xs text-accent-700 hover:underline">
|
||||||
+ Add cause
|
+ Add cause
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -219,7 +219,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
<select
|
<select
|
||||||
value={alcoholTest}
|
value={alcoholTest}
|
||||||
onChange={e => setAlcoholTest(e.target.value)}
|
onChange={e => setAlcoholTest(e.target.value)}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
className="w-full border border-divider px-3 py-2 text-sm"
|
||||||
>
|
>
|
||||||
<option value="">Not conducted</option>
|
<option value="">Not conducted</option>
|
||||||
<option value="negative">Negative</option>
|
<option value="negative">Negative</option>
|
||||||
@@ -233,7 +233,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
<select
|
<select
|
||||||
value={urineTest}
|
value={urineTest}
|
||||||
onChange={e => setUrineTest(e.target.value)}
|
onChange={e => setUrineTest(e.target.value)}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
className="w-full border border-divider px-3 py-2 text-sm"
|
||||||
>
|
>
|
||||||
<option value="">Not conducted</option>
|
<option value="">Not conducted</option>
|
||||||
<option value="negative">Negative</option>
|
<option value="negative">Negative</option>
|
||||||
@@ -256,13 +256,13 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
value={ref}
|
value={ref}
|
||||||
onChange={e => setWitnessRefs(witnessRefs.map((w, j) => (j === i ? e.target.value : w)))}
|
onChange={e => setWitnessRefs(witnessRefs.map((w, j) => (j === i ? e.target.value : w)))}
|
||||||
placeholder="e.g. Ali bin Ahmad — statement dated 12/07/2026"
|
placeholder="e.g. Ali bin Ahmad — statement dated 12/07/2026"
|
||||||
className="w-full rounded border border-gray-300 px-2 py-1.5 text-sm mb-1.5"
|
className="w-full border border-divider px-2 py-1.5 text-sm mb-1.5"
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setWitnessRefs([...witnessRefs, ''])}
|
onClick={() => setWitnessRefs([...witnessRefs, ''])}
|
||||||
className="text-xs text-blue-600 hover:underline"
|
className="text-xs text-accent-700 hover:underline"
|
||||||
>
|
>
|
||||||
+ Add witness statement
|
+ Add witness statement
|
||||||
</button>
|
</button>
|
||||||
@@ -274,7 +274,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
value={findingsText}
|
value={findingsText}
|
||||||
onChange={e => setFindingsText(e.target.value)}
|
onChange={e => setFindingsText(e.target.value)}
|
||||||
rows={3}
|
rows={3}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
className="w-full border border-divider px-3 py-2 text-sm"
|
||||||
placeholder="Describe the sequence of events and contributing factors…"
|
placeholder="Describe the sequence of events and contributing factors…"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -285,7 +285,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
value={rootCause}
|
value={rootCause}
|
||||||
onChange={e => setRootCause(e.target.value)}
|
onChange={e => setRootCause(e.target.value)}
|
||||||
rows={2}
|
rows={2}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
|
className="w-full border border-divider px-3 py-2 text-sm"
|
||||||
placeholder="One-sentence root cause statement…"
|
placeholder="One-sentence root cause statement…"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -293,7 +293,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
{!existingInvestigationId && (
|
{!existingInvestigationId && (
|
||||||
<label className="flex items-center gap-2 text-sm text-gray-700">
|
<label className="flex items-center gap-2 text-sm text-gray-700">
|
||||||
<input type="checkbox" checked={complete} onChange={e => setComplete(e.target.checked)}
|
<input type="checkbox" checked={complete} onChange={e => setComplete(e.target.checked)}
|
||||||
className="rounded border-gray-300 text-blue-600" />
|
className="border-divider text-accent-700" />
|
||||||
Mark investigation complete (transitions incident to CAPA Pending)
|
Mark investigation complete (transitions incident to CAPA Pending)
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
@@ -301,7 +301,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
|||||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||||
|
|
||||||
<button type="submit" disabled={saving}
|
<button type="submit" disabled={saving}
|
||||||
className="w-full bg-indigo-600 text-white rounded-lg py-2 text-sm font-semibold disabled:opacity-50">
|
className="w-full bg-accent text-white py-2 text-sm font-semibold disabled:opacity-50">
|
||||||
{saving ? 'Saving…' : existingInvestigationId ? 'Update Investigation' : 'Start Investigation'}
|
{saving ? 'Saving…' : existingInvestigationId ? 'Update Investigation' : 'Start Investigation'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -35,15 +35,15 @@ export function InvestigationPanel({ investigation: inv }: Props) {
|
|||||||
const investigatorName = inv.investigator?.name ?? inv.investigator?.email ?? 'Unknown'
|
const investigatorName = inv.investigator?.name ?? inv.investigator?.email ?? 'Unknown'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-6 bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
<div className="mt-6 bg-surface shadow-sm border border-divider overflow-hidden">
|
||||||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
|
<div className="flex items-center justify-between px-5 py-4 border-b border-divider">
|
||||||
<h2 className="text-sm font-semibold text-gray-900">Investigation</h2>
|
<h2 className="text-sm font-semibold text-gray-900">Investigation</h2>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<span className="text-xs text-gray-500">{METHOD_LABELS[inv.method] ?? inv.method}</span>
|
<span className="text-xs text-gray-500">{METHOD_LABELS[inv.method] ?? inv.method}</span>
|
||||||
<span className={`text-xs font-medium px-2 py-0.5 rounded-full ${
|
<span className={`text-xs font-medium px-2 py-0.5 ${
|
||||||
inv.completed_at
|
inv.completed_at
|
||||||
? 'bg-green-100 text-green-700'
|
? 'bg-st-green-bg text-st-green-fg'
|
||||||
: 'bg-yellow-100 text-yellow-700'
|
: 'bg-st-blue-bg text-st-blue-fg'
|
||||||
}`}>
|
}`}>
|
||||||
{inv.completed_at ? 'Completed' : 'In Progress'}
|
{inv.completed_at ? 'Completed' : 'In Progress'}
|
||||||
</span>
|
</span>
|
||||||
@@ -67,7 +67,7 @@ export function InvestigationPanel({ investigation: inv }: Props) {
|
|||||||
<ol className="space-y-3">
|
<ol className="space-y-3">
|
||||||
{inv.five_why_steps.map((step, i) => (
|
{inv.five_why_steps.map((step, i) => (
|
||||||
<li key={i} className="flex gap-3">
|
<li key={i} className="flex gap-3">
|
||||||
<span className="flex-shrink-0 w-6 h-6 rounded-full bg-blue-100 text-blue-700 text-xs font-bold flex items-center justify-center">
|
<span className="flex-shrink-0 w-6 h-6 bg-accent-100 text-accent-700 text-xs font-bold flex items-center justify-center">
|
||||||
{i + 1}
|
{i + 1}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
@@ -107,7 +107,7 @@ export function InvestigationPanel({ investigation: inv }: Props) {
|
|||||||
|
|
||||||
{/* Root cause */}
|
{/* Root cause */}
|
||||||
{inv.root_cause_summary && (
|
{inv.root_cause_summary && (
|
||||||
<div className="bg-red-50 border border-red-100 rounded-lg px-4 py-3">
|
<div className="bg-red-50 border border-red-100 px-4 py-3">
|
||||||
<h3 className="text-xs font-semibold text-red-600 uppercase tracking-wide mb-1">Root Cause</h3>
|
<h3 className="text-xs font-semibold text-red-600 uppercase tracking-wide mb-1">Root Cause</h3>
|
||||||
<p className="text-sm text-gray-900 whitespace-pre-wrap">{inv.root_cause_summary}</p>
|
<p className="text-sm text-gray-900 whitespace-pre-wrap">{inv.root_cause_summary}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -56,15 +56,15 @@ export function OfflineSync() {
|
|||||||
if (pendingCount === 0) return null
|
if (pendingCount === 0) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed bottom-4 left-4 right-4 bg-yellow-50 border border-yellow-300 rounded-lg p-3 flex items-center justify-between shadow-md z-50">
|
<div className="fixed bottom-4 left-4 right-4 bg-st-amber-bg rounded-xl p-3 flex items-center justify-between shadow-float z-50">
|
||||||
<span className="text-sm text-yellow-800 font-medium">
|
<span className="text-sm text-st-amber-fg font-medium">
|
||||||
{pendingCount} report{pendingCount > 1 ? 's' : ''} saved offline
|
{pendingCount} report{pendingCount > 1 ? 's' : ''} saved offline
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={syncNow}
|
onClick={syncNow}
|
||||||
disabled={syncing || !navigator.onLine}
|
disabled={syncing || !navigator.onLine}
|
||||||
className="text-xs bg-yellow-600 text-white px-3 py-1.5 rounded font-medium
|
className="text-xs bg-accent text-white px-3 py-1.5 font-medium
|
||||||
hover:bg-yellow-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
hover:bg-accent-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||||
>
|
>
|
||||||
{syncing ? 'Syncing…' : 'Sync now'}
|
{syncing ? 'Syncing…' : 'Sync now'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import Link from 'next/link'
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
page: number
|
|
||||||
pageSize: number
|
|
||||||
total: number
|
|
||||||
href: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Pagination({ page, pageSize, total, href }: Props) {
|
|
||||||
const totalPages = Math.max(1, Math.ceil(total / pageSize))
|
|
||||||
if (totalPages <= 1) return null
|
|
||||||
|
|
||||||
const link = (p: number, label: string, disabled: boolean) =>
|
|
||||||
disabled ? (
|
|
||||||
<span className="px-3 py-1.5 text-sm text-gray-300">{label}</span>
|
|
||||||
) : (
|
|
||||||
<Link href={`${href}?page=${p}`} className="px-3 py-1.5 text-sm text-blue-600 hover:underline">
|
|
||||||
{label}
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<nav className="flex items-center justify-between mt-4" aria-label="Pagination">
|
|
||||||
{link(page - 1, '← Previous', page <= 1)}
|
|
||||||
<span className="text-sm text-gray-500">
|
|
||||||
Page {page} of {totalPages}
|
|
||||||
</span>
|
|
||||||
{link(page + 1, 'Next →', page >= totalPages)}
|
|
||||||
</nav>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -73,7 +73,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
value={(typeDetails[key] as string) ?? ''}
|
value={(typeDetails[key] as string) ?? ''}
|
||||||
onChange={e => setDetail(key, e.target.value)}
|
onChange={e => setDetail(key, e.target.value)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full border border-divider px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -82,7 +82,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
<label className="flex items-center gap-3 cursor-pointer">
|
<label className="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="w-4 h-4 text-blue-600"
|
className="w-4 h-4 text-accent-700"
|
||||||
checked={Boolean(typeDetails[key])}
|
checked={Boolean(typeDetails[key])}
|
||||||
onChange={e => setDetail(key, e.target.checked)}
|
onChange={e => setDetail(key, e.target.checked)}
|
||||||
/>
|
/>
|
||||||
@@ -205,22 +205,22 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
|
|
||||||
if (savedOffline) {
|
if (savedOffline) {
|
||||||
return (
|
return (
|
||||||
<div className="bg-green-50 border border-green-200 rounded-xl p-5 text-sm text-green-700">
|
<div className="bg-neutral-100 border border-divider p-5 text-sm text-ink">
|
||||||
{t.savedOffline}
|
{t.savedOffline}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit} className="space-y-5 bg-white rounded-xl shadow-sm p-5">
|
<form onSubmit={handleSubmit} className="space-y-5 bg-surface shadow-sm p-5">
|
||||||
{!isOnline && (
|
{!isOnline && (
|
||||||
<div className="bg-yellow-50 border border-yellow-200 rounded p-3 text-sm text-yellow-700">
|
<div className="bg-st-amber-bg rounded-md p-3 text-sm text-st-amber-fg">
|
||||||
{t.offlineBanner}
|
{t.offlineBanner}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="bg-red-50 border border-red-200 rounded p-3 text-sm text-red-700">
|
<div className="bg-red-50 border border-red-200 p-3 text-sm text-red-700">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -231,7 +231,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
required
|
required
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full border border-divider px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
value={form.incident_type}
|
value={form.incident_type}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
setForm(f => ({ ...f, incident_type: e.target.value as IncidentType, truck_id: '' }))
|
setForm(f => ({ ...f, incident_type: e.target.value as IncidentType, truck_id: '' }))
|
||||||
@@ -246,26 +246,26 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{form.incident_type === 'environmental' && (
|
{form.incident_type === 'environmental' && (
|
||||||
<div className="space-y-3 border border-gray-200 rounded-lg p-3">
|
<div className="space-y-3 border border-divider p-3">
|
||||||
{detailText('substance', tdLabels.substance, tdLabels.substancePlaceholder)}
|
{detailText('substance', tdLabels.substance, tdLabels.substancePlaceholder)}
|
||||||
{detailText('estimated_volume', tdLabels.estimatedVolume, tdLabels.estimatedVolumePlaceholder)}
|
{detailText('estimated_volume', tdLabels.estimatedVolume, tdLabels.estimatedVolumePlaceholder)}
|
||||||
{detailCheckbox('containment_deployed', tdLabels.containmentDeployed)}
|
{detailCheckbox('containment_deployed', tdLabels.containmentDeployed)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{form.incident_type === 'asset_damage' && (
|
{form.incident_type === 'asset_damage' && (
|
||||||
<div className="space-y-3 border border-gray-200 rounded-lg p-3">
|
<div className="space-y-3 border border-divider p-3">
|
||||||
{detailText('equipment_id', tdLabels.equipmentId, tdLabels.equipmentIdPlaceholder)}
|
{detailText('equipment_id', tdLabels.equipmentId, tdLabels.equipmentIdPlaceholder)}
|
||||||
{detailCheckbox('loto_applied', tdLabels.lotoApplied)}
|
{detailCheckbox('loto_applied', tdLabels.lotoApplied)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{form.incident_type === 'security' && (
|
{form.incident_type === 'security' && (
|
||||||
<div className="space-y-3 border border-gray-200 rounded-lg p-3">
|
<div className="space-y-3 border border-divider p-3">
|
||||||
{detailText('persons_involved', tdLabels.personsInvolved, tdLabels.personsInvolvedPlaceholder)}
|
{detailText('persons_involved', tdLabels.personsInvolved, tdLabels.personsInvolvedPlaceholder)}
|
||||||
{detailCheckbox('police_reported', tdLabels.policeReported)}
|
{detailCheckbox('police_reported', tdLabels.policeReported)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{form.incident_type === 'fire' && (
|
{form.incident_type === 'fire' && (
|
||||||
<div className="space-y-3 border border-gray-200 rounded-lg p-3">
|
<div className="space-y-3 border border-divider p-3">
|
||||||
{detailCheckbox('alarm_raised', tdLabels.alarmRaised)}
|
{detailCheckbox('alarm_raised', tdLabels.alarmRaised)}
|
||||||
{detailCheckbox('fire_brigade_called', tdLabels.fireBrigadeCalled)}
|
{detailCheckbox('fire_brigade_called', tdLabels.fireBrigadeCalled)}
|
||||||
</div>
|
</div>
|
||||||
@@ -278,7 +278,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
required
|
required
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full border border-divider px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
value={form.truck_id}
|
value={form.truck_id}
|
||||||
onChange={e => setForm(f => ({ ...f, truck_id: e.target.value }))}
|
onChange={e => setForm(f => ({ ...f, truck_id: e.target.value }))}
|
||||||
>
|
>
|
||||||
@@ -301,31 +301,31 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
minLength={10}
|
minLength={10}
|
||||||
rows={4}
|
rows={4}
|
||||||
placeholder={t.descriptionPlaceholder}
|
placeholder={t.descriptionPlaceholder}
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none"
|
className="w-full border border-divider px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-accent resize-none"
|
||||||
value={form.description}
|
value={form.description}
|
||||||
onChange={e => setForm(f => ({ ...f, description: e.target.value }))}
|
onChange={e => setForm(f => ({ ...f, description: e.target.value }))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{qualityCheck && !qualityCheck.passes && (
|
{qualityCheck && !qualityCheck.passes && (
|
||||||
<div className="rounded-lg bg-amber-50 border border-amber-200 p-3 space-y-2">
|
<div className="bg-st-amber-bg rounded-md p-3 space-y-2">
|
||||||
<p className="text-xs font-semibold text-amber-700 uppercase tracking-wide">
|
<p className="text-xs font-semibold text-st-amber-fg uppercase tracking-wide">
|
||||||
{t.qualityScoreLabel.replace('{score}', String(qualityCheck.score))}
|
{t.qualityScoreLabel.replace('{score}', String(qualityCheck.score))}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-amber-800">{qualityCheck.feedback}</p>
|
<p className="text-sm text-st-amber-fg">{qualityCheck.feedback}</p>
|
||||||
{qualityCheck.suggestions.length > 0 && (
|
{qualityCheck.suggestions.length > 0 && (
|
||||||
<ul className="list-disc list-inside space-y-1">
|
<ul className="list-disc list-inside space-y-1">
|
||||||
{qualityCheck.suggestions.map((s, i) => (
|
{qualityCheck.suggestions.map((s, i) => (
|
||||||
<li key={i} className="text-xs text-amber-700">{s}</li>
|
<li key={i} className="text-xs text-st-amber-fg">{s}</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
<label className="flex items-center gap-2 text-xs text-amber-700 cursor-pointer mt-1">
|
<label className="flex items-center gap-2 text-xs text-accent-700 cursor-pointer mt-1">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={overrideQuality}
|
checked={overrideQuality}
|
||||||
onChange={e => setOverrideQuality(e.target.checked)}
|
onChange={e => setOverrideQuality(e.target.checked)}
|
||||||
className="rounded border-amber-300 text-amber-600"
|
className="border-accent-300 text-accent-700"
|
||||||
/>
|
/>
|
||||||
{t.submitAnyway}
|
{t.submitAnyway}
|
||||||
</label>
|
</label>
|
||||||
@@ -336,7 +336,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
<label className="flex items-center gap-3 cursor-pointer">
|
<label className="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="w-4 h-4 text-blue-600"
|
className="w-4 h-4 text-accent-700"
|
||||||
checked={form.injury_involved}
|
checked={form.injury_involved}
|
||||||
onChange={e => setForm(f => ({ ...f, injury_involved: e.target.checked, medical_status: '' }))}
|
onChange={e => setForm(f => ({ ...f, injury_involved: e.target.checked, medical_status: '' }))}
|
||||||
/>
|
/>
|
||||||
@@ -350,7 +350,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
required={form.injury_involved}
|
required={form.injury_involved}
|
||||||
className="w-full border border-gray-300 rounded-lg px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
className="w-full border border-divider px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-accent"
|
||||||
value={form.medical_status}
|
value={form.medical_status}
|
||||||
onChange={e => setForm(f => ({ ...f, medical_status: e.target.value as MedicalStatus }))}
|
onChange={e => setForm(f => ({ ...f, medical_status: e.target.value as MedicalStatus }))}
|
||||||
>
|
>
|
||||||
@@ -365,7 +365,7 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
<label className="flex items-center gap-3 cursor-pointer">
|
<label className="flex items-center gap-3 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="w-4 h-4 text-blue-600"
|
className="w-4 h-4 text-accent-700"
|
||||||
checked={form.asset_involved}
|
checked={form.asset_involved}
|
||||||
onChange={e => setForm(f => ({ ...f, asset_involved: e.target.checked }))}
|
onChange={e => setForm(f => ({ ...f, asset_involved: e.target.checked }))}
|
||||||
/>
|
/>
|
||||||
@@ -383,8 +383,8 @@ export function ReportForm({ zoneToken, trucks, initialTruckId }: Props) {
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={submitting || !form.incident_type || (form.incident_type === 'transport' && !form.truck_id)}
|
disabled={submitting || !form.incident_type || (form.incident_type === 'transport' && !form.truck_id)}
|
||||||
className="w-full bg-blue-600 text-white py-3 rounded-lg font-medium text-sm
|
className="w-full bg-accent text-white py-3 font-medium text-sm
|
||||||
hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
hover:bg-accent-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||||
>
|
>
|
||||||
{submitting ? t.submitting : t.submitButton}
|
{submitting ? t.submitting : t.submitButton}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export function SimilarIncidentsPanel({ incidentId }: Props) {
|
|||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className="mt-6 bg-white rounded-xl shadow-sm p-5">
|
<div className="mt-6 bg-surface shadow-sm p-5">
|
||||||
<p className="text-sm text-gray-400">Loading similar incidents…</p>
|
<p className="text-sm text-gray-400">Loading similar incidents…</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -51,7 +51,7 @@ export function SimilarIncidentsPanel({ incidentId }: Props) {
|
|||||||
if (error || similar.length === 0) return null
|
if (error || similar.length === 0) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-6 bg-white rounded-xl shadow-sm p-5">
|
<div className="mt-6 bg-surface shadow-sm p-5">
|
||||||
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-3">
|
<h2 className="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-3">
|
||||||
Similar Past Incidents
|
Similar Past Incidents
|
||||||
</h2>
|
</h2>
|
||||||
@@ -60,7 +60,7 @@ export function SimilarIncidentsPanel({ incidentId }: Props) {
|
|||||||
<a
|
<a
|
||||||
key={inc.id}
|
key={inc.id}
|
||||||
href={`/hse/incidents/${inc.id}`}
|
href={`/hse/incidents/${inc.id}`}
|
||||||
className="block border border-gray-200 rounded-lg p-3 hover:border-blue-300 hover:bg-blue-50 transition-colors"
|
className="block border border-divider p-3 hover:border-accent hover:bg-neutral-100 transition-colors"
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between mb-1">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<span className="text-xs font-medium text-gray-500">
|
<span className="text-xs font-medium text-gray-500">
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
<form onSubmit={handleSubmit} className="space-y-6">
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Severity</label>
|
<label className="block text-sm font-medium text-gray-700 mb-2">Severity</label>
|
||||||
<div className="flex rounded-lg border border-gray-300 overflow-hidden divide-x divide-gray-300">
|
<div className="flex border border-divider overflow-hidden divide-x divide-divider">
|
||||||
{([1, 2, 3, 4, 5] as const).map(v => (
|
{([1, 2, 3, 4, 5] as const).map(v => (
|
||||||
<button
|
<button
|
||||||
key={v}
|
key={v}
|
||||||
@@ -103,8 +103,8 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
onClick={() => setSeverity(v)}
|
onClick={() => setSeverity(v)}
|
||||||
className={`flex-1 py-2 text-xs font-medium transition-colors ${
|
className={`flex-1 py-2 text-xs font-medium transition-colors ${
|
||||||
severity === v
|
severity === v
|
||||||
? 'bg-blue-600 text-white border-blue-600'
|
? 'bg-accent text-white border-accent'
|
||||||
: 'bg-white text-gray-700 hover:bg-gray-50'
|
: 'bg-surface text-gray-700 hover:bg-gray-50'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<span className="block font-bold">{v}</span>
|
<span className="block font-bold">{v}</span>
|
||||||
@@ -126,7 +126,7 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
<input
|
<input
|
||||||
type="checkbox" checked={value}
|
type="checkbox" checked={value}
|
||||||
onChange={e => set(e.target.checked)}
|
onChange={e => set(e.target.checked)}
|
||||||
className="rounded border-gray-300 text-blue-600"
|
className="border-divider text-accent-700"
|
||||||
/>
|
/>
|
||||||
{label}
|
{label}
|
||||||
</label>
|
</label>
|
||||||
@@ -134,7 +134,7 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
{dosh.reasons.length > 0 && (
|
{dosh.reasons.length > 0 && (
|
||||||
<div className="rounded-lg bg-red-50 border border-red-200 p-3 space-y-1">
|
<div className="bg-red-50 border border-red-200 p-3 space-y-1">
|
||||||
<p className="text-xs font-semibold text-red-700 uppercase tracking-wide">DOSH Reporting Required</p>
|
<p className="text-xs font-semibold text-red-700 uppercase tracking-wide">DOSH Reporting Required</p>
|
||||||
{dosh.reasons.map(r => (
|
{dosh.reasons.map(r => (
|
||||||
<p key={r} className="text-xs text-red-600">{r}</p>
|
<p key={r} className="text-xs text-red-600">{r}</p>
|
||||||
@@ -151,16 +151,16 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
value={triageNotes}
|
value={triageNotes}
|
||||||
onChange={e => setTriageNotes(e.target.value)}
|
onChange={e => setTriageNotes(e.target.value)}
|
||||||
rows={3}
|
rows={3}
|
||||||
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
className="w-full border border-divider px-3 py-2 text-sm focus:ring-2 focus:ring-accent focus:border-transparent"
|
||||||
placeholder="Initial assessment, immediate actions taken..."
|
placeholder="Initial assessment, immediate actions taken..."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{aiRationale && (
|
{aiRationale && (
|
||||||
<div className="rounded-lg bg-purple-50 border border-purple-200 p-3">
|
<div className="bg-accent-tint rounded-md p-3">
|
||||||
<p className="text-xs font-semibold text-purple-700 mb-1">AI Suggestion Rationale</p>
|
<p className="text-xs font-semibold text-accent-700 mb-1">AI Suggestion Rationale</p>
|
||||||
<p className="text-xs text-purple-600">{aiRationale}</p>
|
<p className="text-xs text-accent-700">{aiRationale}</p>
|
||||||
<p className="text-xs text-purple-400 mt-1">Fields pre-filled — review before submitting.</p>
|
<p className="text-xs text-accent-400 mt-1">Fields pre-filled — review before submitting.</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -171,14 +171,14 @@ export function TriageForm({ incidentId, currentSeverity }: Props) {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={getAiSuggestion}
|
onClick={getAiSuggestion}
|
||||||
disabled={aiLoading || saving}
|
disabled={aiLoading || saving}
|
||||||
className="flex-1 bg-purple-50 text-purple-700 border border-purple-300 rounded-lg py-2 text-sm font-semibold disabled:opacity-50 hover:bg-purple-100"
|
className="flex-1 bg-accent-100 text-accent-700 border border-accent-300 py-2 text-sm font-semibold disabled:opacity-50 hover:bg-accent-200"
|
||||||
>
|
>
|
||||||
{aiLoading ? 'Getting suggestion…' : 'Get AI Suggestion'}
|
{aiLoading ? 'Getting suggestion…' : 'Get AI Suggestion'}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
className="flex-1 bg-blue-600 text-white rounded-lg py-2 text-sm font-semibold disabled:opacity-50"
|
className="flex-1 bg-accent text-white py-2 text-sm font-semibold disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{saving ? 'Saving…' : 'Complete Triage'}
|
{saving ? 'Saving…' : 'Complete Triage'}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export function LanguageSwitcher() {
|
|||||||
value={current}
|
value={current}
|
||||||
onChange={e => handleChange(e.target.value)}
|
onChange={e => handleChange(e.target.value)}
|
||||||
aria-label="Select language"
|
aria-label="Select language"
|
||||||
className="text-xs border border-gray-300 rounded px-2 py-1 bg-white text-gray-700 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
className="text-xs border border-divider px-2 py-1 bg-surface text-gray-700 focus:outline-none focus:ring-1 focus:ring-accent"
|
||||||
>
|
>
|
||||||
{Object.entries(LOCALES).map(([code, label]) => (
|
{Object.entries(LOCALES).map(([code, label]) => (
|
||||||
<option key={code} value={code}>{label}</option>
|
<option key={code} value={code}>{label}</option>
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect, useRef } from 'react'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { usePathname, useRouter } from 'next/navigation'
|
||||||
|
import { LogOut, Search, ShieldCheck, User } from 'lucide-react'
|
||||||
|
import { NotificationBell } from '@/components/notifications/bell'
|
||||||
|
import { Avatar } from '@/components/ui/avatar'
|
||||||
|
import { cx } from '@/components/ui/cx'
|
||||||
|
import { MobileShell } from './mobile-shell'
|
||||||
|
import { isActivePath, navItemsFor, searchHrefFor } from './nav-items'
|
||||||
|
|
||||||
|
const ITEM = 'flex items-center gap-2.5 h-8 px-2.5 rounded-md text-[13px] w-full text-left'
|
||||||
|
const ITEM_ACTIVE = 'bg-surface text-ink font-semibold shadow-chip'
|
||||||
|
const ITEM_IDLE = 'text-ink-3 hover:bg-rule-2'
|
||||||
|
|
||||||
|
export function AppShell({
|
||||||
|
role,
|
||||||
|
userName,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
role: string
|
||||||
|
userName: string
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const router = useRouter()
|
||||||
|
const items = navItemsFor(role)
|
||||||
|
const searchHref = searchHrefFor(role)
|
||||||
|
const searchRef = useRef<HTMLInputElement>(null)
|
||||||
|
const displayName = userName || 'User'
|
||||||
|
const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
||||||
|
e.preventDefault()
|
||||||
|
searchRef.current?.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener('keydown', onKey)
|
||||||
|
return () => document.removeEventListener('keydown', onKey)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const logout = async () => {
|
||||||
|
await fetch('/api/auth/logout', { method: 'POST' })
|
||||||
|
router.push('/login')
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountActive = pathname === '/account'
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-ground">
|
||||||
|
<header className="hidden md:flex fixed top-0 left-0 right-0 z-40 h-14 items-center justify-between gap-4 pl-5 pr-4 bg-topbar">
|
||||||
|
<div className="flex items-center gap-2.5 w-56">
|
||||||
|
<span className="inline-grid place-items-center w-7 h-7 rounded-md bg-accent text-white">
|
||||||
|
<ShieldCheck size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</span>
|
||||||
|
<span className="text-[15px] font-[650] text-white tracking-tight">IMS</span>
|
||||||
|
<span className="text-[13px] text-neutral-400">Setia HSE</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{searchHref ? (
|
||||||
|
<form action={searchHref} method="get" className="flex-1 max-w-[520px]">
|
||||||
|
<label className="flex items-center gap-2 h-[34px] px-2.5 rounded-[10px] bg-ink-2 shadow-[inset_0_0_0_1px_var(--color-ink-3)] text-neutral-400 text-[13px]">
|
||||||
|
<Search size={16} strokeWidth={2} aria-hidden />
|
||||||
|
<input
|
||||||
|
ref={searchRef}
|
||||||
|
name="q"
|
||||||
|
type="search"
|
||||||
|
placeholder="Search incidents"
|
||||||
|
aria-label="Search incidents"
|
||||||
|
className="flex-1 bg-transparent text-white placeholder:text-neutral-400 outline-none"
|
||||||
|
/>
|
||||||
|
<kbd className="font-mono text-[11px] text-neutral-400">⌘K</kbd>
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<div className="flex-1" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 w-56 justify-end">
|
||||||
|
<NotificationBell />
|
||||||
|
<div className="flex items-center gap-2 py-1 pl-1 pr-2.5 rounded-md bg-ink-2">
|
||||||
|
<Avatar name={displayName} />
|
||||||
|
<span className="text-[13px] text-rule-2 max-w-32 truncate">{displayName}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<aside className="hidden md:flex fixed top-14 left-0 bottom-0 z-30 w-60 flex-col gap-0.5 p-3 bg-rule border-r border-rule-2">
|
||||||
|
{items.map(item => {
|
||||||
|
const active = isActivePath(item.href, pathname)
|
||||||
|
const Icon = item.icon
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
aria-current={active ? 'page' : undefined}
|
||||||
|
className={cx(ITEM, active ? ITEM_ACTIVE : ITEM_IDLE)}
|
||||||
|
>
|
||||||
|
<Icon size={16} strokeWidth={2} className={active ? 'text-accent' : 'text-ink-3'} aria-hidden />
|
||||||
|
<span className="flex-1">{item.label}</span>
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<div className="flex-1" />
|
||||||
|
<div className="flex flex-col gap-0.5 pt-2.5 border-t border-rule-2">
|
||||||
|
<div className="px-2.5 pb-1">
|
||||||
|
<p className="text-[13px] font-semibold truncate">{displayName}</p>
|
||||||
|
<p className="text-xs text-muted truncate">{roleLabel}</p>
|
||||||
|
</div>
|
||||||
|
<Link
|
||||||
|
href="/account"
|
||||||
|
aria-current={accountActive ? 'page' : undefined}
|
||||||
|
className={cx(ITEM, accountActive ? ITEM_ACTIVE : ITEM_IDLE)}
|
||||||
|
>
|
||||||
|
<User size={16} strokeWidth={2} className={accountActive ? 'text-accent' : 'text-ink-3'} aria-hidden />
|
||||||
|
Account
|
||||||
|
</Link>
|
||||||
|
<button type="button" onClick={logout} className={cx(ITEM, ITEM_IDLE, 'cursor-pointer')}>
|
||||||
|
<LogOut size={16} strokeWidth={2} className="text-ink-3" aria-hidden />
|
||||||
|
Log out
|
||||||
|
</button>
|
||||||
|
<p className="px-2.5 pt-2 text-xs text-faint">v1.2.2</p>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<main className="md:pl-60 md:pt-14 pb-16 md:pb-0">{children}</main>
|
||||||
|
|
||||||
|
<MobileShell items={items} pathname={pathname} onLogout={logout} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { LogOut } from 'lucide-react'
|
||||||
|
import { isActivePath, type NavItem } from './nav-items'
|
||||||
|
import { cx } from '@/components/ui/cx'
|
||||||
|
|
||||||
|
export function MobileShell({
|
||||||
|
items,
|
||||||
|
pathname,
|
||||||
|
onLogout,
|
||||||
|
}: {
|
||||||
|
items: NavItem[]
|
||||||
|
pathname: string
|
||||||
|
onLogout: () => void
|
||||||
|
}) {
|
||||||
|
const tabs = items.slice(0, 4)
|
||||||
|
return (
|
||||||
|
<nav
|
||||||
|
aria-label="Mobile"
|
||||||
|
className="md:hidden fixed bottom-0 left-0 right-0 z-40 flex bg-surface border-t border-rule pb-[env(safe-area-inset-bottom)]"
|
||||||
|
>
|
||||||
|
{tabs.map(item => {
|
||||||
|
const active = isActivePath(item.href, pathname)
|
||||||
|
const Icon = item.icon
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={item.href}
|
||||||
|
href={item.href}
|
||||||
|
aria-current={active ? 'page' : undefined}
|
||||||
|
className={cx(
|
||||||
|
'flex-1 flex flex-col items-center gap-1 pt-2 pb-1.5 text-[10.5px] font-medium',
|
||||||
|
active ? 'text-accent' : 'text-faint',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon size={22} strokeWidth={1.8} aria-hidden />
|
||||||
|
<span className="leading-none">{item.label}</span>
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{items.length <= 4 && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onLogout}
|
||||||
|
className="flex-1 flex flex-col items-center gap-1 pt-2 pb-1.5 text-[10.5px] font-medium text-faint cursor-pointer"
|
||||||
|
>
|
||||||
|
<LogOut size={22} strokeWidth={1.8} aria-hidden />
|
||||||
|
<span className="leading-none">Log out</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</nav>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
AlignLeft,
|
||||||
|
CircleCheck,
|
||||||
|
ClipboardList,
|
||||||
|
LayoutDashboard,
|
||||||
|
Plus,
|
||||||
|
Settings,
|
||||||
|
Users,
|
||||||
|
type LucideIcon,
|
||||||
|
} from 'lucide-react'
|
||||||
|
|
||||||
|
export interface NavItem {
|
||||||
|
label: string
|
||||||
|
href: string
|
||||||
|
icon: LucideIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
const NAV_ITEMS: Record<string, NavItem[]> = {
|
||||||
|
reporter: [
|
||||||
|
{ label: 'My Reports', href: '/reporter', icon: ClipboardList },
|
||||||
|
{ label: 'New Incident', href: '/report', icon: Plus },
|
||||||
|
],
|
||||||
|
supervisor: [
|
||||||
|
{ label: 'Overview', href: '/supervisor', icon: AlignLeft },
|
||||||
|
{ label: 'Incidents', href: '/supervisor/incidents', icon: ClipboardList },
|
||||||
|
],
|
||||||
|
hse: [
|
||||||
|
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
|
||||||
|
{ label: 'Incidents', href: '/hse/incidents', icon: ClipboardList },
|
||||||
|
{ label: 'CAPA', href: '/hse/capa', icon: CircleCheck },
|
||||||
|
{ label: 'Settings', href: '/hse/settings', icon: Settings },
|
||||||
|
],
|
||||||
|
management: [{ label: 'Dashboard', href: '/management', icon: LayoutDashboard }],
|
||||||
|
capa_owner: [{ label: 'My CAPAs', href: '/capa-owner', icon: CircleCheck }],
|
||||||
|
admin: [
|
||||||
|
{ label: 'Admin', href: '/admin', icon: Users },
|
||||||
|
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
|
||||||
|
{ label: 'Incidents', href: '/hse/incidents', icon: ClipboardList },
|
||||||
|
{ label: 'CAPA', href: '/hse/capa', icon: CircleCheck },
|
||||||
|
{ label: 'Management', href: '/management', icon: AlignLeft },
|
||||||
|
{ label: 'Settings', href: '/hse/settings', icon: Settings },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
||||||
|
|
||||||
|
export function navItemsFor(role: string): NavItem[] {
|
||||||
|
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isActivePath(href: string, pathname: string): boolean {
|
||||||
|
return EXACT_ROOTS.includes(href) ? pathname === href : pathname.startsWith(href)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function searchHrefFor(role: string): string | null {
|
||||||
|
if (role === 'hse' || role === 'admin') return '/hse/incidents'
|
||||||
|
if (role === 'supervisor') return '/supervisor/incidents'
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,234 +0,0 @@
|
|||||||
'use client'
|
|
||||||
|
|
||||||
import Link from 'next/link'
|
|
||||||
import { usePathname, useRouter } from 'next/navigation'
|
|
||||||
import { NotificationBell } from '@/components/notifications/bell'
|
|
||||||
|
|
||||||
interface NavItem {
|
|
||||||
label: string
|
|
||||||
href: string
|
|
||||||
icon: React.ReactNode
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SidebarProps {
|
|
||||||
role: string
|
|
||||||
userName: string
|
|
||||||
userEmail: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const IconGrid = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h7" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconList = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconCheck = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconChart = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconSettings = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconUsers = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconPlus = () => (
|
|
||||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconLogout = () => (
|
|
||||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
const IconUser = () => (
|
|
||||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
|
||||||
</svg>
|
|
||||||
)
|
|
||||||
|
|
||||||
const NAV_ITEMS: Record<string, NavItem[]> = {
|
|
||||||
reporter: [
|
|
||||||
{ label: 'My Reports', href: '/reporter', icon: <IconList /> },
|
|
||||||
{ label: 'New Incident', href: '/report', icon: <IconPlus /> },
|
|
||||||
],
|
|
||||||
supervisor: [
|
|
||||||
{ label: 'Overview', href: '/supervisor', icon: <IconGrid /> },
|
|
||||||
{ label: 'Incidents', href: '/supervisor/incidents', icon: <IconList /> },
|
|
||||||
],
|
|
||||||
hse: [
|
|
||||||
{ label: 'Dashboard', href: '/hse/dashboard', icon: <IconChart /> },
|
|
||||||
{ label: 'Incidents', href: '/hse/incidents', icon: <IconList /> },
|
|
||||||
{ label: 'CAPA', href: '/hse/capa', icon: <IconCheck /> },
|
|
||||||
{ label: 'Settings', href: '/hse/settings', icon: <IconSettings /> },
|
|
||||||
],
|
|
||||||
management: [
|
|
||||||
{ label: 'Dashboard', href: '/management', icon: <IconChart /> },
|
|
||||||
],
|
|
||||||
capa_owner: [
|
|
||||||
{ label: 'My CAPAs', href: '/capa-owner', icon: <IconCheck /> },
|
|
||||||
],
|
|
||||||
admin: [
|
|
||||||
{ label: 'Admin', href: '/admin', icon: <IconUsers /> },
|
|
||||||
{ label: 'Dashboard', href: '/hse/dashboard', icon: <IconChart /> },
|
|
||||||
{ label: 'Incidents', href: '/hse/incidents', icon: <IconList /> },
|
|
||||||
{ label: 'CAPA', href: '/hse/capa', icon: <IconCheck /> },
|
|
||||||
{ label: 'Management', href: '/management', icon: <IconGrid /> },
|
|
||||||
{ label: 'Settings', href: '/hse/settings', icon: <IconSettings /> },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
function initials(name: string): string {
|
|
||||||
return name
|
|
||||||
.split(' ')
|
|
||||||
.map(w => w[0] ?? '')
|
|
||||||
.join('')
|
|
||||||
.toUpperCase()
|
|
||||||
.slice(0, 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
function useNavItems(role: string): NavItem[] {
|
|
||||||
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
|
|
||||||
}
|
|
||||||
|
|
||||||
function NavLink({ item, pathname }: { item: NavItem; pathname: string }) {
|
|
||||||
// Exact match for root-level single-page roles, prefix match otherwise
|
|
||||||
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
||||||
const isActive = exactRoots.includes(item.href)
|
|
||||||
? pathname === item.href
|
|
||||||
: pathname.startsWith(item.href)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Link
|
|
||||||
href={item.href}
|
|
||||||
className={`flex items-center gap-3 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${
|
|
||||||
isActive
|
|
||||||
? 'bg-blue-50 text-blue-700'
|
|
||||||
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span className={isActive ? 'text-blue-600' : 'text-gray-400'}>{item.icon}</span>
|
|
||||||
{item.label}
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Sidebar({ role, userName, userEmail }: SidebarProps) {
|
|
||||||
const pathname = usePathname()
|
|
||||||
const router = useRouter()
|
|
||||||
const items = useNavItems(role)
|
|
||||||
const mobileItems = items.slice(0, 4)
|
|
||||||
|
|
||||||
const logout = async () => {
|
|
||||||
await fetch('/api/auth/logout', { method: 'POST' })
|
|
||||||
router.push('/login')
|
|
||||||
router.refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
const displayName = userName || userEmail || 'User'
|
|
||||||
const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{/* Desktop sidebar */}
|
|
||||||
<aside className="hidden sm:flex fixed left-0 top-0 h-full w-60 bg-white border-r border-gray-200 flex-col z-40">
|
|
||||||
{/* Header */}
|
|
||||||
<div className="flex items-center justify-between px-4 py-4 border-b border-gray-100">
|
|
||||||
<span className="text-base font-bold text-gray-900 tracking-tight">IMS</span>
|
|
||||||
<NotificationBell />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Nav */}
|
|
||||||
<nav className="flex-1 overflow-y-auto px-3 py-3 space-y-1">
|
|
||||||
{items.map(item => (
|
|
||||||
<NavLink key={item.href} item={item} pathname={pathname} />
|
|
||||||
))}
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
{/* User + logout */}
|
|
||||||
<div className="border-t border-gray-100 px-3 py-3">
|
|
||||||
<div className="flex items-center gap-2 px-2 py-2 mb-1">
|
|
||||||
<div className="w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white text-xs font-bold flex-shrink-0">
|
|
||||||
{initials(displayName)}
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0">
|
|
||||||
<p className="text-sm font-medium text-gray-900 truncate">{displayName}</p>
|
|
||||||
<p className="text-xs text-gray-500 truncate">{roleLabel}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Link
|
|
||||||
href="/account"
|
|
||||||
className={`flex items-center gap-2 w-full px-3 py-2 text-sm rounded-lg transition-colors ${
|
|
||||||
pathname === '/account'
|
|
||||||
? 'bg-blue-50 text-blue-700'
|
|
||||||
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span className={pathname === '/account' ? 'text-blue-600' : 'text-gray-400'}>
|
|
||||||
<IconUser />
|
|
||||||
</span>
|
|
||||||
Account
|
|
||||||
</Link>
|
|
||||||
<button
|
|
||||||
onClick={logout}
|
|
||||||
className="flex items-center gap-2 w-full px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900 rounded-lg transition-colors"
|
|
||||||
>
|
|
||||||
<IconLogout />
|
|
||||||
Logout
|
|
||||||
</button>
|
|
||||||
<div className="mt-3 pt-3 border-t border-gray-100 px-2 text-center">
|
|
||||||
<p className="text-xs text-gray-400">v1.2.2</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
{/* Mobile bottom tab bar */}
|
|
||||||
<nav className="sm:hidden fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 flex z-40 safe-area-pb">
|
|
||||||
{mobileItems.map(item => {
|
|
||||||
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
||||||
const isActive = exactRoots.includes(item.href)
|
|
||||||
? pathname === item.href
|
|
||||||
: pathname.startsWith(item.href)
|
|
||||||
return (
|
|
||||||
<Link
|
|
||||||
key={item.href}
|
|
||||||
href={item.href}
|
|
||||||
className={`flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium transition-colors ${
|
|
||||||
isActive ? 'text-blue-600' : 'text-gray-400'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{item.icon}
|
|
||||||
<span className="leading-none">{item.label}</span>
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
{/* Mobile logout in "More" slot if room */}
|
|
||||||
{items.length <= 4 && (
|
|
||||||
<button
|
|
||||||
onClick={logout}
|
|
||||||
className="flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium text-gray-400"
|
|
||||||
>
|
|
||||||
<IconLogout />
|
|
||||||
<span className="leading-none">Logout</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</nav>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { Bell } from 'lucide-react'
|
||||||
|
import { Drawer } from '@/components/ui/drawer'
|
||||||
|
import { cx } from '@/components/ui/cx'
|
||||||
|
|
||||||
type Notification = {
|
type Notification = {
|
||||||
id: string
|
id: string
|
||||||
@@ -13,11 +16,15 @@ type Notification = {
|
|||||||
|
|
||||||
const POLL_MS = 60_000
|
const POLL_MS = 60_000
|
||||||
|
|
||||||
|
function isToday(iso: string): boolean {
|
||||||
|
return new Date(iso).toDateString() === new Date().toDateString()
|
||||||
|
}
|
||||||
|
|
||||||
export function NotificationBell() {
|
export function NotificationBell() {
|
||||||
const [notifications, setNotifications] = useState<Notification[]>([])
|
const [notifications, setNotifications] = useState<Notification[]>([])
|
||||||
const [unread, setUnread] = useState(0)
|
const [unread, setUnread] = useState(0)
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const panelRef = useRef<HTMLDivElement>(null)
|
const [tab, setTab] = useState<'all' | 'unread'>('all')
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
fetch('/api/notifications')
|
fetch('/api/notifications')
|
||||||
@@ -35,15 +42,6 @@ export function NotificationBell() {
|
|||||||
return () => clearInterval(id)
|
return () => clearInterval(id)
|
||||||
}, [load])
|
}, [load])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) return
|
|
||||||
const onClick = (e: MouseEvent) => {
|
|
||||||
if (panelRef.current && !panelRef.current.contains(e.target as Node)) setOpen(false)
|
|
||||||
}
|
|
||||||
document.addEventListener('mousedown', onClick)
|
|
||||||
return () => document.removeEventListener('mousedown', onClick)
|
|
||||||
}, [open])
|
|
||||||
|
|
||||||
const markAllRead = () => {
|
const markAllRead = () => {
|
||||||
fetch('/api/notifications', {
|
fetch('/api/notifications', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -57,62 +55,94 @@ export function NotificationBell() {
|
|||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shown = tab === 'unread' ? notifications.filter(n => !n.read_at) : notifications
|
||||||
|
const groups: Array<{ label: string; items: Notification[] }> = [
|
||||||
|
{ label: 'Today', items: shown.filter(n => isToday(n.sent_at)) },
|
||||||
|
{ label: 'Earlier', items: shown.filter(n => !isToday(n.sent_at)) },
|
||||||
|
].filter(g => g.items.length > 0)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={panelRef} className="fixed top-3 right-3 z-50">
|
<>
|
||||||
<button
|
<button
|
||||||
onClick={() => setOpen(o => !o)}
|
type="button"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
aria-label={`Notifications${unread > 0 ? ` (${unread} unread)` : ''}`}
|
aria-label={`Notifications${unread > 0 ? ` (${unread} unread)` : ''}`}
|
||||||
className="relative bg-white rounded-full shadow-sm border border-gray-200 w-10 h-10 flex items-center justify-center hover:shadow-md transition-shadow"
|
className="relative inline-grid place-items-center w-8 h-8 rounded-md text-neutral-300 hover:bg-ink-2 cursor-pointer"
|
||||||
>
|
>
|
||||||
<span className="text-lg" aria-hidden>🔔</span>
|
<Bell size={16} strokeWidth={2} aria-hidden />
|
||||||
{unread > 0 && (
|
{unread > 0 && (
|
||||||
<span className="absolute -top-1 -right-1 bg-red-600 text-white text-[10px] font-bold rounded-full min-w-[18px] h-[18px] px-1 flex items-center justify-center">
|
<span className="absolute -top-0.5 -right-0.5 min-w-[16px] h-4 px-1 rounded-full bg-accent text-white text-[10px] font-semibold grid place-items-center">
|
||||||
{unread > 99 ? '99+' : unread}
|
{unread > 99 ? '99+' : unread}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{open && (
|
<Drawer
|
||||||
<div className="absolute right-0 mt-2 w-80 max-h-96 overflow-y-auto bg-white rounded-xl shadow-lg border border-gray-200">
|
open={open}
|
||||||
<div className="flex items-center justify-between px-4 py-2 border-b border-gray-100">
|
onClose={() => setOpen(false)}
|
||||||
<span className="text-sm font-semibold text-gray-700">Notifications</span>
|
title="Notifications"
|
||||||
{unread > 0 && (
|
actions={
|
||||||
<button onClick={markAllRead} className="text-xs text-blue-600 hover:underline">
|
unread > 0 ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={markAllRead}
|
||||||
|
className="px-2 text-[12.5px] font-[550] text-accent hover:underline cursor-pointer"
|
||||||
|
>
|
||||||
Mark all read
|
Mark all read
|
||||||
</button>
|
</button>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="flex gap-0.5 px-3 pb-2 border-b border-rule">
|
||||||
|
{(['all', 'unread'] as const).map(t => (
|
||||||
|
<button
|
||||||
|
key={t}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setTab(t)}
|
||||||
|
className={cx(
|
||||||
|
'inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-[13px] cursor-pointer',
|
||||||
|
tab === t ? 'bg-rule-2 font-semibold' : 'font-medium text-ink-3 hover:bg-surface-2',
|
||||||
)}
|
)}
|
||||||
|
>
|
||||||
|
{t === 'all' ? 'All' : 'Unread'}
|
||||||
|
<span className="text-xs font-medium text-faint">{t === 'all' ? notifications.length : unread}</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
{notifications.length === 0 ? (
|
|
||||||
<p className="px-4 py-6 text-sm text-gray-400 text-center">No notifications</p>
|
{groups.length === 0 ? (
|
||||||
|
<p className="px-4 py-10 text-sm text-faint text-center">No notifications</p>
|
||||||
) : (
|
) : (
|
||||||
|
groups.map(g => (
|
||||||
|
<section key={g.label}>
|
||||||
|
<h3 className="px-4 pt-3 pb-1 text-[11.5px] font-semibold tracking-wide uppercase text-faint">{g.label}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{notifications.map(n => {
|
{g.items.map(n => {
|
||||||
const inner = (
|
const body = (
|
||||||
<>
|
<>
|
||||||
<p className={`text-sm ${n.read_at ? 'text-gray-500' : 'text-gray-900 font-medium'}`}>
|
<p className={cx('text-[13px]', n.read_at ? 'text-muted' : 'text-ink font-medium')}>
|
||||||
{n.title ?? 'Notification'}
|
{n.title ?? 'Notification'}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-gray-400 mt-0.5">
|
<p className="text-xs text-faint mt-0.5">{new Date(n.sent_at).toLocaleString()}</p>
|
||||||
{new Date(n.sent_at).toLocaleString()}
|
|
||||||
</p>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<li key={n.id} className="border-b border-gray-50 last:border-0">
|
<li key={n.id} className={cx('border-b border-rule', !n.read_at && 'bg-accent-tint')}>
|
||||||
{n.link ? (
|
{n.link ? (
|
||||||
<Link href={n.link} className="block px-4 py-3 hover:bg-gray-50" onClick={() => setOpen(false)}>
|
<Link href={n.link} className="block px-4 py-3" onClick={() => setOpen(false)}>
|
||||||
{inner}
|
{body}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<div className="px-4 py-3">{inner}</div>
|
<div className="px-4 py-3">{body}</div>
|
||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
|
</section>
|
||||||
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</Drawer>
|
||||||
)}
|
</>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ export function ApiKeyForm({ settings }: Props) {
|
|||||||
{Object.keys(KEY_LABELS).map(key => {
|
{Object.keys(KEY_LABELS).map(key => {
|
||||||
const status = settings[key]
|
const status = settings[key]
|
||||||
return (
|
return (
|
||||||
<div key={key} className="bg-white rounded-xl shadow-sm p-5">
|
<div key={key} className="bg-surface shadow-sm p-5">
|
||||||
<div className="flex items-center justify-between mb-1">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<label className="text-sm font-semibold text-gray-800">{KEY_LABELS[key]}</label>
|
<label className="text-sm font-semibold text-gray-800">{KEY_LABELS[key]}</label>
|
||||||
<span className={`text-xs font-medium px-2 py-0.5 rounded-full ${
|
<span className={`text-xs font-medium px-2 py-0.5 ${
|
||||||
status?.set
|
status?.set
|
||||||
? 'bg-green-100 text-green-700'
|
? 'bg-st-green-bg text-st-green-fg'
|
||||||
: 'bg-yellow-100 text-yellow-700'
|
: 'bg-st-amber-bg text-st-amber-fg'
|
||||||
}`}>
|
}`}>
|
||||||
{status?.set ? 'Configured' : 'Not set'}
|
{status?.set ? 'Configured' : 'Not set'}
|
||||||
</span>
|
</span>
|
||||||
@@ -66,18 +66,18 @@ export function ApiKeyForm({ settings }: Props) {
|
|||||||
value={values[key]}
|
value={values[key]}
|
||||||
onChange={e => setValues(v => ({ ...v, [key]: e.target.value }))}
|
onChange={e => setValues(v => ({ ...v, [key]: e.target.value }))}
|
||||||
placeholder={status?.set ? 'Enter new key to replace…' : 'Enter API key…'}
|
placeholder={status?.set ? 'Enter new key to replace…' : 'Enter API key…'}
|
||||||
className="flex-1 border border-gray-300 rounded-lg px-3 py-2 text-sm text-gray-900 placeholder-gray-500 focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono"
|
className="flex-1 border border-divider px-3 py-2 text-sm text-gray-900 placeholder-gray-500 focus:ring-2 focus:ring-accent focus:border-transparent font-mono"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => save(key)}
|
onClick={() => save(key)}
|
||||||
disabled={saving[key] || !values[key]}
|
disabled={saving[key] || !values[key]}
|
||||||
className="bg-blue-600 text-white rounded-lg px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:bg-blue-700"
|
className="bg-accent text-white px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:bg-accent-600"
|
||||||
>
|
>
|
||||||
{saving[key] ? 'Saving…' : 'Save'}
|
{saving[key] ? 'Saving…' : 'Save'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{results[key] === 'ok' && (
|
{results[key] === 'ok' && (
|
||||||
<p className="text-xs text-green-600 mt-2">Saved. Reload the page to confirm.</p>
|
<p className="text-xs text-ink mt-2">Saved. Reload the page to confirm.</p>
|
||||||
)}
|
)}
|
||||||
{results[key] === 'error' && (
|
{results[key] === 'error' && (
|
||||||
<p className="text-xs text-red-600 mt-2">Save failed. Check your permissions.</p>
|
<p className="text-xs text-red-600 mt-2">Save failed. Check your permissions.</p>
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
export function initials(name: string): string {
|
||||||
|
return name
|
||||||
|
.split(' ')
|
||||||
|
.map(w => w[0] ?? '')
|
||||||
|
.join('')
|
||||||
|
.toUpperCase()
|
||||||
|
.slice(0, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Avatar({ name }: { name: string }) {
|
||||||
|
return (
|
||||||
|
<span className="inline-grid place-items-center w-6 h-6 rounded-[6px] bg-accent-200 text-accent-700 text-[11px] font-[650]">
|
||||||
|
{initials(name)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import type { ButtonHTMLAttributes } from 'react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
type Variant = 'primary' | 'secondary' | 'icon'
|
||||||
|
|
||||||
|
const BASE =
|
||||||
|
'inline-flex items-center justify-center gap-1.5 whitespace-nowrap transition-colors cursor-pointer ' +
|
||||||
|
'disabled:opacity-45 disabled:cursor-not-allowed'
|
||||||
|
|
||||||
|
const VARIANTS: Record<Variant, string> = {
|
||||||
|
primary: 'h-8 px-3 rounded-md bg-ink-2 text-white text-[13px] font-semibold shadow-primary hover:bg-ink active:bg-black',
|
||||||
|
secondary: 'h-8 px-3 rounded-md bg-surface text-ink text-[13px] font-medium shadow-secondary hover:bg-surface-2 active:bg-rule',
|
||||||
|
icon: 'w-7 h-7 rounded-md text-ink-3 hover:bg-rule',
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
|
||||||
|
variant?: Variant
|
||||||
|
block?: boolean
|
||||||
|
mobile?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buttonClass(
|
||||||
|
variant: Variant = 'primary',
|
||||||
|
opts: { block?: boolean; mobile?: boolean } = {},
|
||||||
|
): string {
|
||||||
|
return cx(
|
||||||
|
BASE,
|
||||||
|
VARIANTS[variant],
|
||||||
|
opts.mobile && variant !== 'icon' && 'h-12 rounded-xl text-sm',
|
||||||
|
opts.block && 'w-full',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Button({ variant = 'primary', block = false, mobile = false, className, type = 'button', ...rest }: Props) {
|
||||||
|
return <button type={type} className={cx(buttonClass(variant, { block, mobile }), className)} {...rest} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { ReactNode } from 'react'
|
||||||
|
|
||||||
|
export function Card({
|
||||||
|
kicker,
|
||||||
|
title,
|
||||||
|
meta,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
kicker?: ReactNode
|
||||||
|
title?: ReactNode
|
||||||
|
meta?: ReactNode
|
||||||
|
children?: ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-2 p-4 bg-surface rounded-xl shadow-card">
|
||||||
|
{kicker && <span className="text-[11px] font-semibold tracking-wide uppercase text-muted">{kicker}</span>}
|
||||||
|
{title && <h3 className="text-base font-[650]">{title}</h3>}
|
||||||
|
{children && <div className="flex-1 text-[13px] text-ink-3">{children}</div>}
|
||||||
|
{meta && <div className="flex items-center gap-1.5 text-xs text-faint">{meta}</div>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { Check, Minus } from 'lucide-react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export function Checkbox({
|
||||||
|
checked,
|
||||||
|
indeterminate = false,
|
||||||
|
onChange,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
checked: boolean
|
||||||
|
indeterminate?: boolean
|
||||||
|
onChange: (next: boolean) => void
|
||||||
|
label: string
|
||||||
|
}) {
|
||||||
|
const on = checked || indeterminate
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="checkbox"
|
||||||
|
aria-checked={indeterminate ? 'mixed' : checked}
|
||||||
|
aria-label={label}
|
||||||
|
onClick={e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
onChange(!checked)
|
||||||
|
}}
|
||||||
|
className={cx(
|
||||||
|
'inline-grid place-items-center w-4 h-4 rounded-[5px] cursor-pointer',
|
||||||
|
on ? 'bg-accent text-white' : 'bg-surface shadow-[inset_0_0_0_1.5px_var(--color-faint)]',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{indeterminate ? <Minus size={12} strokeWidth={3} aria-hidden /> : checked ? <Check size={12} strokeWidth={3} aria-hidden /> : null}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export const cx = (...parts: Array<string | false | null | undefined>): string =>
|
||||||
|
parts.filter(Boolean).join(' ')
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect } from 'react'
|
||||||
|
import { X } from 'lucide-react'
|
||||||
|
import { Button } from './button'
|
||||||
|
|
||||||
|
export function Drawer({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
title,
|
||||||
|
actions,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
open: boolean
|
||||||
|
onClose: () => void
|
||||||
|
title: string
|
||||||
|
actions?: React.ReactNode
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() }
|
||||||
|
document.addEventListener('keydown', onKey)
|
||||||
|
return () => document.removeEventListener('keydown', onKey)
|
||||||
|
}, [open, onClose])
|
||||||
|
|
||||||
|
if (!open) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50">
|
||||||
|
<div className="absolute inset-0 bg-black/30" onClick={onClose} aria-hidden />
|
||||||
|
<aside
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label={title}
|
||||||
|
className="absolute top-2 right-2 bottom-2 w-[420px] max-w-[calc(100vw-16px)] flex flex-col overflow-hidden rounded-2xl bg-surface shadow-drawer"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between px-4 pt-3.5 pb-2.5">
|
||||||
|
<h2 className="text-base font-[650]">{title}</h2>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
{actions}
|
||||||
|
<Button variant="icon" aria-label="Close" onClick={onClose}>
|
||||||
|
<X size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 overflow-y-auto">{children}</div>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import type { InputHTMLAttributes, ReactNode, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export const INPUT_CLASS =
|
||||||
|
'w-full h-9 px-3 rounded-md bg-surface text-[13px] text-ink caret-accent shadow-input ' +
|
||||||
|
'placeholder:text-faint disabled:opacity-45 disabled:cursor-not-allowed'
|
||||||
|
|
||||||
|
export function Field({ label, htmlFor, children }: { label: string; htmlFor: string; children: ReactNode }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<label htmlFor={htmlFor} className="block text-xs text-muted mb-[5px]">
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Input({ className, ...rest }: InputHTMLAttributes<HTMLInputElement>) {
|
||||||
|
return <input className={cx(INPUT_CLASS, className)} {...rest} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Textarea({ className, ...rest }: TextareaHTMLAttributes<HTMLTextAreaElement>) {
|
||||||
|
return <textarea className={cx(INPUT_CLASS, 'h-auto min-h-[90px] py-2 resize-y', className)} {...rest} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Select({ className, ...rest }: SelectHTMLAttributes<HTMLSelectElement>) {
|
||||||
|
return <select className={cx(INPUT_CLASS, className)} {...rest} />
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { ChevronDown, X } from 'lucide-react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export function FilterChip({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
options,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
options: Array<{ value: string; label: string }>
|
||||||
|
onChange: (value: string) => void
|
||||||
|
}) {
|
||||||
|
const selected = options.find(o => o.value === value)
|
||||||
|
const set = Boolean(value && selected)
|
||||||
|
return (
|
||||||
|
<label
|
||||||
|
className={cx(
|
||||||
|
'relative inline-flex items-center gap-1 h-7 px-2.5 rounded-md text-[12.5px] whitespace-nowrap cursor-pointer',
|
||||||
|
set ? 'bg-accent-tint-2 text-accent-700 shadow-chip-set' : 'bg-surface text-ink-2 shadow-chip',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span>{set ? `${label}: ${selected!.label}` : label}</span>
|
||||||
|
{!set && <ChevronDown size={12} strokeWidth={2.5} aria-hidden />}
|
||||||
|
<select
|
||||||
|
aria-label={label}
|
||||||
|
value={value}
|
||||||
|
onChange={e => onChange(e.target.value)}
|
||||||
|
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||||
|
>
|
||||||
|
<option value="">{label}</option>
|
||||||
|
{options.map(o => (
|
||||||
|
<option key={o.value} value={o.value}>{o.label}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{set && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Clear ${label}`}
|
||||||
|
onClick={() => onChange('')}
|
||||||
|
className="relative z-10 inline-grid place-items-center w-4 h-4 cursor-pointer"
|
||||||
|
>
|
||||||
|
<X size={12} strokeWidth={2.5} aria-hidden />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
+11
-12
@@ -1,6 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
import { X } from 'lucide-react'
|
||||||
|
import { Button } from './button'
|
||||||
|
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
open: boolean
|
open: boolean
|
||||||
@@ -25,20 +27,17 @@ export function Modal({ open, onClose, title, children, footer, width = 'md' }:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" role="dialog" aria-modal="true">
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" role="dialog" aria-modal="true">
|
||||||
<div className="absolute inset-0 bg-gray-900/50" onClick={onClose} />
|
<div className="absolute inset-0 bg-black/30" onClick={onClose} />
|
||||||
<div className={`relative w-full ${maxW} bg-white rounded-2xl shadow-2xl`}>
|
<div className={`relative w-full ${maxW} bg-surface rounded-xl shadow-float`}>
|
||||||
<div className="flex items-center justify-between px-6 py-4 border-b border-gray-100">
|
<div className="flex items-center justify-between px-5 py-3.5 border-b border-rule">
|
||||||
<h2 className="text-sm font-semibold text-gray-900">{title}</h2>
|
<h2 className="text-base font-[650]">{title}</h2>
|
||||||
<button onClick={onClose} aria-label="Close"
|
<Button variant="icon" aria-label="Close" onClick={onClose}>
|
||||||
className="text-gray-400 hover:text-gray-600 p-1 rounded-lg hover:bg-gray-100 transition-colors cursor-pointer">
|
<X size={16} strokeWidth={2} aria-hidden />
|
||||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
</Button>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18 18 6M6 6l12 12" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="px-6 py-5">{children}</div>
|
<div className="px-5 py-4">{children}</div>
|
||||||
{footer && (
|
{footer && (
|
||||||
<div className="px-6 py-4 border-t border-gray-100 flex justify-end gap-2">
|
<div className="px-5 py-3.5 border-t border-rule flex justify-end gap-2">
|
||||||
{footer}
|
{footer}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import type { ReactNode } from 'react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export function Segmented({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
value: string
|
||||||
|
onChange: (v: string) => void
|
||||||
|
options: Array<{ value: string; label: ReactNode }>
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="inline-flex p-0.5 rounded-[10px] bg-rule-2">
|
||||||
|
{options.map(o => (
|
||||||
|
<button
|
||||||
|
key={o.value}
|
||||||
|
type="button"
|
||||||
|
aria-pressed={o.value === value}
|
||||||
|
onClick={() => onChange(o.value)}
|
||||||
|
className={cx(
|
||||||
|
'inline-flex items-center gap-1.5 px-2.5 py-[5px] rounded-md text-[13px] cursor-pointer whitespace-nowrap',
|
||||||
|
o.value === value ? 'bg-surface font-semibold shadow-sm' : 'text-ink-3',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{o.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import type { ReactNode } from 'react'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export type StatusHue = 'amber' | 'blue' | 'violet' | 'orange' | 'indigo' | 'green' | 'grey' | 'red'
|
||||||
|
|
||||||
|
const HUES: Record<string, StatusHue> = {
|
||||||
|
reported: 'amber', triaged: 'blue', investigating: 'violet', capa_pending: 'orange',
|
||||||
|
verification: 'indigo', closed: 'green',
|
||||||
|
open: 'grey', in_progress: 'blue', overdue: 'red', pending_verification: 'indigo',
|
||||||
|
verified: 'green', reopened: 'red',
|
||||||
|
critical: 'red', high: 'orange', med: 'amber', medium: 'amber', low: 'grey', active: 'green',
|
||||||
|
}
|
||||||
|
|
||||||
|
const LABELS: Record<string, string> = {
|
||||||
|
capa_pending: 'CAPA pending', pending_verification: 'Verification', in_progress: 'In progress', med: 'Medium',
|
||||||
|
}
|
||||||
|
|
||||||
|
// Full literal class strings so Tailwind can see them.
|
||||||
|
const HUE_CLASS: Record<StatusHue, string> = {
|
||||||
|
amber: 'bg-st-amber-bg text-st-amber-fg',
|
||||||
|
blue: 'bg-st-blue-bg text-st-blue-fg',
|
||||||
|
violet: 'bg-st-violet-bg text-st-violet-fg',
|
||||||
|
orange: 'bg-st-orange-bg text-st-orange-fg',
|
||||||
|
indigo: 'bg-st-indigo-bg text-st-indigo-fg',
|
||||||
|
green: 'bg-st-green-bg text-st-green-fg',
|
||||||
|
grey: 'bg-st-grey-bg text-st-grey-fg',
|
||||||
|
red: 'bg-st-red-bg text-st-red-fg',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function statusHue(key: string): StatusHue {
|
||||||
|
return HUES[key] ?? 'grey'
|
||||||
|
}
|
||||||
|
|
||||||
|
function label(key: string): string {
|
||||||
|
if (LABELS[key]) return LABELS[key]
|
||||||
|
const words = key.split('_').join(' ')
|
||||||
|
return words.charAt(0).toUpperCase() + words.slice(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Pill({ hue, className, children }: { hue: StatusHue; className?: string; children: ReactNode }) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cx(
|
||||||
|
'inline-flex items-center px-2 py-0.5 rounded-md text-xs font-[550] whitespace-nowrap',
|
||||||
|
HUE_CLASS[hue],
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
|
||||||
|
return <Pill hue={statusHue(status)}>{children ?? label(status)}</Pill>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PriorityTag({ priority, children }: { priority: string; children?: ReactNode }) {
|
||||||
|
return <Pill hue={statusHue(priority)}>{children ?? label(priority)}</Pill>
|
||||||
|
}
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import type { ReactNode } from 'react'
|
||||||
|
import { ArrowDown, ArrowUp, ChevronLeft, ChevronRight, ChevronsUpDown, Inbox } from 'lucide-react'
|
||||||
|
import { Checkbox } from './checkbox'
|
||||||
|
import { cx } from './cx'
|
||||||
|
|
||||||
|
export type Column<T> = { key: string; header: string; sortKey?: string; cell: (row: T) => ReactNode }
|
||||||
|
export type Sort = { key: string; dir: 'asc' | 'desc' }
|
||||||
|
export type TableView = { key: string; label: string; count?: number }
|
||||||
|
|
||||||
|
export interface TableCardProps<T> {
|
||||||
|
columns: Column<T>[]
|
||||||
|
rows: T[]
|
||||||
|
rowKey: (row: T) => string
|
||||||
|
onRowOpen?: (row: T) => void
|
||||||
|
rowActions?: (row: T) => ReactNode
|
||||||
|
views?: { items: TableView[]; active: string; onChange: (key: string) => void }
|
||||||
|
toolbar?: ReactNode
|
||||||
|
sort?: Sort
|
||||||
|
onSortChange?: (sortKey: string) => void
|
||||||
|
selection?: { selected: Set<string>; onChange: (next: Set<string>) => void }
|
||||||
|
bulkActions?: ReactNode
|
||||||
|
footer?: { from: number; to: number; total: number; page: number; pageCount: number; onPage: (page: number) => void }
|
||||||
|
empty?: { title: string; action?: ReactNode }
|
||||||
|
mobileRow?: (row: T) => ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
const TH = 'px-3 py-[9px] text-xs font-[550] text-muted text-left bg-surface-2 border-b border-rule-2 whitespace-nowrap'
|
||||||
|
const TD = 'px-3 py-3 text-[13px] border-b border-rule'
|
||||||
|
|
||||||
|
export function TableCard<T>({
|
||||||
|
columns, rows, rowKey, onRowOpen, rowActions, views, toolbar, sort, onSortChange,
|
||||||
|
selection, bulkActions, footer, empty, mobileRow,
|
||||||
|
}: TableCardProps<T>) {
|
||||||
|
const selectedOnPage = selection ? rows.filter(r => selection.selected.has(rowKey(r))).length : 0
|
||||||
|
const allSelected = rows.length > 0 && selectedOnPage === rows.length
|
||||||
|
|
||||||
|
const setAll = (next: boolean) => {
|
||||||
|
if (!selection) return
|
||||||
|
const s = new Set(selection.selected)
|
||||||
|
rows.forEach(r => (next ? s.add(rowKey(r)) : s.delete(rowKey(r))))
|
||||||
|
selection.onChange(s)
|
||||||
|
}
|
||||||
|
const setOne = (id: string, next: boolean) => {
|
||||||
|
if (!selection) return
|
||||||
|
const s = new Set(selection.selected)
|
||||||
|
if (next) s.add(id)
|
||||||
|
else s.delete(id)
|
||||||
|
selection.onChange(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
const open = (row: T) => onRowOpen?.(row)
|
||||||
|
const isEmpty = rows.length === 0 && empty
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative bg-surface rounded-xl shadow-card overflow-hidden">
|
||||||
|
{views && (
|
||||||
|
<div className="flex items-center gap-0.5 p-2 border-b border-rule">
|
||||||
|
{views.items.map(v => (
|
||||||
|
<button
|
||||||
|
key={v.key}
|
||||||
|
type="button"
|
||||||
|
onClick={() => views.onChange(v.key)}
|
||||||
|
className={cx(
|
||||||
|
'inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-[13px] cursor-pointer',
|
||||||
|
v.key === views.active ? 'bg-rule-2 font-semibold text-ink' : 'font-medium text-ink-3 hover:bg-surface-2',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{v.label}
|
||||||
|
{v.count !== undefined && <span className="text-xs font-medium text-faint">{v.count}</span>}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{toolbar && <div className="flex flex-wrap items-center gap-2 px-3 py-2.5 border-b border-rule">{toolbar}</div>}
|
||||||
|
|
||||||
|
{isEmpty ? (
|
||||||
|
<div className="flex flex-col items-center gap-3 px-4 py-14 text-center">
|
||||||
|
<span className="inline-grid place-items-center w-16 h-16 rounded-xl bg-surface-2 text-faint">
|
||||||
|
<Inbox size={28} strokeWidth={1.8} aria-hidden />
|
||||||
|
</span>
|
||||||
|
<p className="text-sm text-ink-3">{empty.title}</p>
|
||||||
|
{empty.action}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="hidden md:block overflow-x-auto">
|
||||||
|
<table className="w-full border-collapse">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{selection && (
|
||||||
|
<th className={cx(TH, 'w-7 pl-4')}>
|
||||||
|
<Checkbox
|
||||||
|
checked={allSelected}
|
||||||
|
indeterminate={selectedOnPage > 0 && !allSelected}
|
||||||
|
onChange={setAll}
|
||||||
|
label="Select all rows"
|
||||||
|
/>
|
||||||
|
</th>
|
||||||
|
)}
|
||||||
|
{columns.map(c => {
|
||||||
|
const sorted = sort && c.sortKey && sort.key === c.sortKey ? sort.dir : null
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
key={c.key}
|
||||||
|
className={TH}
|
||||||
|
aria-sort={sorted ? (sorted === 'asc' ? 'ascending' : 'descending') : undefined}
|
||||||
|
>
|
||||||
|
{c.sortKey && onSortChange ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => onSortChange(c.sortKey!)}
|
||||||
|
className="inline-flex items-center gap-1 cursor-pointer"
|
||||||
|
>
|
||||||
|
{c.header}
|
||||||
|
{sorted === 'asc' ? (
|
||||||
|
<ArrowUp size={12} strokeWidth={2.5} className="text-ink" aria-hidden />
|
||||||
|
) : sorted === 'desc' ? (
|
||||||
|
<ArrowDown size={12} strokeWidth={2.5} className="text-ink" aria-hidden />
|
||||||
|
) : (
|
||||||
|
<ChevronsUpDown size={12} strokeWidth={2} className="text-neutral-400" aria-hidden />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
c.header
|
||||||
|
)}
|
||||||
|
</th>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{rowActions && <th className={cx(TH, 'w-24')} />}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{rows.map(row => {
|
||||||
|
const id = rowKey(row)
|
||||||
|
const selected = Boolean(selection?.selected.has(id))
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
key={id}
|
||||||
|
tabIndex={onRowOpen ? 0 : undefined}
|
||||||
|
onClick={() => open(row)}
|
||||||
|
onKeyDown={e => { if (e.key === 'Enter') open(row) }}
|
||||||
|
className={cx(
|
||||||
|
'group',
|
||||||
|
onRowOpen && 'cursor-pointer',
|
||||||
|
selected ? 'bg-accent-tint' : 'bg-surface hover:bg-surface-2',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{selection && (
|
||||||
|
<td className={cx(TD, 'pl-4')} onClick={e => e.stopPropagation()}>
|
||||||
|
<Checkbox checked={selected} onChange={next => setOne(id, next)} label="Select row" />
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
{columns.map(c => (
|
||||||
|
<td key={c.key} className={TD}>{c.cell(row)}</td>
|
||||||
|
))}
|
||||||
|
{rowActions && (
|
||||||
|
<td className={TD} onClick={e => e.stopPropagation()}>
|
||||||
|
<div className="flex justify-end gap-1 opacity-0 group-hover:opacity-100 focus-within:opacity-100">
|
||||||
|
{rowActions(row)}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{mobileRow && (
|
||||||
|
<ul className="md:hidden">
|
||||||
|
{rows.map(row => (
|
||||||
|
<li
|
||||||
|
key={rowKey(row)}
|
||||||
|
onClick={() => open(row)}
|
||||||
|
className={cx('px-4 py-3 border-b border-rule', onRowOpen && 'cursor-pointer')}
|
||||||
|
>
|
||||||
|
{mobileRow(row)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{footer && (
|
||||||
|
<div className="flex items-center justify-between px-4 py-2.5 bg-surface-2 text-[13px] text-muted">
|
||||||
|
<span>{`Showing ${footer.from}–${footer.to} of ${footer.total}`}</span>
|
||||||
|
<div className="flex">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Previous page"
|
||||||
|
disabled={footer.page <= 1}
|
||||||
|
onClick={() => footer.onPage(footer.page - 1)}
|
||||||
|
className="inline-flex items-center h-8 px-[7px] rounded-l-md bg-surface text-ink shadow-chip disabled:text-neutral-400 cursor-pointer"
|
||||||
|
>
|
||||||
|
<ChevronLeft size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="Next page"
|
||||||
|
disabled={footer.page >= footer.pageCount}
|
||||||
|
onClick={() => footer.onPage(footer.page + 1)}
|
||||||
|
className="inline-flex items-center h-8 px-[7px] rounded-r-md bg-surface text-ink shadow-chip -ml-px disabled:text-neutral-400 cursor-pointer"
|
||||||
|
>
|
||||||
|
<ChevronRight size={16} strokeWidth={2} aria-hidden />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{selection && bulkActions && selection.selected.size > 0 && (
|
||||||
|
<div className="sticky bottom-3 flex justify-center px-4 pb-3 pt-5 bg-gradient-to-t from-surface">
|
||||||
|
<div className="flex items-center gap-1.5 py-1.5 pr-1.5 pl-3 rounded-xl bg-surface shadow-float">
|
||||||
|
<span className="text-[13px] font-semibold px-2">{`${selection.selected.size} selected`}</span>
|
||||||
|
<span className="w-px h-5 bg-rule-2" />
|
||||||
|
{bulkActions}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<script src="./support.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<x-dc>
|
||||||
|
<helmet>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body{margin:0;background:#f7f7f7;color:#1f1f1f;font-family:Geist,system-ui,sans-serif;-webkit-font-smoothing:antialiased}
|
||||||
|
a{color:#0f766e;text-decoration:none}a:hover{text-decoration:underline}
|
||||||
|
</style>
|
||||||
|
</helmet>
|
||||||
|
<div style="max-width:1080px;margin:0 auto;padding:56px 40px 96px;display:flex;flex-direction:column;gap:56px">
|
||||||
|
<div style="display:flex;flex-direction:column;gap:12px">
|
||||||
|
<div style="font:600 12px 'Geist Mono',monospace;color:#616161;letter-spacing:.04em">IMS · UI REFRESH · HANDOFF SPEC</div>
|
||||||
|
<div style="font-size:30px;font-weight:600;letter-spacing:-.02em">Patterns, tokens and states</div>
|
||||||
|
<div style="font-size:15px;line-height:1.55;color:#4a4a4a;max-width:720px;text-wrap:pretty">Everything in <a href="IMS Admin.dc.html">IMS Admin.dc.html</a> is built from the pieces below. Values are the ones used in the mockups; map them to Tailwind theme tokens once and the screens follow. Type is Geist (UI) and Geist Mono (references, keyboard hints).</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:20px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">1 · Color</div>
|
||||||
|
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px">
|
||||||
|
<sc-for list="{{ colors }}" as="c" hint-placeholder-count="12"><div style="display:flex;flex-direction:column;gap:8px"><div style="height:56px;border-radius:10px;background:{{ c.hex }};box-shadow:inset 0 0 0 1px rgba(0,0,0,.08)"></div><div style="font-size:13px;font-weight:550">{{ c.name }}</div><div style="font:500 12px 'Geist Mono',monospace;color:#616161">{{ c.hex }}</div><div style="font-size:12px;color:#616161;line-height:1.4">{{ c.use }}</div></div></sc-for>
|
||||||
|
</div>
|
||||||
|
<div style="font-size:14px;font-weight:600;margin-top:8px">Status pills</div>
|
||||||
|
<div style="display:flex;flex-wrap:wrap;gap:8px">
|
||||||
|
<sc-for list="{{ pills }}" as="p" hint-placeholder-count="12"><span style="display:inline-flex;align-items:center;gap:8px;padding:2px 8px 2px 8px;border-radius:8px;font-size:12px;font-weight:550;white-space:nowrap;background:{{ p.bg }};color:{{ p.fg }}">{{ p.label }}<span style="font:500 11px 'Geist Mono',monospace;opacity:.75">{{ p.bg }} / {{ p.fg }}</span></span></sc-for>
|
||||||
|
</div>
|
||||||
|
<div style="font-size:13px;color:#4a4a4a;line-height:1.5;max-width:720px">Pill text is always a dark ramp step on a light tint — never white on a saturated fill. Priority uses the same scale: Critical = red, High = orange, Medium = yellow, Low = neutral. Incident status and CAPA status share one palette so the dashboard reads consistently.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:20px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">2 · Type, radius, shadow</div>
|
||||||
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:24px">
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px">
|
||||||
|
<sc-for list="{{ type }}" as="t" hint-placeholder-count="7"><div style="display:grid;grid-template-columns:150px 1fr;gap:16px;align-items:baseline;padding:8px 0;border-bottom:1px solid #ebebeb"><span style="font:500 12px 'Geist Mono',monospace;color:#616161">{{ t.spec }}</span><span style="font-size:{{ t.size }};font-weight:{{ t.w }};font-family:{{ t.fam }};letter-spacing:{{ t.ls }}">{{ t.sample }}</span></div></sc-for>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px">
|
||||||
|
<sc-for list="{{ shape }}" as="s" hint-placeholder-count="6"><div style="display:grid;grid-template-columns:150px 1fr;gap:16px;align-items:center;padding:8px 0;border-bottom:1px solid #ebebeb"><span style="font:500 12px 'Geist Mono',monospace;color:#616161">{{ s.k }}</span><span style="font-size:13px;color:#303030">{{ s.v }}</span></div></sc-for>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:20px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">3 · Buttons and controls</div>
|
||||||
|
<div style="display:flex;flex-wrap:wrap;gap:24px;align-items:flex-start">
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Primary · 32px · #303030, inset highlight</span><span style="display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 12px;border-radius:8px;background:#303030;color:#fff;font-size:13px;font-weight:600;box-shadow:inset 0 -1px 0 #000,inset 0 1px 0 rgba(255,255,255,.18),0 1px 2px rgba(0,0,0,.2);cursor:pointer;white-space:nowrap;align-self:flex-start">{{ ic.plus }}Report incident</span><span style="font-size:12px;color:#616161">hover #1f1f1f · active #000 · focus 2px ring #0f766e offset 2px</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Secondary · white, 1px #d4d4d4 ring</span><span style="display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 12px;border-radius:8px;background:#fff;color:#1f1f1f;font-size:13px;font-weight:550;box-shadow:inset 0 0 0 1px #d4d4d4,0 1px 0 rgba(0,0,0,.05);cursor:pointer;white-space:nowrap;align-self:flex-start">{{ ic.download }}Export</span><span style="font-size:12px;color:#616161">hover bg #f7f7f7 · active bg #ebebeb</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Icon button · 28px, ghost</span><span style="width:28px;height:28px;border-radius:8px;display:grid;place-items:center;color:#4a4a4a;cursor:pointer;background:#ebebeb">{{ ic.more }}</span><span style="font-size:12px;color:#616161">rest transparent · hover #ebebeb</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Filter chip · 28px</span><div style="display:flex;gap:6px"><span style="display:inline-flex;align-items:center;gap:4px;height:28px;padding:0 10px;border-radius:8px;font-size:12.5px;color:#303030;box-shadow:inset 0 0 0 1px #d4d4d4;background:#fff;cursor:pointer;white-space:nowrap">Owner{{ ic.chev12 }}</span><span style="display:inline-flex;align-items:center;gap:4px;height:28px;padding:0 10px;border-radius:8px;font-size:12.5px;background:#e6f4f1;box-shadow:inset 0 0 0 1px #9fd3c7;color:#0b4f47;cursor:pointer;white-space:nowrap">Priority: Critical{{ ic.x12 }}</span></div><span style="font-size:12px;color:#616161">unset: chevron · set: teal tint + value + clear ×</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Segmented · 2px padding on #e3e3e3</span><div style="display:flex;padding:2px;border-radius:10px;background:#e3e3e3;align-self:flex-start"><span style="display:flex;align-items:center;gap:6px;padding:5px 10px;border-radius:8px;background:#fff;font-size:13px;font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.1);white-space:nowrap">{{ ic.rows }}List</span><span style="display:flex;align-items:center;gap:6px;padding:5px 10px;font-size:13px;color:#4a4a4a;white-space:nowrap">{{ ic.kanban }}Board</span></div></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Checkbox · 16px, radius 5</span><div style="display:flex;gap:8px;align-items:center"><span style="width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px #8a8a8a;background:#fff;display:block"></span><span style="width:16px;height:16px;border-radius:5px;background:#0f766e;color:#fff;display:grid;place-items:center">{{ ic.tick12 }}</span><span style="width:16px;height:16px;border-radius:5px;background:#0f766e;color:#fff;display:grid;place-items:center">{{ ic.minus12 }}</span></div><span style="font-size:12px;color:#616161">off · on · indeterminate (header)</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:10px"><span style="font-size:12px;color:#616161">Text input · 36px desktop, 48px mobile</span><div style="height:36px;padding:0 12px;border-radius:8px;box-shadow:inset 0 0 0 1px #8a8a8a;background:#fff;font-size:13px;display:flex;align-items:center;color:#8a8a8a;width:220px">Placeholder</div><span style="font-size:12px;color:#616161">rest ring #8a8a8a · focus ring 2px #0f766e · error #b3261e</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:20px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">4 · Table card</div>
|
||||||
|
<div style="font-size:13px;color:#4a4a4a;line-height:1.5;max-width:720px;text-wrap:pretty">One component wraps every list in the app. Anatomy top to bottom; every part is optional except the table and the card.</div>
|
||||||
|
<div style="background:#fff;border-radius:12px;box-shadow:0 0 0 1px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.06);overflow:hidden;position:relative">
|
||||||
|
<div style="display:flex;align-items:center;justify-content:space-between;padding:8px;border-bottom:1px solid #ebebeb"><div style="display:flex;gap:2px;align-items:center"><div style="display:flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:8px;font-size:13px;font-weight:600;background:#e3e3e3;color:#1f1f1f">All <span style="font-size:12px;color:#8a8a8a;font-weight:500">248</span></div><div style="display:flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:8px;font-size:13px;font-weight:500;color:#4a4a4a">Open <span style="font-size:12px;color:#8a8a8a">37</span></div><div style="width:28px;height:28px;border-radius:8px;display:grid;place-items:center;color:#4a4a4a">{{ ic.plus }}</div></div><span style="font:500 11px 'Geist Mono',monospace;color:#8a8a8a;padding-right:4px">A · saved views · padding 8 · active #e3e3e3</span></div>
|
||||||
|
<div style="display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid #ebebeb"><div style="display:flex;align-items:center;gap:8px;height:32px;padding:0 10px;border-radius:8px;box-shadow:inset 0 0 0 1px #8a8a8a;background:#fff;color:#616161;font-size:13px;min-width:260px">{{ ic.search }}<span>Search</span></div><span style="display:inline-flex;align-items:center;gap:4px;height:28px;padding:0 10px;border-radius:8px;font-size:12.5px;color:#303030;box-shadow:inset 0 0 0 1px #d4d4d4;background:#fff;white-space:nowrap">Site{{ ic.chev12 }}</span><span style="flex:1"></span><span style="font:500 11px 'Geist Mono',monospace;color:#8a8a8a">B · search + filter chips · padding 10/12</span></div>
|
||||||
|
<table><thead><tr><th style="padding:9px 12px;font-size:12px;font-weight:550;color:#616161;text-align:left;background:#f7f7f7;border-bottom:1px solid #e3e3e3;white-space:nowrap;width:28px;padding-left:16px"><span style="width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px #8a8a8a;background:#fff;display:block"></span></th><th style="padding:9px 12px;font-size:12px;font-weight:550;color:#616161;text-align:left;background:#f7f7f7;border-bottom:1px solid #e3e3e3;white-space:nowrap"><span style="display:inline-flex;align-items:center;gap:4px">Reference<span style="color:#1f1f1f">{{ ic.down12 }}</span></span></th><th style="padding:9px 12px;font-size:12px;font-weight:550;color:#616161;text-align:left;background:#f7f7f7;border-bottom:1px solid #e3e3e3;white-space:nowrap"><span style="display:inline-flex;align-items:center;gap:4px">Status<span style="color:#c4c4c4">{{ ic.sort12 }}</span></span></th><th style="padding:9px 12px;font-size:12px;font-weight:550;color:#616161;text-align:left;background:#f7f7f7;border-bottom:1px solid #e3e3e3;white-space:nowrap;width:100%"><span style="font:500 11px 'Geist Mono',monospace;color:#8a8a8a;font-weight:500">C · header #f7f7f7 · 12px/550 · sorted column ink, others #c4c4c4</span></th><th style="padding:9px 12px;background:#f7f7f7;border-bottom:1px solid #e3e3e3;width:100px"></th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr style="background:#fff"><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;padding-left:16px"><span style="width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px #8a8a8a;background:#fff;display:block"></span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><a href="#" style="font-family:'Geist Mono',monospace;font-size:12.5px">IMS-2026-0248</a></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><span style="display:inline-flex;align-items:center;padding:2px 8px;border-radius:8px;font-size:12px;font-weight:550;background:#ede7ff;color:#4b2e99">Investigating</span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;color:#8a8a8a;font:500 11px 'Geist Mono',monospace">D · row rest · #fff · 13px · 12px cell padding · 1px #ebebeb rule</td><td style="padding:12px;border-bottom:1px solid #ebebeb"></td></tr>
|
||||||
|
<tr style="background:#f7f7f7"><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;padding-left:16px"><span style="width:16px;height:16px;border-radius:5px;box-shadow:inset 0 0 0 1.5px #8a8a8a;background:#fff;display:block"></span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><a href="#" style="font-family:'Geist Mono',monospace;font-size:12.5px">IMS-2026-0247</a></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><span style="display:inline-flex;align-items:center;padding:2px 8px;border-radius:8px;font-size:12px;font-weight:550;background:#e0efff;color:#00527c">Triaged</span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;color:#8a8a8a;font:500 11px 'Geist Mono',monospace">E · row hover · #f7f7f7 · quick actions appear right</td><td style="padding:12px;border-bottom:1px solid #ebebeb"><div style="display:flex;gap:4px;justify-content:flex-end"><span style="width:28px;height:28px;border-radius:8px;display:grid;place-items:center;color:#4a4a4a">{{ ic.eye }}</span><span style="width:28px;height:28px;border-radius:8px;display:grid;place-items:center;color:#4a4a4a">{{ ic.more }}</span></div></td></tr>
|
||||||
|
<tr style="background:#f2f7f6"><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;padding-left:16px"><span style="width:16px;height:16px;border-radius:5px;background:#0f766e;color:#fff;display:grid;place-items:center">{{ ic.tick12 }}</span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><a href="#" style="font-family:'Geist Mono',monospace;font-size:12.5px">IMS-2026-0246</a></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb"><span style="display:inline-flex;align-items:center;padding:2px 8px;border-radius:8px;font-size:12px;font-weight:550;background:#fff1c2;color:#6b4a00">Reported</span></td><td style="padding:12px;font-size:13px;border-bottom:1px solid #ebebeb;color:#8a8a8a;font:500 11px 'Geist Mono',monospace">F · row selected · #f2f7f6</td><td style="padding:12px;border-bottom:1px solid #ebebeb"></td></tr>
|
||||||
|
</tbody></table>
|
||||||
|
<div style="display:flex;align-items:center;justify-content:space-between;padding:10px 16px;background:#f7f7f7;font-size:13px;color:#616161"><span>Showing 1–3 of 248</span><span style="font:500 11px 'Geist Mono',monospace;color:#8a8a8a">G · footer #f7f7f7 · count left, pager right</span><div style="display:flex"><span style="display:inline-flex;align-items:center;height:32px;padding:0 7px;border-radius:8px 0 0 8px;background:#fff;box-shadow:inset 0 0 0 1px #d4d4d4;color:#b5b5b5">{{ ic.chevLeft }}</span><span style="display:inline-flex;align-items:center;height:32px;padding:0 7px;border-radius:0 8px 8px 0;background:#fff;box-shadow:inset 0 0 0 1px #d4d4d4;margin-left:-1px;color:#1f1f1f">{{ ic.chevRight }}</span></div></div>
|
||||||
|
<div style="display:flex;justify-content:center;padding:20px 16px 24px;background:#fcfcfc;border-top:1px solid #ebebeb"><div style="display:flex;align-items:center;gap:6px;padding:6px 6px 6px 12px;border-radius:12px;background:#fff;box-shadow:0 0 0 1px rgba(0,0,0,.1),0 12px 32px rgba(0,0,0,.18)"><span style="width:16px;height:16px;border-radius:5px;background:#0f766e;color:#fff;display:grid;place-items:center">{{ ic.tick12 }}</span><span style="font-size:13px;font-weight:600;padding:0 8px 0 4px;white-space:nowrap">1 selected</span><span style="width:1px;height:20px;background:#e3e3e3"></span><span style="display:inline-flex;align-items:center;height:32px;padding:0 12px;border-radius:8px;font-size:13px;font-weight:550">Assign</span><span style="display:inline-flex;align-items:center;height:32px;padding:0 12px;border-radius:8px;font-size:13px;font-weight:550">Export</span><span style="font:500 11px 'Geist Mono',monospace;color:#8a8a8a;padding:0 8px">H · bulk bar · floats centred above footer, appears on first selection</span></div></div>
|
||||||
|
</div>
|
||||||
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:24px;font-size:13px;color:#4a4a4a;line-height:1.55">
|
||||||
|
<div style="display:flex;flex-direction:column;gap:8px"><span style="font-weight:600;color:#1f1f1f">Behaviour</span><span>Whole row is clickable and opens the record; the checkbox cell, links and quick actions stop propagation.</span><span>Sorting is single-column; the sorted header shows a filled arrow, others a faint double chevron.</span><span>Saved views are server-side filters; the + opens "Save current filters as view". Counts update live.</span><span>Empty state replaces thead + tbody with a 64px icon tile, one line of copy and the primary action (see artboard 08).</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:8px"><span style="font-weight:600;color:#1f1f1f">Mobile</span><span>Below 768px the table becomes a stacked list in the same card: reference + status on line one, type · zone on line two, date on line three, chevron right (artboard 10).</span><span>Saved views become horizontally scrolling 999px chips; filters collapse to one "Filter" button opening a sheet.</span><span>Bulk bar is replaced by a bottom sheet.</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:20px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">5 · Layout shell</div>
|
||||||
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:24px;font-size:13px;color:#4a4a4a;line-height:1.55">
|
||||||
|
<div style="display:flex;flex-direction:column;gap:8px"><span style="font-weight:600;color:#1f1f1f">Desktop</span><span>Top bar 56px #1a1a1a: brand 224px · ⌘K search max 520px #303030 · bell + user chip 224px.</span><span>Sidebar 240px #ebebeb, padding 12, items 32px radius 8; active item white with 1px ring and teal icon; badges 999px #dcdcdc.</span><span>Main padding 24/32, column gap 16. Page title 20px/650 with actions right. Detail pages use 1fr + 320–340px side rail.</span><span>Page background #f1f1f1; cards white, radius 12, ring rgba(0,0,0,.08) + 1px shadow.</span></div>
|
||||||
|
<div style="display:flex;flex-direction:column;gap:8px"><span style="font-weight:600;color:#1f1f1f">Mobile (reporter)</span><span>390px reference. Page title 22px/650, horizontal padding 16, card gap 12.</span><span>Tab bar: white, 1px top rule, 3 items, 22px icons, 10.5px labels; active #0f766e.</span><span>Form controls 48px tall, radius 12; primary button full width 48px. Footers sit on #f1f1f1 with a 1px top rule and 30px bottom safe area.</span><span>Minimum hit target 44px everywhere.</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;flex-direction:column;gap:12px">
|
||||||
|
<div style="font-size:18px;font-weight:600;letter-spacing:-.01em;padding-bottom:10px;border-bottom:1px solid #dcdcdc">6 · Screen index</div>
|
||||||
|
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:6px 24px">
|
||||||
|
<sc-for list="{{ screens }}" as="s" hint-placeholder-count="24"><div style="display:flex;gap:10px;padding:6px 0;border-bottom:1px solid #ebebeb;font-size:13px"><span style="font:600 11px 'Geist Mono',monospace;color:#616161;width:32px;flex:none;padding-top:2px">{{ s.id }}</span><span style="flex:1">{{ s.name }}</span><span style="font-size:12px;color:#8a8a8a;white-space:nowrap">{{ s.route }}</span></div></sc-for>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-dc>
|
||||||
|
<script type="text/x-dc" data-dc-script>
|
||||||
|
class Component extends DCLogic {
|
||||||
|
renderVals() {
|
||||||
|
const I = (paths, s = 16, w = 2) => React.createElement('svg', { width: s, height: s, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: w, strokeLinecap: 'round', strokeLinejoin: 'round', style: { flex: 'none' } }, paths.map((d, i) => React.createElement('path', { key: i, d })));
|
||||||
|
const P = {
|
||||||
|
plus: ['M12 5v14', 'M5 12h14'], download: ['M12 3v12', 'm7 10 5 5 5-5', 'M4 19h16'], more: ['M12 12h.01', 'M19 12h.01', 'M5 12h.01'],
|
||||||
|
chevDown: ['m6 9 6 6 6-6'], x: ['M18 6 6 18', 'm6 6 12 12'], rows: ['M3 5h18v14H3z', 'M3 12h18'], kanban: ['M6 5v11', 'M12 5v6', 'M18 5v14'],
|
||||||
|
tick: ['M20 6 9 17l-5-5'], minus: ['M5 12h14'], search: ['M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16z', 'm21 21-4.3-4.3'],
|
||||||
|
sort: ['m7 15 5 5 5-5', 'm7 9 5-5 5 5'], down: ['M12 5v14', 'm19 12-7 7-7-7'], eye: ['M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z', 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'],
|
||||||
|
chevLeft: ['m15 18-6-6 6-6'], chevRight: ['m9 18 6-6-6-6']
|
||||||
|
};
|
||||||
|
const ic = {}; Object.keys(P).forEach(k => { ic[k] = I(P[k]); });
|
||||||
|
ic.tick12 = I(P.tick, 12, 3); ic.minus12 = I(P.minus, 12, 3); ic.more = I(P.more, 16, 3); ic.sort12 = I(P.sort, 12); ic.down12 = I(P.down, 12, 2.5); ic.x12 = I(P.x, 12, 2.5); ic.chev12 = I(P.chevDown, 12, 2.5);
|
||||||
|
const colors = [
|
||||||
|
['Ink', '#1f1f1f', 'Primary text, active sidebar text'], ['Ink 2', '#303030', 'Primary button, chip text'], ['Ink 3', '#4a4a4a', 'Secondary text, icons'], ['Muted', '#616161', 'Labels, helper text'], ['Faint', '#8a8a8a', 'Placeholders, input ring'],
|
||||||
|
['Rule', '#ebebeb', 'Row rules, sidebar bg'], ['Rule 2', '#e3e3e3', 'Header rule, segmented bg'], ['Ring', '#d4d4d4', 'Secondary button and chip ring'], ['Surface 2', '#f7f7f7', 'Table header, footer, row hover'], ['Ground', '#f1f1f1', 'Page background'],
|
||||||
|
['Teal', '#0f766e', 'Accent: checks, links, active tab icon'], ['Teal tint', '#f2f7f6', 'Selected row, selected card'], ['Teal tint 2', '#e6f4f1', 'Set filter chip (ring #9fd3c7, text #0b4f47)'], ['Danger', '#b3261e', 'Overdue text, required marks'], ['Top bar', '#1a1a1a', 'App header (#303030 for its controls)']
|
||||||
|
].map(c => ({ name: c[0], hex: c[1], use: c[2] }));
|
||||||
|
const pills = [
|
||||||
|
['Reported', '#fff1c2', '#6b4a00'], ['Triaged', '#e0efff', '#00527c'], ['Investigating', '#ede7ff', '#4b2e99'], ['CAPA pending', '#ffe6cf', '#7a3a00'], ['Verification', '#e3e8ff', '#2c3e8f'], ['Closed', '#d7f4e3', '#0c5132'],
|
||||||
|
['Open', '#ebebeb', '#4a4a4a'], ['In progress', '#e0efff', '#00527c'], ['Overdue · Critical', '#fee3e0', '#8e1f0b'], ['High', '#ffe6cf', '#7a3a00'], ['Medium', '#fff1c2', '#6b4a00'], ['Active', '#d7f4e3', '#0c5132']
|
||||||
|
].map(p => ({ label: p[0], bg: p[1], fg: p[2] }));
|
||||||
|
const type = [
|
||||||
|
['32 / 600 / -0.02em', '32px', 600, 'Geist', '-.02em', 'Cover title'], ['22 / 650 / -0.02em', '22px', 650, 'Geist', '-.02em', 'Mobile page title'], ['20 / 650 / -0.01em', '20px', 650, 'Geist', '-.01em', 'Page title'], ['16 / 650', '16px', 650, 'Geist', '-.01em', 'Card title (detail)'], ['14 / 600', '14px', 600, 'Geist', '0', 'Section heading'], ['13 / 400–550', '13px', 450, 'Geist', '0', 'Body, table cells, buttons'], ['12 / 550', '12px', 550, 'Geist', '0', 'Table header, pill, helper'], ['12.5 mono', '12.5px', 500, "'Geist Mono'", '0', 'IMS-2026-0247']
|
||||||
|
].map(t => ({ spec: t[0], size: t[1], w: t[2], fam: t[3], ls: t[4], sample: t[5] }));
|
||||||
|
const shape = [
|
||||||
|
['radius', '12 cards, phones' + ' · 10 drawer/inputs mobile · 8 buttons, chips, inputs, pills, sidebar items · 6 avatars 24px · 5 checkbox · 999 badges'],
|
||||||
|
['card', 'bg #fff · box-shadow 0 0 0 1px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06)'],
|
||||||
|
['floating', 'box-shadow 0 0 0 1px rgba(0,0,0,.1), 0 12px 32px rgba(0,0,0,.18) (bulk bar, drawer uses 24/60 .24)'],
|
||||||
|
['focus', 'outline 2px #0f766e, offset 2px, on every interactive element'],
|
||||||
|
['spacing', '4 · 6 · 8 · 10 · 12 · 16 · 20 · 24 · 32. Card padding 16–20 · table cell 12 · toolbar 10/12'],
|
||||||
|
['icons', 'Lucide, 16px stroke 2 in UI · 12px stroke 2.5 inside chips/checks · 22px stroke 1.8 in mobile tab bar']
|
||||||
|
].map(s => ({ k: s[0], v: s[1] }));
|
||||||
|
const screens = [
|
||||||
|
['01', 'Incidents list', '/hse/incidents'], ['01b', 'Notifications drawer', 'global'], ['02', 'Incident detail', '/hse/incidents/[id]'], ['02b', 'Triage form', '/hse/incidents/[id] · triage'], ['02c', 'Investigation form', '/hse/incidents/[id] · investigation'], ['02d', 'DOSH reporting · JKKP 6', '/hse/incidents/[id] · new'],
|
||||||
|
['03', 'Dashboard', '/hse/dashboard'], ['04', 'CAPA list', '/hse/capa'], ['04b', 'CAPA board', '/hse/capa · board'], ['04c', 'CAPA detail · verification', '/hse/capa · new'],
|
||||||
|
['05', 'Admin · users', '/admin'], ['05b', 'Admin · sites & zones', '/admin · tab'], ['05c', 'Admin · trucks', '/admin · tab'], ['05d', 'Admin · audit log', '/admin · new tab'], ['06', 'Settings', '/hse/settings'], ['07', 'Reporter · my reports', '/reporter'], ['08', 'Empty state', 'pattern'],
|
||||||
|
['09', 'Mobile · reporter home', '/reporter'], ['10', 'Mobile · incidents', '/hse/incidents'], ['11', 'Mobile · incident detail', '/hse/incidents/[id]'], ['12–15', 'Mobile · new incident 1/3 → saved offline', '/report'], ['16', 'Mobile · CAPA owner action', '/capa-owner']
|
||||||
|
].map(s => ({ id: s[0], name: s[1], route: s[2] }));
|
||||||
|
return { ic, colors, pills, type, shape, screens };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
File diff suppressed because one or more lines are too long
+151
@@ -0,0 +1,151 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"react",
|
||||||
|
"import"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"react/forbid-elements": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"forbid": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-restricted-imports": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"patterns": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"no-restricted-syntax": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"selector": "Literal[value=/#[0-9a-fA-F]{3,8}\\b/]",
|
||||||
|
"message": "Raw hex color — use a design-system color token via var()."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "Literal[value=/\\b\\d+px\\b/]",
|
||||||
|
"message": "Raw px value — use a design-system spacing token via var()."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"selector": "Literal[value=/font-family\\s*:\\s*(?!['\\\"]?(?:Archivo))/i]",
|
||||||
|
"message": "Font not provided by the design system. Available: Archivo."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"**/index.js"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"no-restricted-imports": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"x-omelette": {
|
||||||
|
"components": {},
|
||||||
|
"tokens": [
|
||||||
|
"--color-accent",
|
||||||
|
"--color-accent-100",
|
||||||
|
"--color-accent-2",
|
||||||
|
"--color-accent-2-100",
|
||||||
|
"--color-accent-2-200",
|
||||||
|
"--color-accent-2-300",
|
||||||
|
"--color-accent-2-400",
|
||||||
|
"--color-accent-2-500",
|
||||||
|
"--color-accent-2-600",
|
||||||
|
"--color-accent-2-700",
|
||||||
|
"--color-accent-2-800",
|
||||||
|
"--color-accent-2-900",
|
||||||
|
"--color-accent-200",
|
||||||
|
"--color-accent-300",
|
||||||
|
"--color-accent-400",
|
||||||
|
"--color-accent-500",
|
||||||
|
"--color-accent-600",
|
||||||
|
"--color-accent-700",
|
||||||
|
"--color-accent-800",
|
||||||
|
"--color-accent-900",
|
||||||
|
"--color-bg",
|
||||||
|
"--color-divider",
|
||||||
|
"--color-neutral-100",
|
||||||
|
"--color-neutral-200",
|
||||||
|
"--color-neutral-300",
|
||||||
|
"--color-neutral-400",
|
||||||
|
"--color-neutral-500",
|
||||||
|
"--color-neutral-600",
|
||||||
|
"--color-neutral-700",
|
||||||
|
"--color-neutral-800",
|
||||||
|
"--color-neutral-900",
|
||||||
|
"--color-surface",
|
||||||
|
"--color-text",
|
||||||
|
"--font-body",
|
||||||
|
"--font-heading",
|
||||||
|
"--font-heading-weight",
|
||||||
|
"--radius-lg",
|
||||||
|
"--radius-md",
|
||||||
|
"--radius-sm",
|
||||||
|
"--shadow-lg",
|
||||||
|
"--shadow-md",
|
||||||
|
"--shadow-sm",
|
||||||
|
"--space-1",
|
||||||
|
"--space-2",
|
||||||
|
"--space-3",
|
||||||
|
"--space-4",
|
||||||
|
"--space-6",
|
||||||
|
"--space-8"
|
||||||
|
],
|
||||||
|
"tokenKinds": {
|
||||||
|
"--color-bg": "color",
|
||||||
|
"--color-surface": "color",
|
||||||
|
"--color-text": "font",
|
||||||
|
"--color-accent": "color",
|
||||||
|
"--color-accent-2": "color",
|
||||||
|
"--color-divider": "color",
|
||||||
|
"--color-neutral-100": "color",
|
||||||
|
"--color-neutral-200": "color",
|
||||||
|
"--color-neutral-300": "color",
|
||||||
|
"--color-neutral-400": "color",
|
||||||
|
"--color-neutral-500": "color",
|
||||||
|
"--color-neutral-600": "color",
|
||||||
|
"--color-neutral-700": "color",
|
||||||
|
"--color-neutral-800": "color",
|
||||||
|
"--color-neutral-900": "color",
|
||||||
|
"--color-accent-100": "color",
|
||||||
|
"--color-accent-200": "color",
|
||||||
|
"--color-accent-300": "color",
|
||||||
|
"--color-accent-400": "color",
|
||||||
|
"--color-accent-500": "color",
|
||||||
|
"--color-accent-600": "color",
|
||||||
|
"--color-accent-700": "color",
|
||||||
|
"--color-accent-800": "color",
|
||||||
|
"--color-accent-900": "color",
|
||||||
|
"--color-accent-2-100": "color",
|
||||||
|
"--color-accent-2-200": "color",
|
||||||
|
"--color-accent-2-300": "color",
|
||||||
|
"--color-accent-2-400": "color",
|
||||||
|
"--color-accent-2-500": "color",
|
||||||
|
"--color-accent-2-600": "color",
|
||||||
|
"--color-accent-2-700": "color",
|
||||||
|
"--color-accent-2-800": "color",
|
||||||
|
"--color-accent-2-900": "color",
|
||||||
|
"--font-heading": "font",
|
||||||
|
"--font-heading-weight": "font",
|
||||||
|
"--font-body": "font",
|
||||||
|
"--space-1": "spacing",
|
||||||
|
"--space-2": "spacing",
|
||||||
|
"--space-3": "spacing",
|
||||||
|
"--space-4": "spacing",
|
||||||
|
"--space-6": "spacing",
|
||||||
|
"--space-8": "spacing",
|
||||||
|
"--radius-sm": "radius",
|
||||||
|
"--radius-md": "radius",
|
||||||
|
"--radius-lg": "radius",
|
||||||
|
"--shadow-sm": "shadow",
|
||||||
|
"--shadow-md": "shadow",
|
||||||
|
"--shadow-lg": "shadow"
|
||||||
|
},
|
||||||
|
"fontFamilies": [
|
||||||
|
"Archivo"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/* @ds-bundle: {"format":4,"namespace":"Modernist_modern","components":[],"sourceHashes":{},"inlinedExternals":[],"unexposedExports":[]} */
|
||||||
|
|
||||||
|
(() => {
|
||||||
|
|
||||||
|
const __ds_ns = (window.Modernist_modern = window.Modernist_modern || {});
|
||||||
|
|
||||||
|
const __ds_scope = {};
|
||||||
|
|
||||||
|
(__ds_ns.__errors = __ds_ns.__errors || []);
|
||||||
|
|
||||||
|
})();
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,81 @@
|
|||||||
|
# Modernist design system
|
||||||
|
|
||||||
|
Modernist is flat, architectural and set entirely in Archivo: a near-mono red on white, a visible modular grid, zero corner radius and strong 2px rules. Nothing floats and nothing is decorated — alignment and the strength of the dividers do all the organising, labels sit flush left (even inside buttons), and photography prints in pure black and white.
|
||||||
|
|
||||||
|
## How to use this
|
||||||
|
|
||||||
|
- Link the one stylesheet from every page — `<link rel="stylesheet" href="styles.css">` (adjust the relative path) — and take every color, font, spacing, radius and shadow from its variables (`var(--color-*)`, `var(--font-*)`, `var(--space-*)`, `var(--radius-*)`, `var(--shadow-*)`). Never hard-code a hex, a font name or a px value the tokens already carry.
|
||||||
|
- Build with the classes below rather than inventing parallel ones; the component pages are plain HTML, so view source and copy the markup.
|
||||||
|
- `templates/` holds starting points a consuming project can copy whole.
|
||||||
|
- The whole system was derived from `theme.json`. To change the look, edit the tokens at the top of `styles.css` — every page, the thumbnail and this guide read from them — and keep `theme.json` and the written guidance in step so they don't drift from what the CSS actually does.
|
||||||
|
|
||||||
|
## Direction
|
||||||
|
|
||||||
|
Modular grid layouts — content in equal-width cells, strong horizontal and vertical rhythm, visible structure. Use strong 2px dividers (`var(--color-divider)`) between major sections. Button labels are flush left — a button wider than its label starts the text at the left padding edge (trailing icon and all), never centered. Wrap hero and inline images in the `.grayscale` class — they print in pure black and white.
|
||||||
|
|
||||||
|
## Color
|
||||||
|
|
||||||
|
A light ground (`--color-bg` #f3f2f2) with `--color-text` #201e1d and a single accent #ec3013 (this is a mono scheme: no second accent was chosen — the `--color-accent-2-*` variables carry a machine-derived stand-in kept only so both sets resolve; treat them as one role). Each role carries a 100–900 tonal ramp (`--color-neutral-100` … `--color-accent-2-900`) generated in OKLCH on a shared perceptual lightness scale, so the same step of any ramp has the same visual weight. Use the light steps (100–300) for tinted fills, hovers and subtle borders, 500 as the role's base, and the dark steps (700–900) for text on tinted fills and for pressed states; prefer ramp steps over ad-hoc `color-mix()`. For elevation use `--shadow-sm/md/lg` (already tuned to the ground) rather than ad-hoc box-shadows.
|
||||||
|
|
||||||
|
## Type
|
||||||
|
|
||||||
|
Archivo for headings over Archivo for body text, loaded as `--font-heading` / `--font-body`. Density 1.00× and radius 0px are already baked into the `--space-*` / `--radius-*` scales — use the variables, not raw numbers.
|
||||||
|
|
||||||
|
## Icons
|
||||||
|
|
||||||
|
Use Lucide icons (https://lucide.dev) throughout.
|
||||||
|
|
||||||
|
## Interaction states
|
||||||
|
|
||||||
|
Interactive states are themed, never browser defaults: give every interactive element a `:hover` tint and a pressed state from the accent ramp (one step past the base — `--color-accent-600` on a light ground, `--color-accent-400` on a dark one, or a `color-mix()` tint for outlined/ghost variants), and style keyboard focus with `:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }` — never leave the default blue focus ring.
|
||||||
|
|
||||||
|
## Components
|
||||||
|
|
||||||
|
| Class | What it is | Shown in |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `.btn` with `.btn-primary`, `.btn-secondary`, `.btn-ghost`, `.btn-icon`, `.btn-block` | Actions — the primary is a solid accent fill | components/buttons.html |
|
||||||
|
| `.tag` with `.tag-accent`, `.tag-accent-2`, `.tag-neutral`, `.tag-outline` | Small labels tinted from the ramps (mono palette: accent-2 reads the same as accent) | components/buttons.html |
|
||||||
|
| `.field` + `label`, `.input`, `.radio` + `.dot`, `.seg` + `.seg-opt` | Form fields and choices on native elements — no script | components/forms.html |
|
||||||
|
| `.card` with `.card-kicker`, `.card-title`, `.card-body`, `.card-meta`; `.elev-sm/md/lg` | Surface-filled content cards; elevation utilities | components/cards.html |
|
||||||
|
| `.nav` + `.nav-brand` | The header bar | components/navigation.html |
|
||||||
|
| `.table` | Data tables with themed header and row rules | components/table.html |
|
||||||
|
| `.dialog-backdrop` + `.dialog` (+ `.dialog-title/-body/-actions`) | A modal at the top elevation | components/dialog.html |
|
||||||
|
| `.hr` | A strong 2px horizontal rule | foundations/layout.html |
|
||||||
|
| `.grayscale` | The image wrapper — every content photograph goes through it | foundations/image.html |
|
||||||
|
|
||||||
|
States are built in: hovers and pressed states come from the accent ramp, keyboard focus is the 2px accent `:focus-visible` ring, `::selection` is an accent tint, and disabled controls drop to 45% opacity. Don't restyle them per page. The accent-to-ground pair is tuned to at least 3:1 — enough for icons, large text and interface chrome, not for body copy — so for paragraph-size text in the accent use a deep ramp step (`--color-accent-700` on this ground) rather than the accent itself.
|
||||||
|
|
||||||
|
## Do
|
||||||
|
|
||||||
|
- Let the grid show: equal-width cells, strong horizontal rules between sections, visible structure.
|
||||||
|
- Keep everything flush left — headings, copy, and the labels inside wide buttons.
|
||||||
|
- Use the accent sparingly, for the primary action and small emphasis; the system is mostly ink on ground. The one place red runs as a field is the poster statement — the deck's section dividers and the landing's closing banner — where type stays display-grade and the accent carries the page.
|
||||||
|
- Print photographs in black and white with the `.grayscale` wrapper.
|
||||||
|
|
||||||
|
## Don't
|
||||||
|
|
||||||
|
- Do not round a corner anywhere — `--radius-md` is 0 on purpose.
|
||||||
|
- Do not center button labels or hero copy.
|
||||||
|
- Do not soften the rules into hairlines or drop them for whitespace.
|
||||||
|
- Do not tint or colorize imagery.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
- `styles.css` — the only stylesheet: the token sheet (`:root` variables, ramps, base type) plus the component layer. Link it from every page.
|
||||||
|
- `readme.md` — this guide.
|
||||||
|
- `theme.json` — the parameters these files were derived from (a machine-readable record of the theme).
|
||||||
|
- `thumbnail.html` — the project cover (brand mark + swatches).
|
||||||
|
- `foundations/type.html` — the type scale and the heading/body pairing at real sizes.
|
||||||
|
- `foundations/color.html` — color roles and the 100-900 tonal ramps, with usage notes.
|
||||||
|
- `foundations/layout.html` — the spacing scale, the grid and how edges are drawn.
|
||||||
|
- `foundations/icons.html` — the icon set at interface sizes, inline and in buttons.
|
||||||
|
- `foundations/image.html` — how photographs and figures are treated.
|
||||||
|
- `components/buttons.html` — buttons, icon buttons and tags in every variant and state.
|
||||||
|
- `components/forms.html` — text fields, radios and the segmented control on native elements.
|
||||||
|
- `components/cards.html` — content cards and the elevation steps.
|
||||||
|
- `components/navigation.html` — the header bar pattern.
|
||||||
|
- `components/table.html` — a data table with the themed header and row rules.
|
||||||
|
- `components/dialog.html` — a modal over its backdrop at the top elevation.
|
||||||
|
- `theme.html` — the theme's parameters rendered as a reference sheet.
|
||||||
|
- `templates/landing/` — a starter page consuming the system the intended way (`index.html`, its `ds-base.js` loader, and the vendored `image-slot.js` its photograph mounts).
|
||||||
|
- `assets/photo.jpg` — the reference photograph the imagery page treats.
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
/* Modernist — design-system tokens and component classes. This file is the source of truth for the system's look; retune it here and see readme.md. */
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;600;800&display=swap');
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--color-bg: #f3f2f2;
|
||||||
|
--color-surface: #eae9e9;
|
||||||
|
--color-text: #201e1d;
|
||||||
|
--color-accent: #ec3013;
|
||||||
|
--color-accent-2: #e15b47;
|
||||||
|
--color-divider: color-mix(in srgb, #201e1d 40%, transparent);
|
||||||
|
|
||||||
|
/* Tonal ramps — generated in OKLCH on one shared lightness scale, so the
|
||||||
|
same step of any role matches the others in visual value. */
|
||||||
|
--color-neutral-100: #f8f4f4;
|
||||||
|
--color-neutral-200: #eae7e7;
|
||||||
|
--color-neutral-300: #d7d3d3;
|
||||||
|
--color-neutral-400: #bab6b6;
|
||||||
|
--color-neutral-500: #9b9797;
|
||||||
|
--color-neutral-600: #7d7979;
|
||||||
|
--color-neutral-700: #605d5d;
|
||||||
|
--color-neutral-800: #444141;
|
||||||
|
--color-neutral-900: #2d2b2b;
|
||||||
|
|
||||||
|
--color-accent-100: #fff2ef;
|
||||||
|
--color-accent-200: #ffe0d9;
|
||||||
|
--color-accent-300: #ffc4b8;
|
||||||
|
--color-accent-400: #ff9783;
|
||||||
|
--color-accent-500: #ff563c;
|
||||||
|
--color-accent-600: #dd2b0f;
|
||||||
|
--color-accent-700: #ae1800;
|
||||||
|
--color-accent-800: #7c1405;
|
||||||
|
--color-accent-900: #4d170e;
|
||||||
|
|
||||||
|
--color-accent-2-100: #fff2ef;
|
||||||
|
--color-accent-2-200: #ffe0da;
|
||||||
|
--color-accent-2-300: #ffc4b9;
|
||||||
|
--color-accent-2-400: #ff9784;
|
||||||
|
--color-accent-2-500: #ef6853;
|
||||||
|
--color-accent-2-600: #c94b39;
|
||||||
|
--color-accent-2-700: #9e3526;
|
||||||
|
--color-accent-2-800: #71261b;
|
||||||
|
--color-accent-2-900: #471d16;
|
||||||
|
|
||||||
|
--font-heading: "Archivo", system-ui, sans-serif;
|
||||||
|
--font-heading-weight: 800;
|
||||||
|
--font-body: "Archivo", system-ui, sans-serif;
|
||||||
|
|
||||||
|
--space-1: 4.0px;
|
||||||
|
--space-2: 8.0px;
|
||||||
|
--space-3: 12.0px;
|
||||||
|
--space-4: 16.0px;
|
||||||
|
--space-6: 24.0px;
|
||||||
|
--space-8: 32.0px;
|
||||||
|
|
||||||
|
--radius-sm: 0px;
|
||||||
|
--radius-md: 0px;
|
||||||
|
--radius-lg: 0px;
|
||||||
|
|
||||||
|
/* Elevation — derived from the ground: soft ink-tinted shadows on a
|
||||||
|
light theme, a hairline edge + ambient darkness on a dark one. */
|
||||||
|
--shadow-sm: 0 1px 2px color-mix(in srgb, #2d2b2b 14%, transparent);
|
||||||
|
--shadow-md: 0 3px 10px color-mix(in srgb, #2d2b2b 16%, transparent);
|
||||||
|
--shadow-lg: 0 12px 32px color-mix(in srgb, #2d2b2b 22%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--color-bg);
|
||||||
|
color: var(--color-text);
|
||||||
|
font-family: var(--font-body);
|
||||||
|
}
|
||||||
|
h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: var(--font-heading-weight); }
|
||||||
|
|
||||||
|
.grayscale{filter:grayscale(1) contrast(1.08)}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════════════════════════════════
|
||||||
|
Components — built with the tokens above. Plain CSS
|
||||||
|
on plain HTML: no JavaScript, no build step. Each class is documented in
|
||||||
|
readme.md and demonstrated in foundations/ and components/.
|
||||||
|
══════════════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
*, *::before, *::after { box-sizing: border-box; }
|
||||||
|
body { margin: 0; font-size: 15px; line-height: 1.55; font-weight: 400; }
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
font-family: var(--font-heading); font-weight: var(--font-heading-weight);
|
||||||
|
line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 var(--space-2);
|
||||||
|
}
|
||||||
|
h1 { font-size: 42px; }
|
||||||
|
h2 { font-size: 32px; }
|
||||||
|
h3 { font-size: 25px; }
|
||||||
|
h4 { font-size: 20px; }
|
||||||
|
h5 { font-size: 16px; }
|
||||||
|
h6 { font-size: 13px; }
|
||||||
|
h6 { letter-spacing: 0.08em; text-transform: uppercase; }
|
||||||
|
p { margin: 0 0 var(--space-3); }
|
||||||
|
a { color: var(--color-accent); text-underline-offset: 3px; }
|
||||||
|
img { display: block; max-width: 100%; }
|
||||||
|
figure { margin: 0; }
|
||||||
|
figcaption {
|
||||||
|
font-size: 11px; margin-top: var(--space-1);
|
||||||
|
color: color-mix(in srgb, var(--color-text) 55%, transparent);
|
||||||
|
}
|
||||||
|
.text-muted { color: color-mix(in srgb, var(--color-text) 55%, transparent); }
|
||||||
|
:focus { outline: none; }
|
||||||
|
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
|
||||||
|
::selection { background: color-mix(in srgb, var(--color-accent) 30%, transparent); }
|
||||||
|
|
||||||
|
/* — rules — */
|
||||||
|
.hr {
|
||||||
|
height: 2px; border: 0; margin: var(--space-4) 0;
|
||||||
|
background: var(--color-divider);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* — buttons — */
|
||||||
|
.btn {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
||||||
|
cursor: pointer; text-decoration: none;
|
||||||
|
font-family: var(--font-heading); font-weight: var(--font-heading-weight);
|
||||||
|
font-size: 14px; line-height: 1.2; color: var(--color-text); /* matches the .input's 14px —
|
||||||
|
the pair sits side by side in sign-up rows */
|
||||||
|
background: transparent; border: 1px solid transparent;
|
||||||
|
padding: var(--space-2) calc(var(--space-3) * 1.2);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
}
|
||||||
|
.btn svg { display: block; }
|
||||||
|
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||||
|
.btn-primary { background: var(--color-accent); color: var(--color-bg); }
|
||||||
|
.btn-primary:hover { background: var(--color-accent-600); }
|
||||||
|
.btn-primary:active { background: var(--color-accent-700); }
|
||||||
|
.btn-secondary { border-color: var(--color-divider); }
|
||||||
|
.btn-secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
|
||||||
|
.btn-secondary:active { background: color-mix(in srgb, var(--color-text) 14%, transparent); }
|
||||||
|
.btn-ghost { color: var(--color-accent); padding-inline: var(--space-1); }
|
||||||
|
.btn-ghost:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
|
||||||
|
.btn-ghost:active { background: color-mix(in srgb, var(--color-accent) 18%, transparent); }
|
||||||
|
.btn-icon { width: 36px; height: 36px; padding: 0; }
|
||||||
|
.btn-block { width: 100%; margin-top: var(--space-2); justify-content: flex-start; text-align: left; }
|
||||||
|
|
||||||
|
/* — forms — */
|
||||||
|
.field > label {
|
||||||
|
display: block; font-size: 12px; margin-bottom: 5px;
|
||||||
|
color: color-mix(in srgb, var(--color-text) 70%, transparent);
|
||||||
|
}
|
||||||
|
.input {
|
||||||
|
width: 100%; min-height: 36px; padding: 6px 10px; font: inherit;
|
||||||
|
font-size: 14px; color: var(--color-text); caret-color: var(--color-accent);
|
||||||
|
background: var(--color-surface);
|
||||||
|
border: 1px solid var(--color-divider); border-radius: var(--radius-md);
|
||||||
|
}
|
||||||
|
.input:hover { border-color: color-mix(in srgb, var(--color-text) 45%, transparent); }
|
||||||
|
.input:focus-visible { border-color: var(--color-accent); outline-offset: 0; }
|
||||||
|
textarea.input { min-height: 90px; resize: vertical; }
|
||||||
|
.radio { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
|
||||||
|
.radio input, .seg-opt input {
|
||||||
|
position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
|
||||||
|
}
|
||||||
|
.radio .dot {
|
||||||
|
width: 16px; height: 16px; flex: none; border-radius: 50%;
|
||||||
|
border: 1.5px solid var(--color-divider);
|
||||||
|
}
|
||||||
|
.radio:hover .dot { border-color: var(--color-accent); }
|
||||||
|
.radio input:checked + .dot {
|
||||||
|
border-color: var(--color-accent); background: var(--color-accent);
|
||||||
|
box-shadow: inset 0 0 0 4px var(--color-bg);
|
||||||
|
}
|
||||||
|
.radio input:focus-visible + .dot { outline: 2px solid var(--color-accent); outline-offset: 2px; }
|
||||||
|
.seg {
|
||||||
|
display: inline-flex; overflow: hidden;
|
||||||
|
border: 1px solid var(--color-divider); border-radius: var(--radius-md);
|
||||||
|
}
|
||||||
|
.seg-opt {
|
||||||
|
display: inline-flex; align-items: center; gap: 6px;
|
||||||
|
padding: 7px 12px; font-size: 13px; cursor: pointer;
|
||||||
|
}
|
||||||
|
.seg-opt + .seg-opt { border-left: 1px solid var(--color-divider); }
|
||||||
|
.seg-opt:has(input:checked) { background: var(--color-accent); color: var(--color-bg); }
|
||||||
|
.seg-opt:not(:has(input:checked)):hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
|
||||||
|
.seg-opt:has(input:focus-visible) { outline: 2px solid var(--color-accent); outline-offset: -2px; }
|
||||||
|
|
||||||
|
/* — cards — */
|
||||||
|
.card {
|
||||||
|
display: flex; flex-direction: column; gap: var(--space-2);
|
||||||
|
padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface);
|
||||||
|
}
|
||||||
|
.card-kicker { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-accent); }
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-heading); font-weight: var(--font-heading-weight);
|
||||||
|
font-size: 17px; line-height: 1.2;
|
||||||
|
}
|
||||||
|
.card-body { margin: 0; font-size: 13px; opacity: 0.8; flex: 1; }
|
||||||
|
.card-meta {
|
||||||
|
display: flex; align-items: center; gap: 6px; font-size: 11px;
|
||||||
|
color: color-mix(in srgb, var(--color-text) 50%, transparent);
|
||||||
|
}
|
||||||
|
.elev-sm { box-shadow: var(--shadow-sm); }
|
||||||
|
.elev-md { box-shadow: var(--shadow-md); }
|
||||||
|
.elev-lg { box-shadow: var(--shadow-lg); }
|
||||||
|
|
||||||
|
/* — tags — */
|
||||||
|
.tag {
|
||||||
|
display: inline-flex; align-items: center; font-size: 11px;
|
||||||
|
letter-spacing: 0.02em; padding: 3px 10px;
|
||||||
|
border-radius: calc(var(--radius-md) * 0.75);
|
||||||
|
}
|
||||||
|
.tag-accent { background: var(--color-accent-100); color: var(--color-accent-800); }
|
||||||
|
.tag-accent-2 { background: var(--color-accent-2-100); color: var(--color-accent-2-800); }
|
||||||
|
.tag-neutral { background: var(--color-neutral-100); color: var(--color-neutral-800); }
|
||||||
|
.tag-outline { border: 1px solid var(--color-accent); color: var(--color-accent); }
|
||||||
|
|
||||||
|
/* — navigation — */
|
||||||
|
.nav {
|
||||||
|
display: flex; align-items: center; gap: var(--space-4);
|
||||||
|
padding: var(--space-3) var(--space-4);
|
||||||
|
border-bottom: 2px solid var(--color-divider);
|
||||||
|
}
|
||||||
|
.nav-brand {
|
||||||
|
font-family: var(--font-heading); font-weight: var(--font-heading-weight);
|
||||||
|
font-size: 18px; margin-right: auto;
|
||||||
|
}
|
||||||
|
.nav a { color: inherit; text-decoration: none; font-size: 14px; }
|
||||||
|
.nav a:hover, .nav a[aria-current='page'] { color: var(--color-accent); }
|
||||||
|
|
||||||
|
/* — tables — */
|
||||||
|
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
||||||
|
.table th {
|
||||||
|
text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
|
||||||
|
color: color-mix(in srgb, var(--color-text) 60%, transparent);
|
||||||
|
padding: var(--space-2); border-bottom: 2px solid var(--color-divider);
|
||||||
|
}
|
||||||
|
.table td {
|
||||||
|
padding: var(--space-2);
|
||||||
|
border-bottom: 1px solid var(--color-divider);
|
||||||
|
}
|
||||||
|
.table tbody tr:hover { background: color-mix(in srgb, var(--color-text) 4%, transparent); }
|
||||||
|
|
||||||
|
/* — dialog — */
|
||||||
|
.dialog-backdrop {
|
||||||
|
position: fixed; inset: 0; display: grid; place-items: center;
|
||||||
|
padding: var(--space-4);
|
||||||
|
background: color-mix(in srgb, var(--color-neutral-900) 50%, transparent);
|
||||||
|
}
|
||||||
|
.dialog {
|
||||||
|
width: min(440px, 100%); display: flex; flex-direction: column; gap: var(--space-3);
|
||||||
|
padding: var(--space-4); border-radius: var(--radius-lg);
|
||||||
|
background: var(--color-surface); box-shadow: var(--shadow-lg);
|
||||||
|
}
|
||||||
|
.dialog-title {
|
||||||
|
font-family: var(--font-heading); font-weight: var(--font-heading-weight);
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
.dialog-body { font-size: 14px; opacity: 0.85; }
|
||||||
|
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-2); }
|
||||||
|
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
# IMS Design System: Admin refresh
|
||||||
|
|
||||||
|
Source of truth for IMS UI. Derived from `IMS Admin Spec.dc.html` (patterns, tokens, states) and `IMS Admin.dc.html` (25 artboards: 7 desktop screens plus variants, 9 mobile screens). When this file and the mockups disagree, fix this file and say so in the PR. The earlier Modernist system (`design-system/_ds/`) is retired.
|
||||||
|
|
||||||
|
Rules in `CLAUDE.md` ("Design system") summarise this file. Tokens in `app/globals.css` mirror §2.
|
||||||
|
|
||||||
|
## 1. Principles
|
||||||
|
|
||||||
|
- Neutral commerce-admin look: grey ground, white cards, dark primary action, one teal accent used sparingly.
|
||||||
|
- Every list is a `TableCard` (§4.9). Do not hand-build tables.
|
||||||
|
- Status is always a dark text step on a light tint, with a text label (§4.2). Never white text on a saturated fill, never colour alone.
|
||||||
|
- Rules are 1px. Corners come from the radius scale in §2.3. Text and headings are flush left.
|
||||||
|
- Minimum hit target 44px on mobile.
|
||||||
|
|
||||||
|
## 2. Tokens
|
||||||
|
|
||||||
|
### 2.1 Colour
|
||||||
|
|
||||||
|
| Token | Hex | Use |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `ink` | `#1f1f1f` | Primary text, active sidebar text |
|
||||||
|
| `ink-2` | `#303030` | Primary button, chip text |
|
||||||
|
| `ink-3` | `#4a4a4a` | Secondary text, icons |
|
||||||
|
| `muted` | `#616161` | Labels, helper text |
|
||||||
|
| `faint` | `#8a8a8a` | Placeholders, input ring |
|
||||||
|
| `rule` | `#ebebeb` | Row rules, sidebar background |
|
||||||
|
| `rule-2` | `#e3e3e3` | Header rule, segmented background |
|
||||||
|
| `ring` | `#d4d4d4` | Secondary button and chip ring |
|
||||||
|
| `surface` | `#ffffff` | Cards, rows, inputs |
|
||||||
|
| `surface-2` | `#f7f7f7` | Table header, footer, row hover |
|
||||||
|
| `ground` | `#f1f1f1` | Page background |
|
||||||
|
| `accent` | `#0f766e` | Checks, links, focus ring, active tab icon |
|
||||||
|
| `accent-tint` | `#f2f7f6` | Selected row, selected card |
|
||||||
|
| `accent-tint-2` | `#e6f4f1` | Set filter chip (ring `#9fd3c7`, text `#0b4f47`) |
|
||||||
|
| `danger` | `#b3261e` | Overdue text, required marks, input error |
|
||||||
|
| `topbar` | `#1a1a1a` | App header (its controls use `#303030`, ring `#3d3d3d`, text `#a3a3a3`) |
|
||||||
|
|
||||||
|
Tailwind names: `bg-ground`, `bg-surface`, `bg-surface-2`, `text-ink`, `text-ink-2`, `text-ink-3`, `text-muted`, `text-faint`, `border-rule`, `border-rule-2`, `border-ring`, `bg-accent`, `text-accent`, `bg-accent-tint`, `bg-accent-tint-2`, `text-danger`, `bg-topbar`.
|
||||||
|
|
||||||
|
### 2.2 Type
|
||||||
|
|
||||||
|
Geist for UI, Geist Mono for references and keyboard hints. Exposed as `--font-geist` and `--font-geist-mono`.
|
||||||
|
|
||||||
|
| Spec | Use |
|
||||||
|
| --- | --- |
|
||||||
|
| 32 / 600 / -0.02em | Cover title |
|
||||||
|
| 22 / 650 / -0.02em | Mobile page title |
|
||||||
|
| 20 / 650 / -0.01em | Page title |
|
||||||
|
| 16 / 650 / -0.01em | Card title (detail) |
|
||||||
|
| 14 / 600 | Section heading |
|
||||||
|
| 13 / 400-550 | Body, table cells, buttons |
|
||||||
|
| 12 / 550 | Table header, pill, helper |
|
||||||
|
| 12.5 mono / 500 | References such as `IMS-2026-0247` |
|
||||||
|
|
||||||
|
### 2.3 Radius, shadow, spacing, icons
|
||||||
|
|
||||||
|
- **Radius:** 12 cards and phones; 10 mobile drawer and mobile inputs; 8 buttons, chips, inputs, pills, sidebar items; 6 avatars (24px); 5 checkbox; 999 badges. Tailwind: `rounded-md` = 8, `rounded-xl` = 12, `rounded-[5px]` checkbox.
|
||||||
|
- **Card shadow** (`shadow-card`): `0 0 0 1px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06)`.
|
||||||
|
- **Floating shadow** (`shadow-float`, bulk bar): `0 0 0 1px rgba(0,0,0,.1), 0 12px 32px rgba(0,0,0,.18)`. Drawer: `0 0 0 1px rgba(0,0,0,.1), 0 24px 60px rgba(0,0,0,.24)`.
|
||||||
|
- **Focus:** `outline: 2px solid accent; outline-offset: 2px` on every interactive element.
|
||||||
|
- **Spacing:** 4, 6, 8, 10, 12, 16, 20, 24, 32. Card padding 16-20, table cell 12, toolbar 10/12.
|
||||||
|
- **Icons:** Lucide. 16px stroke 2 in UI; 12px stroke 2.5 inside chips and checks; 22px stroke 1.8 in the mobile tab bar.
|
||||||
|
- **Motion:** transitions 120ms on background and shadow only.
|
||||||
|
|
||||||
|
## 3. Layout shell
|
||||||
|
|
||||||
|
**Desktop (`AppShell`)**
|
||||||
|
- Top bar 56px `topbar`: brand 224px (28px teal tile radius 8, "IMS", muted "Setia HSE"), search max 520px (34px, radius 10, shows a Cmd-K hint), bell and user chip on the right.
|
||||||
|
- Sidebar 240px `rule` background, 1px right border `#e0e0e0`, padding 12, items 32px radius 8, 13px. Active item: white, 1px ring, teal icon. Badges 999 `#dcdcdc`, 11px/600. Footer block has a 1px `#dcdcdc` top rule.
|
||||||
|
- Main: padding 24/32, column gap 16. Page title 20px/650 with actions on the right. Detail pages use `1fr` plus a 320-340px side rail.
|
||||||
|
- Page background `ground`; cards `surface`, radius 12, `shadow-card`.
|
||||||
|
|
||||||
|
**Mobile (`MobileShell`, reporter and CAPA owner)**
|
||||||
|
- 390px reference. Page title 22px/650, horizontal padding 16, card gap 12.
|
||||||
|
- Tab bar: white, 1px top rule, 3 items, 22px icons, 10.5px labels, active `accent`.
|
||||||
|
- Controls 48px tall, radius 12; primary button full width 48px. Footers sit on `ground` with a 1px top rule and 30px bottom safe area.
|
||||||
|
|
||||||
|
## 4. Components
|
||||||
|
|
||||||
|
Hover and active values below are per component. Every interactive element also gets the global focus ring (§2.3). Disabled controls drop to 45% opacity.
|
||||||
|
|
||||||
|
### 4.1 Button
|
||||||
|
- **Primary** 32px, radius 8, `#303030`, white 13px/600, inset highlight `inset 0 -1px 0 #000, inset 0 1px 0 rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.2)`. Hover `#1f1f1f`, active `#000`.
|
||||||
|
- **Secondary** white, 13px/550, ring `inset 0 0 0 1px #d4d4d4, 0 1px 0 rgba(0,0,0,.05)`. Hover `#f7f7f7`, active `#ebebeb`.
|
||||||
|
- **Icon** 28px ghost, radius 8, `ink-3`. Hover `#ebebeb`.
|
||||||
|
- Mobile primary: full width, 48px, radius 12.
|
||||||
|
|
||||||
|
### 4.2 StatusTag and PriorityTag
|
||||||
|
Pill: `inline-flex`, padding 2px 8px, radius 8, 12px/550, no wrap. Dark text on a light tint. Incident status and CAPA status share one palette.
|
||||||
|
|
||||||
|
| Label | Background | Text |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Reported | `#fff1c2` | `#6b4a00` |
|
||||||
|
| Triaged | `#e0efff` | `#00527c` |
|
||||||
|
| Investigating | `#ede7ff` | `#4b2e99` |
|
||||||
|
| CAPA pending | `#ffe6cf` | `#7a3a00` |
|
||||||
|
| Verification | `#e3e8ff` | `#2c3e8f` |
|
||||||
|
| Closed | `#d7f4e3` | `#0c5132` |
|
||||||
|
| Open | `#ebebeb` | `#4a4a4a` |
|
||||||
|
| In progress | `#e0efff` | `#00527c` |
|
||||||
|
| Overdue / Critical | `#fee3e0` | `#8e1f0b` |
|
||||||
|
| High | `#ffe6cf` | `#7a3a00` |
|
||||||
|
| Medium | `#fff1c2` | `#6b4a00` |
|
||||||
|
| Low | `#ebebeb` | `#4a4a4a` |
|
||||||
|
| Active | `#d7f4e3` | `#0c5132` |
|
||||||
|
| Verified | `#d7f4e3` | `#0c5132` |
|
||||||
|
| Reopened | `#fee3e0` | `#8e1f0b` |
|
||||||
|
|
||||||
|
Mapping from the data model: incident `reported/triaged/investigating/capa_pending/verification/closed` use the matching rows; CAPA `open/in_progress/overdue/pending_verification/verified/reopened/closed` map to Open, In progress, Overdue, Verification, Verified, Reopened, Closed; priority `high/med/low` map to High, Medium, Low. Severity 5 and Critical use the Overdue / Critical row. Tailwind: one pair per hue, `bg-st-<hue>-bg` / `text-st-<hue>-fg`, hue in `amber blue violet orange indigo green grey red`; `StatusTag` maps each status to a hue (reported amber, triaged blue, investigating violet, capa_pending orange, verification and pending_verification indigo, closed and verified green, open and low grey, in_progress blue, overdue and reopened red, high orange, med amber). Banners follow the same pairs: error red, warning or offline amber, success green; AI suggestions and hints use `bg-accent-tint`. No icon required; the text label is always present.
|
||||||
|
|
||||||
|
### 4.3 FilterChip
|
||||||
|
28px, radius 8, 12.5px, padding 0 10px. Unset: white, ring `#d4d4d4`, text `#303030`, trailing 12px chevron. Set: `accent-tint-2`, ring `#9fd3c7`, text `#0b4f47`, shows "Label: value" and a clear x.
|
||||||
|
|
||||||
|
### 4.4 Segmented
|
||||||
|
Container padding 2px, background `#e3e3e3`, radius 10. Option 13px, padding 5px 10px, radius 8. Active: white, 13px/600, `0 1px 2px rgba(0,0,0,.1)`. Used for List / Board.
|
||||||
|
|
||||||
|
### 4.5 Checkbox
|
||||||
|
16px, radius 5. Off: white with `inset 0 0 0 1.5px #8a8a8a`. On and indeterminate (header): `accent` fill, white 12px tick or minus at stroke 3.
|
||||||
|
|
||||||
|
### 4.6 Field and Input
|
||||||
|
Input 36px desktop, 48px mobile, padding 0 12px, radius 8 (12 on mobile), 13px, white. Rest ring `inset 0 0 0 1px #8a8a8a`; focus ring 2px `accent`; error ring `danger`. Placeholder `faint`. Label 12px `muted`, 5px above. Textarea and Select share the ring.
|
||||||
|
|
||||||
|
### 4.7 Avatar
|
||||||
|
24px, radius 6, background `#c5e8e0`, text `#0b4f47`, 11px/650, initials. Top bar variant sits in a `#303030` chip.
|
||||||
|
|
||||||
|
### 4.8 Card
|
||||||
|
White, radius 12, `shadow-card`, padding 16-20. Selected card uses `accent-tint`. Detail card title 16px/650.
|
||||||
|
|
||||||
|
### 4.9 TableCard
|
||||||
|
One component wraps every list. Parts top to bottom, all optional except the table and the card:
|
||||||
|
- **A. Saved views:** padding 8, bottom rule `#ebebeb`. View chip 28px radius 8, 13px; active `#e3e3e3` 13px/600 with a faint count (12px `#8a8a8a`); trailing + button opens "Save current filters as view". Saved views are server-side filters; counts update live.
|
||||||
|
- **B. Toolbar:** padding 10/12, bottom rule. Search 32px, radius 8, ring `#8a8a8a`, min-width 260. Filter chips (§4.3). Right-aligned actions.
|
||||||
|
- **C. Header:** `surface-2`, 12px/550 `muted`, padding 9/12, bottom rule `#e3e3e3`. Single-column sort: sorted column shows a filled arrow in `ink`, others a faint `#c4c4c4` double chevron.
|
||||||
|
- **D. Row rest:** white, 13px, cell padding 12, 1px `#ebebeb` rule. References in Geist Mono 12.5px in `accent`.
|
||||||
|
- **E. Row hover:** `surface-2`; quick actions (eye, more) appear on the right as 28px icon buttons.
|
||||||
|
- **F. Row selected:** `accent-tint` and a filled checkbox.
|
||||||
|
- **G. Footer:** `surface-2`, padding 10/16, "Showing 1-3 of 248" left, pager right (32px segmented chevrons, radius 8 on outer ends, ring `#d4d4d4`).
|
||||||
|
- **H. Bulk bar:** floats centred above the footer on first selection. White, radius 12, `shadow-float`, padding 6 6 6 12; checkbox, "N selected", divider, ghost actions (Assign, Export).
|
||||||
|
- **Empty state:** replaces thead and tbody: 64px icon tile, one line of copy, the primary action.
|
||||||
|
|
||||||
|
Behaviour: the whole row opens the record; the checkbox cell, links and quick actions stop propagation.
|
||||||
|
|
||||||
|
**Mobile:** below 768px the table becomes a stacked list in the same card: reference + status on line one, type and zone on line two, date on line three, chevron right. Saved views become horizontally scrolling 999px chips; filters collapse to one "Filter" button opening a sheet; the bulk bar becomes a bottom sheet.
|
||||||
|
|
||||||
|
### 4.10 Drawer
|
||||||
|
Notifications drawer: absolute, top/right/bottom 8px, width 420px, white, radius 14, shadow `0 0 0 1px rgba(0,0,0,.1), 0 24px 60px rgba(0,0,0,.24)`; scrim `rgba(0,0,0,.28)`. Header 16px/650 title with "Mark all read" (12.5px/550 `accent`), settings and close icon buttons. Tab row of 28px view chips with counts. Group labels 11.5px/600 uppercase `faint`. Items: 32px radius-9 icon tile, padding 12/16, rule `#f0f0f0`, unread items tinted.
|
||||||
|
|
||||||
|
## 5. Screen index
|
||||||
|
|
||||||
|
| Id | Screen | Route |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 01 | Incidents list | `/hse/incidents` |
|
||||||
|
| 01b | Notifications drawer | global |
|
||||||
|
| 02 | Incident detail | `/hse/incidents/[id]` |
|
||||||
|
| 02b | Triage form | `/hse/incidents/[id]` triage |
|
||||||
|
| 02c | Investigation form | `/hse/incidents/[id]` investigation |
|
||||||
|
| 02d | DOSH reporting (JKKP 6) | `/hse/incidents/[id]` new |
|
||||||
|
| 03 | Dashboard | `/hse/dashboard` |
|
||||||
|
| 04 | CAPA list | `/hse/capa` |
|
||||||
|
| 04b | CAPA board | `/hse/capa` board |
|
||||||
|
| 04c | CAPA detail, verification | `/hse/capa` new |
|
||||||
|
| 05 | Admin, users | `/admin` |
|
||||||
|
| 05b | Admin, sites and zones | `/admin` tab |
|
||||||
|
| 05c | Admin, trucks | `/admin` tab |
|
||||||
|
| 05d | Admin, audit log | `/admin` new tab |
|
||||||
|
| 06 | Settings, API keys | `/hse/settings` |
|
||||||
|
| 07 | Reporter, my reports | `/reporter` |
|
||||||
|
| 08 | Empty state | pattern |
|
||||||
|
| 09 | Mobile, reporter home | `/reporter` |
|
||||||
|
| 10 | Mobile, incidents | `/hse/incidents` |
|
||||||
|
| 11 | Mobile, incident detail | `/hse/incidents/[id]` |
|
||||||
|
| 12-15 | Mobile, new incident 1/3 to saved offline | `/report` |
|
||||||
|
| 16 | Mobile, CAPA owner action | `/capa-owner` |
|
||||||
|
|
||||||
|
Mockup features with no backend yet (do not fake them in the UI): CAPA export, bulk actions on a selection (send reminder, reassign, escalate), group-by, department and due-date range filters, the activity and comments feed, cost, evidence files on a CAPA, the verification note, "ask owner a question", and edit. Add them in a slice that also adds the backend.
|
||||||
|
|
||||||
|
New routes in the mockup that do not exist yet: audit log (05d), DOSH reporting entry (02d), and any "new tab" marked above. Treat them as separate features; do not build them as part of the restyle.
|
||||||
|
|
||||||
|
## 6. Accessibility
|
||||||
|
|
||||||
|
- Text on tints passes contrast because pills use dark steps. Body text is `ink` or `ink-3` on white or `ground`; `faint` is for placeholders only.
|
||||||
|
- Focus ring on every interactive element; nothing relies on colour alone.
|
||||||
|
- Hit targets 44px minimum on mobile.
|
||||||
|
|
||||||
|
## 7. Scope
|
||||||
|
|
||||||
|
This file covers look and component structure. Routes, queries, permissions and audit logging do not change as part of a restyle.
|
||||||
|
|
||||||
|
## 8. Build order
|
||||||
|
|
||||||
|
1. **Tokens:** replace the Modernist tokens in `app/globals.css` with §2 (`@theme static`), Geist via `next/font`, `shadow-card`, `shadow-float`, `st-*` pairs. Keep the `gray-*`/`blue-*`/`red-*` remaps pointing at the new neutral and teal values so unmigrated pages stay readable.
|
||||||
|
2. **UI primitives:** `Button`, `StatusTag`, `PriorityTag`, `Checkbox`, `Field`/`Input`/`Select`/`Textarea`, `FilterChip`, `Segmented`, `Avatar`, `Card`, `Drawer` in `components/ui/`.
|
||||||
|
3. **TableCard** (§4.9) with the desktop and mobile variants.
|
||||||
|
4. **Shells:** `AppShell` (top bar, sidebar, notifications drawer) and `MobileShell`.
|
||||||
|
5. **Migrate the Incidents list** (screen 01 and 10) as the first full screen.
|
||||||
|
6. **Remaining screens**, in §5 order, one plan per group.
|
||||||
|
|
||||||
|
Slice 1 (gate, tokens, primitives, TableCard, shells, Incidents list) and slice 2 (CAPA list, board, detail, verification, create form) are implemented; the remaining screens follow in later plans.
|
||||||
|
|
||||||
|
Gate first: before step 1, update `scripts/check-design-gates.mjs` to allow `rounded-*`, flag `border-b-2` and `border-2`, and flag Archivo and `#ec3013`. `npm run check:design` must pass at the end of each step.
|
||||||
|
|
||||||
|
## 9. What changes from the live Modernist build
|
||||||
|
|
||||||
|
| Area | Now (Modernist) | After |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Font | Archivo | Geist and Geist Mono |
|
||||||
|
| Accent | `#ec3013` red | `#0f766e` teal (used sparingly) |
|
||||||
|
| Primary button | red, flush left | `#303030`, 32px, radius 8 |
|
||||||
|
| Radius | 0 everywhere | 8 / 10 / 12 scale |
|
||||||
|
| Rules | 2px section rules | 1px |
|
||||||
|
| Status | mono tags (accent, outline, neutral) | coloured pills (§4.2) |
|
||||||
|
| Sidebar | flat, 2px rule | dark top bar plus `#ebebeb` sidebar |
|
||||||
|
| Lists | per-page tables | `TableCard` |
|
||||||
|
| Gate | no rounded, 2px rules | rounded allowed, 2px flagged |
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,117 @@
|
|||||||
|
# Modernist Design System Restyle
|
||||||
|
|
||||||
|
**Date:** 2026-09-30
|
||||||
|
**Status:** Approved
|
||||||
|
**Goal:** Restyle the whole IMS app to the Modernist design system in `design-system/_ds/modernist-*/`, and record the guidelines so future development follows them.
|
||||||
|
|
||||||
|
## Decisions
|
||||||
|
|
||||||
|
- **Governing source:** Modernist (`design-system/_ds/modernist-6062679c-a4aa-42a4-9043-28fea370dda9/readme.md` and `styles.css`). `design-system/IMS Admin.dc.html` (Geist, teal, 12px radius) is superseded and is not implemented. Its screen structure is out of scope for this pass.
|
||||||
|
- **Scope:** Whole app in one pass: tokens and base styles, shared shell, then every page (login, reporter, HSE, supervisor, management, capa-owner, admin).
|
||||||
|
- **Approach:** Remap Tailwind v4 tokens to Modernist so the existing utility classes restyle automatically, then add a thin set of shared components where token remapping leaves the markup structurally wrong.
|
||||||
|
|
||||||
|
## Current state
|
||||||
|
|
||||||
|
- Tailwind v4 (`@import "tailwindcss"` and `@theme inline` in `app/globals.css`), 62 TSX files with `className`.
|
||||||
|
- Utility usage: 522 `gray-*`, 120 `blue-*`, 219 `rounded*`, 57 `shadow*`.
|
||||||
|
- Semantic colors in use: red (errors, overdue), green (done, verified), purple, yellow, orange (workflow statuses, priorities).
|
||||||
|
- Font: Geist and Geist Mono via `next/font/google` in `app/layout.tsx`.
|
||||||
|
- Icons: inline SVG, `lucide-react` is not installed.
|
||||||
|
- Shared UI: `components/ui/modal.tsx` (rounded-2xl, gray-900/50 backdrop), `components/layout/sidebar.tsx`.
|
||||||
|
|
||||||
|
## Design
|
||||||
|
|
||||||
|
### 1. Tokens (`app/globals.css`)
|
||||||
|
|
||||||
|
Copy the Modernist `:root` variables verbatim from `styles.css` (colors, neutral and accent ramps, fonts, spacing, radius, shadows). Do not hard-code hex values elsewhere.
|
||||||
|
|
||||||
|
Expose them to Tailwind through `@theme`:
|
||||||
|
|
||||||
|
- `--color-gray-50…900` map to `--color-neutral-100…900` (nearest step). Existing `gray-*` classes then render on the Modernist neutral ramp.
|
||||||
|
- `--color-blue-50…900` map to `--color-accent-100…900`. Existing `blue-*` classes then render as the red accent (primary buttons, links, focus).
|
||||||
|
- `--radius-*` (`sm`, `md`, `lg`, `xl`, `2xl`, `3xl`) are set to `0`. `rounded-full` is left alone, so circular avatars and radio dots stay round.
|
||||||
|
- Shadows: remap `shadow-sm/md/lg` to `--shadow-sm/md/lg`. `shadow-xl` and `shadow-2xl` are replaced with `shadow-lg`.
|
||||||
|
- `--font-sans` and `--font-heading` are set to Archivo (400, 600, 800). Remove Geist, and Geist Mono stays only if monospace is used anywhere.
|
||||||
|
|
||||||
|
Base layer (from `styles.css`): body uses `--color-bg` and `--color-text` at 15px/1.55, headings use Archivo 800 with the Modernist scale, `a` uses the accent, `:focus-visible` is a 2px accent outline with 2px offset, `::selection` is an accent tint, disabled controls drop to 45% opacity. Remove the `prefers-color-scheme: dark` block: Modernist defines only a light ground.
|
||||||
|
|
||||||
|
Fix `app/globals.css` input colors (`#111827`, `#6b7280`) to use `--color-text` and a 55% text mix.
|
||||||
|
|
||||||
|
### 2. Shared components (`components/ui/`)
|
||||||
|
|
||||||
|
Each takes Modernist tokens only and carries the markup rules Tailwind remapping cannot:
|
||||||
|
|
||||||
|
| Component | Rules |
|
||||||
|
| --- | --- |
|
||||||
|
| `Button` (`primary`, `secondary`, `ghost`, `icon`, `block`) | Archivo 800 14px, flush-left label even when wide, primary is solid accent with `accent-600` hover and `accent-700` pressed. Secondary is a 1px divider border. |
|
||||||
|
| `Tag` (`accent`, `neutral`, `outline`) | 11px, 3px 10px padding, no radius. Used for statuses and priorities. |
|
||||||
|
| `Field` and `Input` | 12px label above, 36px min height, surface fill, 1px divider border, accent border on focus. |
|
||||||
|
| `Card` | Surface fill, 12px padding, no border, no radius, optional `kicker`, `title`, `meta`. |
|
||||||
|
| `DataTable` styles | Uppercase 11px header with a 2px divider under it, 1px row rules, 4% text-tint row hover. |
|
||||||
|
| `Modal` (existing) | Restyle to `.dialog`: surface fill, 0 radius, `--shadow-lg`, neutral-900/50 backdrop, title uses Archivo 800 20px, Lucide `X` for close. |
|
||||||
|
|
||||||
|
Existing pages keep their own markup where the remapped utilities already render correctly. Migrate a page to these components only when its markup needs a structural change (for example centered button labels, rounded chips, hairline dividers).
|
||||||
|
|
||||||
|
### 3. Shell
|
||||||
|
|
||||||
|
- **Sidebar:** flat surface, 2px right rule in `--color-divider`, brand in Archivo 800, nav items flush left with Lucide icons, active item in accent, version label kept at the bottom.
|
||||||
|
- **Mobile bottom nav:** 2px top rule, same active treatment.
|
||||||
|
- **Notification bell:** square button with a 1px divider border (was a round white button).
|
||||||
|
- **Section dividers:** use `.hr` (2px) between major sections, not whitespace or hairlines.
|
||||||
|
|
||||||
|
### 4. Icons
|
||||||
|
|
||||||
|
Install `lucide-react` and replace the inline SVGs in the sidebar, modal, nav, and buttons with Lucide equivalents. Default 16 to 20px, stroke 2.
|
||||||
|
|
||||||
|
### 5. Imagery
|
||||||
|
|
||||||
|
Add the `grayscale` class (`filter: grayscale(1) contrast(1.08)`) for decorative or brand photography only. Incident evidence photos and thumbnails stay in full color, because color can carry evidence (spill color, burns, signage). Decided 2026-09-30.
|
||||||
|
|
||||||
|
### 6. Status and priority colors (design decision)
|
||||||
|
|
||||||
|
Modernist is near-mono with one accent, so the current red, green, purple, yellow and orange status chips cannot all survive. Proposed mapping:
|
||||||
|
|
||||||
|
| Meaning | Treatment |
|
||||||
|
| --- | --- |
|
||||||
|
| Needs attention or overdue, open, reported, severity 4 to 5, errors | `tag-accent` (red tint), red text for inline errors |
|
||||||
|
| In progress (triaged, investigating, CAPA pending, verification) | `tag-outline` (accent outline) |
|
||||||
|
| Done (closed, verified, completed) | `tag-neutral` |
|
||||||
|
| Low priority or informational | `tag-neutral` |
|
||||||
|
|
||||||
|
Status is never conveyed by color alone: every tag keeps its text label, and the workflow states gain a Lucide icon. One central `StatusTag` and `PriorityTag` component replaces the scattered `STATUS_COLORS` and `PRIORITY_COLORS` maps (used in `capa-board.tsx`, `incident-list.tsx`, `incident-header.tsx`, `incident-detail.tsx`, and the reporter, supervisor and capa-owner pages).
|
||||||
|
|
||||||
|
### 7. Out of scope
|
||||||
|
|
||||||
|
- The IMS Admin mockup layouts (index tables with saved views, filter chips, bulk select).
|
||||||
|
- Dark mode.
|
||||||
|
- Data, API, auth or routing changes.
|
||||||
|
- Email templates and the generated PDFs (JKKP 6/7/8, incident report). They keep their own styling.
|
||||||
|
|
||||||
|
## Documentation and memory
|
||||||
|
|
||||||
|
- Add a "Design system" section to `CLAUDE.md`: Modernist is the source of truth, use tokens and never hard-code hex or px, 0 radius, flush-left labels, 2px rules, Lucide icons, `grayscale` imagery, status via `StatusTag` and `PriorityTag`.
|
||||||
|
- Save a memory file `ims-design-system.md` (type `reference`) pointing at `design-system/_ds/modernist-*/readme.md` and recording these rules and the status-color mapping, then add it to `MEMORY.md`.
|
||||||
|
|
||||||
|
## Testing and verification
|
||||||
|
|
||||||
|
- `next build` passes with no type errors. The vitest suite still passes. Only tests asserting old class names need updating.
|
||||||
|
- Run the app locally and check each role's pages in a browser: login, reporter report form and list, HSE inbox, incident detail, CAPA board, supervisor, management dashboard, admin users and settings. Check desktop and mobile widths.
|
||||||
|
- Grep gates after migration: no `rounded-(sm|md|lg|xl|2xl|3xl)` left in app/ or components/ apart from deliberate exceptions, no hard-coded hex in TSX, no `text-center` on button labels.
|
||||||
|
- Keyboard: every interactive element shows the 2px accent focus ring.
|
||||||
|
- Contrast: body copy in accent uses `accent-700`, not the accent itself (accent on ground is 3:1, so chrome only).
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
A build-only deploy per the IMS deployment procedure (`/srv/apps/ims/app`, never build on the server, keep `.next/BUILD_ID` and `.next/static` in place). No database changes.
|
||||||
|
|
||||||
|
## Risks
|
||||||
|
|
||||||
|
- **Remapping `blue-*` to red** can make unrelated blue uses (links, info banners) read as errors. Review every `blue-*` site (120 uses) and switch informational ones to neutral.
|
||||||
|
- **Status legibility:** removing green and purple makes states less scannable. Icons plus labels mitigate this, and the mapping above needs your sign-off.
|
||||||
|
- **Archivo 800 headings** are wider than Geist and can overflow narrow table headers and mobile nav labels. Check at 360px.
|
||||||
|
- **Visual diff is large** (62 files of class changes), so review in a browser, not only via the diff.
|
||||||
|
|
||||||
|
## Resolved decisions
|
||||||
|
|
||||||
|
1. Status mapping in section 6 is approved as written. Green is not kept for "closed/verified".
|
||||||
|
2. Evidence photos are exempt from grayscale (section 5).
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
export type CapaStatus =
|
||||||
|
| 'open' | 'in_progress' | 'overdue' | 'pending_verification' | 'verified' | 'reopened' | 'closed'
|
||||||
|
export type CapaPriority = 'low' | 'med' | 'high'
|
||||||
|
|
||||||
|
export interface CapaRow {
|
||||||
|
id: string
|
||||||
|
incident_id: string
|
||||||
|
description: string
|
||||||
|
department: string
|
||||||
|
due_date: string
|
||||||
|
priority: CapaPriority
|
||||||
|
status: CapaStatus
|
||||||
|
incident_ref: string | null
|
||||||
|
owner_name: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PAGE_SIZE = 25
|
||||||
|
|
||||||
|
export const STATUS_ORDER: CapaStatus[] = [
|
||||||
|
'open', 'in_progress', 'overdue', 'reopened', 'pending_verification', 'verified', 'closed',
|
||||||
|
]
|
||||||
|
|
||||||
|
export type CapaViewKey = 'all' | 'active' | 'overdue' | 'verification' | 'done'
|
||||||
|
|
||||||
|
export const VIEWS: Array<{ key: CapaViewKey; label: string; statuses: CapaStatus[] | null }> = [
|
||||||
|
{ key: 'all', label: 'All', statuses: null },
|
||||||
|
{ key: 'active', label: 'Active', statuses: ['open', 'in_progress', 'reopened'] },
|
||||||
|
{ key: 'overdue', label: 'Overdue', statuses: ['overdue'] },
|
||||||
|
{ key: 'verification', label: 'Verification', statuses: ['pending_verification'] },
|
||||||
|
{ key: 'done', label: 'Done', statuses: ['verified', 'closed'] },
|
||||||
|
]
|
||||||
|
|
||||||
|
export interface CapaFilters {
|
||||||
|
q: string
|
||||||
|
owner: string
|
||||||
|
department: string
|
||||||
|
priority: string
|
||||||
|
view: CapaViewKey
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EMPTY_FILTERS: CapaFilters = { q: '', owner: '', department: '', priority: '', view: 'all' }
|
||||||
|
|
||||||
|
export type CapaSortKey = 'due_date' | 'priority' | 'status'
|
||||||
|
export type CapaSort = { key: CapaSortKey; dir: 'asc' | 'desc' }
|
||||||
|
|
||||||
|
function matchesOthers(r: CapaRow, f: CapaFilters): boolean {
|
||||||
|
if (f.owner && r.owner_name !== f.owner) return false
|
||||||
|
if (f.department && r.department !== f.department) return false
|
||||||
|
if (f.priority && r.priority !== f.priority) return false
|
||||||
|
if (f.q) {
|
||||||
|
const q = f.q.toLowerCase()
|
||||||
|
const hay = `${r.description} ${r.incident_ref ?? ''} ${r.owner_name ?? ''}`.toLowerCase()
|
||||||
|
if (!hay.includes(q)) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function inView(r: CapaRow, view: CapaViewKey): boolean {
|
||||||
|
const statuses = VIEWS.find(v => v.key === view)?.statuses ?? null
|
||||||
|
return statuses === null || statuses.includes(r.status)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function filterCapas(rows: CapaRow[], f: CapaFilters): CapaRow[] {
|
||||||
|
return rows.filter(r => matchesOthers(r, f) && inView(r, f.view))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function viewCounts(rows: CapaRow[], f: CapaFilters): Record<CapaViewKey, number> {
|
||||||
|
const scoped = rows.filter(r => matchesOthers(r, f))
|
||||||
|
const counts = {} as Record<CapaViewKey, number>
|
||||||
|
for (const v of VIEWS) counts[v.key] = scoped.filter(r => inView(r, v.key)).length
|
||||||
|
return counts
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRIORITY_RANK: Record<CapaPriority, number> = { high: 0, med: 1, low: 2 }
|
||||||
|
|
||||||
|
export function sortCapas(rows: CapaRow[], sort: CapaSort): CapaRow[] {
|
||||||
|
const sign = sort.dir === 'asc' ? 1 : -1
|
||||||
|
const key = (r: CapaRow): number | string =>
|
||||||
|
sort.key === 'priority' ? PRIORITY_RANK[r.priority]
|
||||||
|
: sort.key === 'status' ? STATUS_ORDER.indexOf(r.status)
|
||||||
|
: r.due_date
|
||||||
|
return [...rows].sort((a, b) => {
|
||||||
|
const ka = key(a)
|
||||||
|
const kb = key(b)
|
||||||
|
return ka < kb ? -sign : ka > kb ? sign : 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function nextSort(current: CapaSort, key: CapaSortKey): CapaSort {
|
||||||
|
if (current.key === key) return { key, dir: current.dir === 'asc' ? 'desc' : 'asc' }
|
||||||
|
return { key, dir: 'asc' }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function paginate<T>(rows: T[], page: number, size: number) {
|
||||||
|
const total = rows.length
|
||||||
|
const pageCount = Math.max(1, Math.ceil(total / size))
|
||||||
|
const p = Math.min(Math.max(1, page), pageCount)
|
||||||
|
const items = rows.slice((p - 1) * size, p * size)
|
||||||
|
const from = items.length === 0 ? 0 : (p - 1) * size + 1
|
||||||
|
const to = items.length === 0 ? 0 : from + items.length - 1
|
||||||
|
return { items, from, to, total, page: p, pageCount }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function distinct(values: Array<string | null | undefined>): string[] {
|
||||||
|
return [...new Set(values.filter((v): v is string => Boolean(v)))].sort()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function daysLate(due: string, today: string): number {
|
||||||
|
const diff = Math.round((Date.parse(today) - Date.parse(due)) / 86_400_000)
|
||||||
|
return Math.max(0, diff)
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@ describe('analyzePdfsWithDeepSeek', () => {
|
|||||||
const metadata = await analyzePdfsWithDeepSeek(pdfTexts)
|
const metadata = await analyzePdfsWithDeepSeek(pdfTexts)
|
||||||
expect(metadata.description).toBeDefined()
|
expect(metadata.description).toBeDefined()
|
||||||
expect(metadata.date).toBeDefined()
|
expect(metadata.date).toBeDefined()
|
||||||
expect(metadata.location.site).toBeDefined()
|
expect(metadata.location?.site).toBeDefined()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
export const PAGE_SIZE = 25
|
||||||
|
export const OPEN_STATUSES = ['reported', 'triaged', 'investigating', 'capa_pending', 'verification'] as const
|
||||||
|
|
||||||
|
export type SortKey = 'reported_at' | 'reference_no' | 'status'
|
||||||
|
export type ListView = 'all' | 'open' | 'closed'
|
||||||
|
|
||||||
|
export interface ListParams {
|
||||||
|
page: number
|
||||||
|
q: string
|
||||||
|
status: string
|
||||||
|
type: string
|
||||||
|
siteId: string
|
||||||
|
truckId: string
|
||||||
|
view: ListView
|
||||||
|
sort: SortKey
|
||||||
|
dir: 'asc' | 'desc'
|
||||||
|
}
|
||||||
|
|
||||||
|
type Raw = {
|
||||||
|
page?: string; q?: string; status?: string; type?: string; site_id?: string; truck_id?: string
|
||||||
|
view?: string; sort?: string; dir?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const SORT_KEYS: SortKey[] = ['reported_at', 'reference_no', 'status']
|
||||||
|
const VIEWS: ListView[] = ['all', 'open', 'closed']
|
||||||
|
|
||||||
|
export function parseListParams(raw: Raw): ListParams {
|
||||||
|
const page = Number.parseInt(raw.page ?? '1', 10)
|
||||||
|
return {
|
||||||
|
page: Number.isFinite(page) && page > 0 ? page : 1,
|
||||||
|
q: raw.q ?? '',
|
||||||
|
status: raw.status ?? '',
|
||||||
|
type: raw.type ?? '',
|
||||||
|
siteId: raw.site_id ?? '',
|
||||||
|
truckId: raw.truck_id ?? '',
|
||||||
|
view: VIEWS.includes(raw.view as ListView) ? (raw.view as ListView) : 'all',
|
||||||
|
sort: SORT_KEYS.includes(raw.sort as SortKey) ? (raw.sort as SortKey) : 'reported_at',
|
||||||
|
dir: raw.dir === 'asc' ? 'asc' : 'desc',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function nextSort(
|
||||||
|
current: { key: SortKey; dir: 'asc' | 'desc' },
|
||||||
|
key: SortKey,
|
||||||
|
): { key: SortKey; dir: 'asc' | 'desc' } {
|
||||||
|
if (current.key === key) return { key, dir: current.dir === 'asc' ? 'desc' : 'asc' }
|
||||||
|
return { key, dir: key === 'reported_at' ? 'desc' : 'asc' }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function withParams(search: string, updates: Record<string, string | null>): string {
|
||||||
|
const p = new URLSearchParams(search)
|
||||||
|
for (const [k, v] of Object.entries(updates)) {
|
||||||
|
if (v) p.set(k, v)
|
||||||
|
else p.delete(k)
|
||||||
|
}
|
||||||
|
if (!('page' in updates)) p.delete('page')
|
||||||
|
const s = p.toString()
|
||||||
|
return s ? `?${s}` : ''
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { and, asc, desc, eq, ilike, inArray, or, sql, aliasedTable } from 'drizzle-orm'
|
||||||
|
import { asAdmin } from '@/lib/db/with-user'
|
||||||
|
import { incidents, sites, trucks, users, zones } from '@/lib/db/schema'
|
||||||
|
import { OPEN_STATUSES, PAGE_SIZE, type ListParams } from './list-params'
|
||||||
|
import type { Incident, SiteOption, TruckOption } from './types'
|
||||||
|
|
||||||
|
export interface IncidentListData {
|
||||||
|
incidents: Incident[]
|
||||||
|
total: number
|
||||||
|
counts: { all: number; open: number; closed: number }
|
||||||
|
sites: SiteOption[]
|
||||||
|
trucks: TruckOption[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadIncidentList(p: ListParams): Promise<IncidentListData> {
|
||||||
|
const reporter = aliasedTable(users, 'reporter')
|
||||||
|
|
||||||
|
const base = []
|
||||||
|
if (p.q) base.push(or(ilike(incidents.referenceNo, `%${p.q}%`), ilike(incidents.description, `%${p.q}%`)))
|
||||||
|
if (p.type) base.push(eq(incidents.incidentType, p.type as never))
|
||||||
|
if (p.siteId) base.push(eq(incidents.siteId, p.siteId))
|
||||||
|
if (p.truckId) base.push(eq(incidents.truckId, p.truckId))
|
||||||
|
|
||||||
|
const scoped = [...base]
|
||||||
|
if (p.status) scoped.push(eq(incidents.status, p.status as never))
|
||||||
|
if (p.view === 'open') scoped.push(inArray(incidents.status, [...OPEN_STATUSES] as never))
|
||||||
|
if (p.view === 'closed') scoped.push(eq(incidents.status, 'closed' as never))
|
||||||
|
|
||||||
|
const where = scoped.length ? and(...scoped) : undefined
|
||||||
|
const baseWhere = base.length ? and(...base) : undefined
|
||||||
|
|
||||||
|
const sortColumn = { reported_at: incidents.reportedAt, reference_no: incidents.referenceNo, status: incidents.status }[p.sort]
|
||||||
|
const orderBy = p.dir === 'asc' ? asc(sortColumn) : desc(sortColumn)
|
||||||
|
|
||||||
|
const [[countRow], rows, statusCounts, siteRows, truckRows] = await Promise.all([
|
||||||
|
asAdmin(db => db.select({ count: sql<number>`count(*)` }).from(incidents).where(where)),
|
||||||
|
asAdmin(db =>
|
||||||
|
db.select({
|
||||||
|
id: incidents.id,
|
||||||
|
referenceNo: incidents.referenceNo,
|
||||||
|
incidentType: incidents.incidentType,
|
||||||
|
status: incidents.status,
|
||||||
|
severity: incidents.severity,
|
||||||
|
reportedAt: incidents.reportedAt,
|
||||||
|
siteName: sites.name,
|
||||||
|
zoneName: zones.name,
|
||||||
|
reporterName: reporter.name,
|
||||||
|
truckNo: trucks.truckNo,
|
||||||
|
})
|
||||||
|
.from(incidents)
|
||||||
|
.leftJoin(sites, eq(incidents.siteId, sites.id))
|
||||||
|
.leftJoin(zones, eq(incidents.zoneId, zones.id))
|
||||||
|
.leftJoin(reporter, eq(incidents.reportedBy, reporter.id))
|
||||||
|
.leftJoin(trucks, eq(incidents.truckId, trucks.id))
|
||||||
|
.where(where)
|
||||||
|
.orderBy(orderBy)
|
||||||
|
.limit(PAGE_SIZE)
|
||||||
|
.offset((p.page - 1) * PAGE_SIZE)
|
||||||
|
),
|
||||||
|
asAdmin(db =>
|
||||||
|
db.select({ status: incidents.status, count: sql<number>`count(*)` })
|
||||||
|
.from(incidents)
|
||||||
|
.where(baseWhere)
|
||||||
|
.groupBy(incidents.status)
|
||||||
|
),
|
||||||
|
asAdmin(db => db.select({ id: sites.id, name: sites.name }).from(sites).orderBy(asc(sites.name))),
|
||||||
|
asAdmin(db =>
|
||||||
|
db.select({ id: trucks.id, truckNo: trucks.truckNo })
|
||||||
|
.from(trucks)
|
||||||
|
.where(eq(trucks.active, true))
|
||||||
|
.orderBy(asc(trucks.truckNo))
|
||||||
|
),
|
||||||
|
])
|
||||||
|
|
||||||
|
const byStatus = new Map(statusCounts.map(r => [r.status as string, Number(r.count)]))
|
||||||
|
const all = [...byStatus.values()].reduce((a, b) => a + b, 0)
|
||||||
|
const open = OPEN_STATUSES.reduce((sum, s) => sum + (byStatus.get(s) ?? 0), 0)
|
||||||
|
|
||||||
|
return {
|
||||||
|
incidents: rows.map(r => ({
|
||||||
|
id: r.id,
|
||||||
|
reference_no: r.referenceNo,
|
||||||
|
incident_type: r.incidentType,
|
||||||
|
status: r.status,
|
||||||
|
severity: r.severity,
|
||||||
|
reported_at: r.reportedAt.toISOString(),
|
||||||
|
sites: r.siteName ? { name: r.siteName } : null,
|
||||||
|
zones: r.zoneName ? { name: r.zoneName } : null,
|
||||||
|
trucks: r.truckNo ? { truck_no: r.truckNo } : null,
|
||||||
|
reporter: r.reporterName ? { name: r.reporterName } : null,
|
||||||
|
})),
|
||||||
|
total: Number(countRow?.count ?? 0),
|
||||||
|
counts: { all, open, closed: byStatus.get('closed') ?? 0 },
|
||||||
|
sites: siteRows.map(s => ({ id: s.id, name: s.name })),
|
||||||
|
trucks: truckRows.map(t => ({ id: t.id, truck_no: t.truckNo })),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export type Incident = {
|
||||||
|
id: string
|
||||||
|
reference_no: string | null
|
||||||
|
incident_type: string
|
||||||
|
status: string
|
||||||
|
severity: number | null
|
||||||
|
reported_at: string
|
||||||
|
sites: { name: string } | null
|
||||||
|
zones: { name: string } | null
|
||||||
|
trucks: { truck_no: string } | null
|
||||||
|
reporter: { name: string } | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SiteOption { id: string; name: string }
|
||||||
|
export interface TruckOption { id: string; truck_no: string }
|
||||||
+1
-1
@@ -47,5 +47,5 @@ export async function middleware(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
|
matcher: ['/((?!_next/static|_next/image|favicon.ico|manifest\\.json$|sw\\.js$|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+18
-2
@@ -16,6 +16,7 @@
|
|||||||
"file-type": "^22.0.1",
|
"file-type": "^22.0.1",
|
||||||
"idb": "^8.0.3",
|
"idb": "^8.0.3",
|
||||||
"jose": "^6.2.4",
|
"jose": "^6.2.4",
|
||||||
|
"lucide-react": "^1.49.0",
|
||||||
"next": "^16.3.7",
|
"next": "^16.3.7",
|
||||||
"openai": "^6.46.0",
|
"openai": "^6.46.0",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
@@ -3226,7 +3227,7 @@
|
|||||||
"version": "19.2.17",
|
"version": "19.2.17",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.17.tgz",
|
||||||
"integrity": "sha512-MXfmqaVPEVgkBT/aY0aGCkRWWtByiYQXo3xdQ8r5RzuFrPiRn8Gar2tQdXSUQ2GKV3bkXckek89V8wQBY2Q/Aw==",
|
"integrity": "sha512-MXfmqaVPEVgkBT/aY0aGCkRWWtByiYQXo3xdQ8r5RzuFrPiRn8Gar2tQdXSUQ2GKV3bkXckek89V8wQBY2Q/Aw==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"csstype": "^3.2.2"
|
"csstype": "^3.2.2"
|
||||||
@@ -4681,7 +4682,7 @@
|
|||||||
"version": "3.2.3",
|
"version": "3.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||||
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/d": {
|
"node_modules/d": {
|
||||||
@@ -8169,6 +8170,21 @@
|
|||||||
"es5-ext": "~0.10.2"
|
"es5-ext": "~0.10.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/lucide-react": {
|
||||||
|
"version": "1.49.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.49.0.tgz",
|
||||||
|
"integrity": "sha512-ApfaNM4/7jBrVopqLJ84Jz8TMQ1Q1JeZ1PmKh25aeS3E1FTVcMkSh1bEQB7dfzdIrwXRP8p3z4AJjTIHHb5IIA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "*",
|
||||||
|
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/lz-string": {
|
"node_modules/lz-string": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",
|
||||||
|
|||||||
+3
-1
@@ -9,7 +9,8 @@
|
|||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"generate-qr": "tsx scripts/generate-qr.ts"
|
"generate-qr": "tsx scripts/generate-qr.ts",
|
||||||
|
"check:design": "node scripts/check-design-gates.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "^0.111.0",
|
"@anthropic-ai/sdk": "^0.111.0",
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
"file-type": "^22.0.1",
|
"file-type": "^22.0.1",
|
||||||
"idb": "^8.0.3",
|
"idb": "^8.0.3",
|
||||||
"jose": "^6.2.4",
|
"jose": "^6.2.4",
|
||||||
|
"lucide-react": "^1.49.0",
|
||||||
"next": "^16.3.7",
|
"next": "^16.3.7",
|
||||||
"openai": "^6.46.0",
|
"openai": "^6.46.0",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user