Phase 2: API client, typed hooks, live probe

- Add api:types script (openapi-typescript against live FastAPI)
- Generate src/lib/api/types.ts (2972 lines, 55 paths, 16 schemas)
- lib/api/client.ts: typed apiRequest + ApiError + makeQueryClient
  (staleTime 5s, no refetchOnWindowFocus to preserve editor state)
- lib/providers.tsx: QueryClientProvider client component, useState
  singleton so App Router re-renders don't dump the cache
- lib/api/cases.ts: Case type + casesKeys + useCases hook (pragmatic
  hand-typed Case pending backend response-model annotations)
- layout.tsx: wrap children with <Providers>
- Smoke test: CasesLiveProbe component on home page hitting live FastAPI
  via /api/cases rewrite proxy

Phase 2 deliverable check: useCases() returns typed Case[] from the
production FastAPI through the Next.js proxy. End-to-end wiring proven.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chaim
2026-04-11 15:49:24 +00:00
parent 64724656af
commit 0ee8e723bd
9 changed files with 3260 additions and 80 deletions

View File

@@ -0,0 +1,51 @@
"use client";
import { useCases } from "@/lib/api/cases";
/**
* Phase 2 smoke-test component — proves that the typed API client, the
* TanStack Query provider, the Next.js rewrite proxy, and the FastAPI backend
* are all wired up correctly end-to-end. Temporary; replaced in Phase 3 by the
* real case list view.
*/
export function CasesLiveProbe() {
const { data, isLoading, isError, error } = useCases();
if (isLoading) {
return (
<p className="text-ink-muted">טוען תיקים מה-API</p>
);
}
if (isError) {
return (
<div className="text-danger">
<p className="font-medium">שגיאה בטעינת תיקים</p>
<p className="text-sm text-ink-muted">
{error instanceof Error ? error.message : "שגיאה לא ידועה"}
</p>
</div>
);
}
const count = data?.length ?? 0;
return (
<div className="space-y-2">
<p className="text-ink">
<span className="font-semibold text-navy">{count}</span>{" "}
תיקים טעונים מה-API בהצלחה.
</p>
{data && data.length > 0 && (
<ul className="text-sm text-ink-muted space-y-1">
{data.slice(0, 3).map((c) => (
<li key={c.case_number}>
<span className="text-gold-deep">{c.case_number}</span> {c.title}
</li>
))}
{data.length > 3 && <li>ועוד {data.length - 3}</li>}
</ul>
)}
</div>
);
}