Reporting Server Component Refactor
Last updated: 2026-06-02
Purpose
task-0595 starts the read-heavy dashboard/reporting conversion by moving /analytics/reports from a client-only fetch page to a server-rendered data page with a focused client island.
What Changed
src/app/(dashboard)/analytics/reports/page.tsxis now a Server Component that authenticates with request headers, redirects unauthenticated users, and fetches firm-scoped report data before rendering.src/app/(dashboard)/analytics/reports/_components/analytics-reports-client.tsxowns only interactive behavior: tab state, CSV export, links, and chart rendering.src/lib/analytics/reports.tscentralizes attorney and financial report calculations so the page and existing API routes share one source of truth.- Recharts panels are lazy-loaded from the client island via
next/dynamic, keeping chart code out of the server page and splitting heavy chart bundles.
Follow-On Pattern
- Keep authentication, firm scoping, and read-heavy aggregation in Server Components or shared server libraries.
- Pass only serializable DTOs to client islands.
- Keep client islands limited to state, events, browser APIs, exports, and interactive chart controls.
- Lazy-load Recharts, editors, builders, and other heavy panels from client components rather than server components.
Verification
src/__tests__/lib/analytics-reports.test.tscovers attorney stats, financial summaries, distribution buckets, top-case shaping, and monthly settlement trend bucketing.