From b0b733d5e1f375dca304c21d6964a80eda12f8ac Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Sun, 22 Mar 2026 18:20:27 +0000 Subject: [PATCH] feat(BIT-247): consolidate error reporting repo from OTT Merge ingest-api, collector-worker, admin-ui, database/error_reporting, deploy/lxc, docker-compose, and deployment docs into the dedicated repository. Paths updated for repo root (ER_REPO_ROOT, systemd WorkingDirectory). Root README documents layout. Co-Authored-By: Paperclip --- .env.example | 24 + .gitignore | 1 + README.md | 43 + admin-ui/.env.example | 5 + admin-ui/.gitignore | 6 + admin-ui/app/globals.scss | 41 + admin-ui/app/incidents/[id]/not-found.tsx | 20 + admin-ui/app/incidents/[id]/page.tsx | 162 + admin-ui/app/incidents/page.tsx | 200 + admin-ui/app/layout.tsx | 15 + admin-ui/app/page.tsx | 63 + admin-ui/components/AppShell.tsx | 58 + admin-ui/components/DataAlert.tsx | 16 + admin-ui/components/IncidentNotes.tsx | 45 + admin-ui/components/KpiCard.tsx | 20 + admin-ui/components/SeverityBadge.tsx | 21 + admin-ui/components/StateBadge.tsx | 19 + admin-ui/eslint.config.mjs | 14 + admin-ui/lib/demo-incidents.ts | 123 + admin-ui/lib/format.ts | 14 + admin-ui/lib/incidents-data.ts | 178 + admin-ui/lib/types.ts | 47 + admin-ui/next-env.d.ts | 6 + admin-ui/next.config.ts | 7 + admin-ui/package-lock.json | 5847 +++++++++++++++++ admin-ui/package.json | 32 + admin-ui/tsconfig.json | 21 + api/package-lock.json | 3842 +++++++++++ collector-worker/.gitignore | 2 + collector-worker/Dockerfile | 15 + collector-worker/fixture/errors.json | 12 + collector-worker/package-lock.json | 2160 ++++++ collector-worker/package.json | 28 + .../src/auth/resolveSecret.test.ts | 25 + collector-worker/src/auth/resolveSecret.ts | 33 + collector-worker/src/config/loadEnv.ts | 42 + collector-worker/src/db/collectorRunWriter.ts | 82 + collector-worker/src/db/loadActiveSources.ts | 33 + collector-worker/src/ingest/pushEvents.ts | 38 + collector-worker/src/log/structuredLog.ts | 13 + collector-worker/src/main.ts | 85 + collector-worker/src/poll/fetchHttpEvents.ts | 79 + .../src/scheduler/runHttpSourceOnce.ts | 218 + .../src/scheduler/sourceState.test.ts | 34 + collector-worker/src/scheduler/sourceState.ts | 20 + collector-worker/src/types/ingest.ts | 19 + collector-worker/tsconfig.json | 17 + collector-worker/vitest.config.ts | 8 + database/error_reporting/README.md | 34 + ...43000_create_error_reporting_core.down.sql | 12 + ...2043000_create_error_reporting_core.up.sql | 76 + ...eate_error_occurrences_and_states.down.sql | 18 + ...create_error_occurrences_and_states.up.sql | 128 + ...0322044500_add_ingest_idempotency.down.sql | 7 + ...260322044500_add_ingest_idempotency.up.sql | 42 + ...te_collectors_retention_and_audit.down.sql | 18 + ...eate_collectors_retention_and_audit.up.sql | 135 + .../seed/dev_collector_http_fixture.sql | 26 + .../error_reporting/seed/dev_two_projects.sql | 24 + deploy/lxc/README.md | 15 + deploy/lxc/env.example | 32 + ...itreport-error-reporting.site.conf.example | 37 + deploy/lxc/run-migrate.sh | 37 + ...bitreport-error-reporting-admin-ui.service | 19 + ...t-error-reporting-collector-worker.service | 19 + ...treport-error-reporting-ingest-api.service | 19 + deploy/lxc/verify.sh | 38 + docker-compose.yml | 101 + ...treport-error-reporting-compose-proxmox.md | 95 + .../bitreport-error-reporting-lxc-proxmox.md | 173 + ingest-api/.env.example | 4 + ingest-api/.gitignore | 4 + ingest-api/Dockerfile | 16 + ingest-api/package-lock.json | 3373 ++++++++++ ingest-api/package.json | 33 + ingest-api/src/buildApp.ts | 231 + ingest-api/src/config/env.ts | 34 + .../src/integration.twoProjects.test.ts | 194 + ingest-api/src/lib/hash.ts | 25 + ingest-api/src/lib/normalize.test.ts | 54 + ingest-api/src/lib/normalize.ts | 53 + ingest-api/src/server.ts | 27 + ingest-api/src/services/ingestAuth.ts | 69 + ingest-api/src/services/processIngestBatch.ts | 189 + ingest-api/src/types/fastify.d.ts | 7 + ingest-api/tsconfig.json | 17 + ingest-api/vitest.config.ts | 10 + scripts/docker-migrate.sh | 23 + 88 files changed, 19321 insertions(+) create mode 100644 .env.example create mode 100644 README.md create mode 100644 admin-ui/.env.example create mode 100644 admin-ui/.gitignore create mode 100644 admin-ui/app/globals.scss create mode 100644 admin-ui/app/incidents/[id]/not-found.tsx create mode 100644 admin-ui/app/incidents/[id]/page.tsx create mode 100644 admin-ui/app/incidents/page.tsx create mode 100644 admin-ui/app/layout.tsx create mode 100644 admin-ui/app/page.tsx create mode 100644 admin-ui/components/AppShell.tsx create mode 100644 admin-ui/components/DataAlert.tsx create mode 100644 admin-ui/components/IncidentNotes.tsx create mode 100644 admin-ui/components/KpiCard.tsx create mode 100644 admin-ui/components/SeverityBadge.tsx create mode 100644 admin-ui/components/StateBadge.tsx create mode 100644 admin-ui/eslint.config.mjs create mode 100644 admin-ui/lib/demo-incidents.ts create mode 100644 admin-ui/lib/format.ts create mode 100644 admin-ui/lib/incidents-data.ts create mode 100644 admin-ui/lib/types.ts create mode 100644 admin-ui/next-env.d.ts create mode 100644 admin-ui/next.config.ts create mode 100644 admin-ui/package-lock.json create mode 100644 admin-ui/package.json create mode 100644 admin-ui/tsconfig.json create mode 100644 api/package-lock.json create mode 100644 collector-worker/.gitignore create mode 100644 collector-worker/Dockerfile create mode 100644 collector-worker/fixture/errors.json create mode 100644 collector-worker/package-lock.json create mode 100644 collector-worker/package.json create mode 100644 collector-worker/src/auth/resolveSecret.test.ts create mode 100644 collector-worker/src/auth/resolveSecret.ts create mode 100644 collector-worker/src/config/loadEnv.ts create mode 100644 collector-worker/src/db/collectorRunWriter.ts create mode 100644 collector-worker/src/db/loadActiveSources.ts create mode 100644 collector-worker/src/ingest/pushEvents.ts create mode 100644 collector-worker/src/log/structuredLog.ts create mode 100644 collector-worker/src/main.ts create mode 100644 collector-worker/src/poll/fetchHttpEvents.ts create mode 100644 collector-worker/src/scheduler/runHttpSourceOnce.ts create mode 100644 collector-worker/src/scheduler/sourceState.test.ts create mode 100644 collector-worker/src/scheduler/sourceState.ts create mode 100644 collector-worker/src/types/ingest.ts create mode 100644 collector-worker/tsconfig.json create mode 100644 collector-worker/vitest.config.ts create mode 100644 database/error_reporting/README.md create mode 100644 database/error_reporting/migrations/20260322043000_create_error_reporting_core.down.sql create mode 100644 database/error_reporting/migrations/20260322043000_create_error_reporting_core.up.sql create mode 100644 database/error_reporting/migrations/20260322044000_create_error_occurrences_and_states.down.sql create mode 100644 database/error_reporting/migrations/20260322044000_create_error_occurrences_and_states.up.sql create mode 100644 database/error_reporting/migrations/20260322044500_add_ingest_idempotency.down.sql create mode 100644 database/error_reporting/migrations/20260322044500_add_ingest_idempotency.up.sql create mode 100644 database/error_reporting/migrations/20260322045000_create_collectors_retention_and_audit.down.sql create mode 100644 database/error_reporting/migrations/20260322045000_create_collectors_retention_and_audit.up.sql create mode 100644 database/error_reporting/seed/dev_collector_http_fixture.sql create mode 100644 database/error_reporting/seed/dev_two_projects.sql create mode 100644 deploy/lxc/README.md create mode 100644 deploy/lxc/env.example create mode 100644 deploy/lxc/nginx/bitreport-error-reporting.site.conf.example create mode 100755 deploy/lxc/run-migrate.sh create mode 100644 deploy/lxc/systemd/bitreport-error-reporting-admin-ui.service create mode 100644 deploy/lxc/systemd/bitreport-error-reporting-collector-worker.service create mode 100644 deploy/lxc/systemd/bitreport-error-reporting-ingest-api.service create mode 100755 deploy/lxc/verify.sh create mode 100644 docker-compose.yml create mode 100644 docs/deployment/bitreport-error-reporting-compose-proxmox.md create mode 100644 docs/deployment/bitreport-error-reporting-lxc-proxmox.md create mode 100644 ingest-api/.env.example create mode 100644 ingest-api/.gitignore create mode 100644 ingest-api/Dockerfile create mode 100644 ingest-api/package-lock.json create mode 100644 ingest-api/package.json create mode 100644 ingest-api/src/buildApp.ts create mode 100644 ingest-api/src/config/env.ts create mode 100644 ingest-api/src/integration.twoProjects.test.ts create mode 100644 ingest-api/src/lib/hash.ts create mode 100644 ingest-api/src/lib/normalize.test.ts create mode 100644 ingest-api/src/lib/normalize.ts create mode 100644 ingest-api/src/server.ts create mode 100644 ingest-api/src/services/ingestAuth.ts create mode 100644 ingest-api/src/services/processIngestBatch.ts create mode 100644 ingest-api/src/types/fastify.d.ts create mode 100644 ingest-api/tsconfig.json create mode 100644 ingest-api/vitest.config.ts create mode 100755 scripts/docker-migrate.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bea5746 --- /dev/null +++ b/.env.example @@ -0,0 +1,24 @@ +# BitReport error reporting — Docker Compose (copy to `.env` in this directory). +# `docker compose` reads `.env` automatically for variable substitution in docker-compose.yml. + +# --- PostgreSQL (service: postgres) --- +ER_POSTGRES_USER=postgres +ER_POSTGRES_PASSWORD=postgres +ER_POSTGRES_DB=error_reporting +# Host port mapped to Postgres (container always listens on 5432) +ER_PUBLISH_PG_PORT=5434 + +# --- Ingest API (service: ingest-api) --- +ER_PUBLISH_INGEST_PORT=3041 +# Optional rate limiting (defaults match ingest-api/src/config/env.ts) +# INGEST_RATE_LIMIT_MAX=300 +# INGEST_RATE_LIMIT_WINDOW_MS=60000 + +# --- Collector worker (service: collector-worker) --- +# Demo token for the seeded HTTP fixture source (must match project token in DB seed) +ER_COLLECTOR_PROJECT_ALPHA_TOKEN=er_tst_a_secret_one +# TICK_INTERVAL_MS=3000 +# SOURCE_REFRESH_MS=15000 +# HTTP_FETCH_TIMEOUT_MS=15000 +# MAX_BACKOFF_EXPONENT=8 +# COLLECTOR_DEFAULT_INGEST_TOKEN= diff --git a/.gitignore b/.gitignore index a881f62..5d739cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist/ .env.local *.log coverage/ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..2373451 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# errors.bitreport.pt + +BitReport **central error reporting** platform: ingest API, collector worker, admin UI (incidents), PostgreSQL migrations, and optional **admin portal** (auth/RBAC) from BIT-183. + +**Remote:** `https://git.bitreport.pt/BitReport.pt/errors.bitreport.pt.git` +**Tracking:** Paperclip **BIT-247** (migration from `OTT/error-reporting/`). + +## Layout + +| Path | Role | +|------|------| +| `ingest-api/` | Fastify HTTP ingest (BIT-154.x) | +| `collector-worker/` | Polls configured sources → ingest API | +| `admin-ui/` | Next.js operator UI (incidents) | +| `database/error_reporting/` | SQL migrations + dev seed (used by Compose + LXC) | +| `deploy/lxc/` | systemd, nginx examples, migrate script (no Docker) | +| `docker-compose.yml`, `.env.example` | Local / Proxmox Docker stack | +| `api/` | Fastify admin API — sessions, RBAC (BIT-183) | +| `web/` | Next.js admin login/UI for `api/` | +| `db/migrations/` | Admin-user schema (node-pg-migrate); distinct from `database/error_reporting/` | +| `docs/` | Permission matrix, deployment runbooks | + +## Docker Compose (ingest stack) + +From the **repository root**: + +```bash +cp .env.example .env +docker compose up --build +curl -sf "http://127.0.0.1:${ER_PUBLISH_INGEST_PORT:-3041}/health" +``` + +## Docs + +- Compose + TLS: [`docs/deployment/bitreport-error-reporting-compose-proxmox.md`](docs/deployment/bitreport-error-reporting-compose-proxmox.md) +- LXC + systemd: [`docs/deployment/bitreport-error-reporting-lxc-proxmox.md`](docs/deployment/bitreport-error-reporting-lxc-proxmox.md) + +## Tests (local) + +```bash +cd ingest-api && npm ci && npm test +cd ../api && npm ci && npm test +``` diff --git a/admin-ui/.env.example b/admin-ui/.env.example new file mode 100644 index 0000000..6ee5939 --- /dev/null +++ b/admin-ui/.env.example @@ -0,0 +1,5 @@ +# Base URL da API admin (Fastify) quando existir (BIT-179). Sem trailing slash. +# ERROR_REPORTING_ADMIN_API_BASE=http://127.0.0.1:3050 + +# Apenas desenvolvimento: carrega dados fictícios para validar layout sem API. +# ERROR_REPORTING_UI_DEMO=1 diff --git a/admin-ui/.gitignore b/admin-ui/.gitignore new file mode 100644 index 0000000..d679276 --- /dev/null +++ b/admin-ui/.gitignore @@ -0,0 +1,6 @@ +.next/ +node_modules/ +out/ +.env +.env.local +*.tsbuildinfo diff --git a/admin-ui/app/globals.scss b/admin-ui/app/globals.scss new file mode 100644 index 0000000..cca73cc --- /dev/null +++ b/admin-ui/app/globals.scss @@ -0,0 +1,41 @@ +@import "bootstrap/scss/bootstrap"; + +/* Velzon-adjacent shell (Bootstrap 5; no proprietary template assets). */ +.er-app { + --er-sidebar-width: 260px; +} + +.er-sidebar { + width: var(--er-sidebar-width); + background: linear-gradient(180deg, #1a1d21 0%, #212529 40%, #1a1d21 100%); +} + +.er-nav-link { + border-radius: 0.35rem; + padding: 0.5rem 0.75rem; +} + +.er-nav-link:hover, +.er-nav-link:focus { + background: rgba(255, 255, 255, 0.06); + color: #fff !important; +} + +.er-topbar { + position: sticky; + top: 0; + z-index: 1020; +} + +.er-main { + background-color: #f3f6f9; + min-height: calc(100vh - 72px); +} + +pre.er-stack { + max-height: 320px; + overflow: auto; + font-size: 0.8rem; + white-space: pre-wrap; + word-break: break-word; +} diff --git a/admin-ui/app/incidents/[id]/not-found.tsx b/admin-ui/app/incidents/[id]/not-found.tsx new file mode 100644 index 0000000..2645e35 --- /dev/null +++ b/admin-ui/app/incidents/[id]/not-found.tsx @@ -0,0 +1,20 @@ +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; + +export default function IncidentNotFound() { + return ( + +

O incidente pedido não existe ou foi removido.

+ + Voltar à lista + +
+ ); +} diff --git a/admin-ui/app/incidents/[id]/page.tsx b/admin-ui/app/incidents/[id]/page.tsx new file mode 100644 index 0000000..779e48a --- /dev/null +++ b/admin-ui/app/incidents/[id]/page.tsx @@ -0,0 +1,162 @@ +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { AppShell } from "@/components/AppShell"; +import { DataAlert } from "@/components/DataAlert"; +import { IncidentNotes } from "@/components/IncidentNotes"; +import { SeverityBadge } from "@/components/SeverityBadge"; +import { StateBadge } from "@/components/StateBadge"; +import { formatDateTime } from "@/lib/format"; +import { fetchIncidentDetail } from "@/lib/incidents-data"; + +export default async function IncidentDetailPage(props: { params: Promise<{ id: string }> }) { + const { id } = await props.params; + const _decoded = decodeURIComponent(id); + const _result = await fetchIncidentDetail(_decoded); + + if (!_result.ok) { + if (_result.error === "not_found") { + notFound(); + } + return ( + + + + Voltar à lista + + + ); + } + + const _inc = _result.incident; + const _occ = _inc.occurrences[0]; + + return ( + + {_result.source === "demo" ? ( +

+ Dados de demonstração — stack e contexto alinhados com o modelo relacional (BIT-178). +

+ ) : null} + +
+
+
+
+
+ + +
+ id: {_inc.id} +
+
+
+
Projeto
+
+ {_inc.projectSlug} +
+
Fingerprint
+
+ {_inc.fingerprint} +
+
Origem (ingest)
+
{_inc.ingestKeyLabel ?? "—"}
+
Primeira vista
+
{formatDateTime(_inc.firstSeenAt)}
+
Última vista
+
{formatDateTime(_inc.lastSeenAt)}
+
Ocorrências
+
{_inc.occurrencesCount}
+
+
+
+ +
+
Meta (incidente)
+
+ {_inc.metadataJson && Object.keys(_inc.metadataJson).length > 0 ? ( +
+                  {JSON.stringify(_inc.metadataJson, null, 2)}
+                
+ ) : ( +

Sem metadados agregados neste incidente.

+ )} +
+
+ +
+
Última ocorrência — mensagem
+
+ {_occ ? ( + <> +

{_occ.message}

+

+ + Nível: {_occ.levelRaw} + + · {formatDateTime(_occ.occurredAt)} +

+ + ) : ( +

Sem ocorrências carregadas nesta vista.

+ )} +
+
+ +
+
Stack trace
+
+ {_occ?.stacktrace ? ( +
{_occ.stacktrace}
+ ) : ( +

Sem stack trace na última ocorrência.

+ )} +
+
+ +
+
Contexto (JSON)
+
+ {_occ?.contextJson && Object.keys(_occ.contextJson).length > 0 ? ( +
+                  {JSON.stringify(_occ.contextJson, null, 2)}
+                
+ ) : ( +

Sem contexto estruturado na última ocorrência.

+ )} +
+
+
+ +
+
+
Notas
+
+ +
+
+ + Voltar à lista + +
+
+
+ ); +} diff --git a/admin-ui/app/incidents/page.tsx b/admin-ui/app/incidents/page.tsx new file mode 100644 index 0000000..f27052f --- /dev/null +++ b/admin-ui/app/incidents/page.tsx @@ -0,0 +1,200 @@ +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; +import { DataAlert } from "@/components/DataAlert"; +import { SeverityBadge } from "@/components/SeverityBadge"; +import { StateBadge } from "@/components/StateBadge"; +import { formatDateTime } from "@/lib/format"; +import { fetchIncidentList } from "@/lib/incidents-data"; +import type { IncidentState, Severity } from "@/lib/types"; + +type SearchParams = Promise>; + +const _states: IncidentState[] = ["open", "investigating", "resolved", "ignored"]; +const _severities: Severity[] = ["critical", "high", "medium", "low", "info"]; + +function _param(sp: Record, key: string): string { + const _v = sp[key]; + if (Array.isArray(_v)) { + return _v[0] ?? ""; + } + return _v ?? ""; +} + +export default async function IncidentsPage(props: { searchParams: SearchParams }) { + const _sp = await props.searchParams; + const _state = _param(_sp, "state") as IncidentState | ""; + const _severity = _param(_sp, "severity") as Severity | ""; + const _project = _param(_sp, "project"); + const _q = _param(_sp, "q"); + + // Fetch unfiltered list first to build the project dropdown options. + const _allList = await fetchIncidentList({}); + const _projectSlugs: string[] = _allList.ok + ? [...new Set(_allList.incidents.map((r) => r.projectSlug))].sort() + : []; + + const _list = await fetchIncidentList({ + state: _states.includes(_state as IncidentState) ? _state : "", + severity: _severities.includes(_severity as Severity) ? _severity : "", + project: _project, + q: _q, + }); + + return ( + + {_list.ok && _list.source === "demo" ? ( +

+ Dados de demonstração — ligue ERROR_REPORTING_ADMIN_API_BASE para dados reais + (BIT-179). +

+ ) : null} + + {!_list.ok ? ( + + ) : null} + +
+
Filtros
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ +
+
+ Resultados + {_list.ok ? ( + {_list.incidents.length} + ) : null} +
+
+ {_list.ok && _list.incidents.length === 0 ? ( +

Nenhum incidente corresponde aos filtros.

+ ) : null} + {_list.ok && _list.incidents.length > 0 ? ( +
+ + + + + + + + + + + + + {_list.incidents.map((row) => ( + + + + + + + + + + ))} + +
EstadoSeveridadeProjetoTítulo + Ocorrências + Última vista +
+ + + + + {row.projectSlug} + {row.title}{row.occurrencesCount} + {formatDateTime(row.lastSeenAt)} + + + Detalhe + +
+
+ ) : null} +
+
+
+ ); +} diff --git a/admin-ui/app/layout.tsx b/admin-ui/app/layout.tsx new file mode 100644 index 0000000..acd4224 --- /dev/null +++ b/admin-ui/app/layout.tsx @@ -0,0 +1,15 @@ +import type { Metadata } from "next"; +import "./globals.scss"; + +export const metadata: Metadata = { + title: "BitReport — Error reporting", + description: "Painel central de incidentes (BIT-181)", +}; + +export default function RootLayout({ children }: { children: React.ReactNode }) { + return ( + + {children} + + ); +} diff --git a/admin-ui/app/page.tsx b/admin-ui/app/page.tsx new file mode 100644 index 0000000..c3a3d52 --- /dev/null +++ b/admin-ui/app/page.tsx @@ -0,0 +1,63 @@ +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; +import { DataAlert } from "@/components/DataAlert"; +import { KpiCard } from "@/components/KpiCard"; +import { computeKpis, fetchIncidentList } from "@/lib/incidents-data"; + +export default async function DashboardPage() { + const _list = await fetchIncidentList({}); + + if (!_list.ok) { + return ( + + +

+ Com ERROR_REPORTING_UI_DEMO=1 pode visualizar KPIs de demonstração sem API. +

+
+ ); + } + + const _kpis = computeKpis(_list.incidents); + const _sourceHint = + _list.source === "demo" ? ( +

+ Modo demonstração (ERROR_REPORTING_UI_DEMO=1) — substituir por API em + produção. +

+ ) : null; + + return ( + + {_sourceHint} +
+ + + + +
+
+
+ +
+
+
+
+ Atalhos +
+
+

+ Consulte a lista completa com filtros por estado, severidade e texto. +

+ + Ver incidentes + +
+
+
+ ); +} diff --git a/admin-ui/components/AppShell.tsx b/admin-ui/components/AppShell.tsx new file mode 100644 index 0000000..571a9a4 --- /dev/null +++ b/admin-ui/components/AppShell.tsx @@ -0,0 +1,58 @@ +import Link from "next/link"; +import type { ReactNode } from "react"; + +export function AppShell({ + children, + title, + breadcrumb, +}: { + children: ReactNode; + title: string; + breadcrumb?: { label: string; href?: string }[]; +}) { + return ( +
+ +
+
+
+

{title}

+ {breadcrumb && breadcrumb.length > 0 ? ( + + ) : null} +
+
+
{children}
+
+
+ ); +} diff --git a/admin-ui/components/DataAlert.tsx b/admin-ui/components/DataAlert.tsx new file mode 100644 index 0000000..ba270d4 --- /dev/null +++ b/admin-ui/components/DataAlert.tsx @@ -0,0 +1,16 @@ +export function DataAlert({ + variant, + title, + body, +}: { + variant: "warning" | "danger" | "info"; + title: string; + body: string; +}) { + return ( +
+ {title} + {body} +
+ ); +} diff --git a/admin-ui/components/IncidentNotes.tsx b/admin-ui/components/IncidentNotes.tsx new file mode 100644 index 0000000..25147a0 --- /dev/null +++ b/admin-ui/components/IncidentNotes.tsx @@ -0,0 +1,45 @@ +"use client"; + +import { useEffect, useId, useState } from "react"; + +const _storageKey = (id: string) => `er-incident-notes:${id}`; + +export function IncidentNotes({ incidentId }: { incidentId: string }) { + const _id = useId(); + const [value, setValue] = useState(""); + + useEffect(() => { + if (typeof window === "undefined") { + return; + } + const _stored = window.sessionStorage.getItem(_storageKey(incidentId)); + setValue(_stored ?? ""); + }, [incidentId]); + + useEffect(() => { + if (typeof window === "undefined") { + return; + } + window.sessionStorage.setItem(_storageKey(incidentId), value); + }, [incidentId, value]); + + return ( +
+ +