From d310058bc59c531c8153b83d3f6ee8c4ad0df97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 11 Nov 2026 21:48:15 +0100 Subject: [PATCH] fix(admin): read the AI quality summary once on the Coach page `/admin/coach` mounts the AI quality card and the Coach feedback card, and both read `GET /api/admin/ai-quality` with the same unwrap, under two different query keys, so every open sent the request twice. The feedback card now reads the quality card's cell. --- .../__tests__/coach-feedback-section.test.tsx | 23 +++++++++++++++++++ .../admin/coach-feedback-section.tsx | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/admin/__tests__/coach-feedback-section.test.tsx b/src/components/admin/__tests__/coach-feedback-section.test.tsx index 8886fb700..a68e821d3 100644 --- a/src/components/admin/__tests__/coach-feedback-section.test.tsx +++ b/src/components/admin/__tests__/coach-feedback-section.test.tsx @@ -19,6 +19,7 @@ vi.mock("@tanstack/react-query", () => ({ })); import { I18nProvider } from "@/lib/i18n/context"; +import { AiQualitySection } from "../ai-quality-section"; import { CoachFeedbackSection } from "../coach-feedback-section"; function render() { @@ -138,3 +139,25 @@ describe("CoachFeedbackSection", () => { } }); }); + +describe("the Coach admin page's two quality cards", () => { + it("read one cache cell, so the page asks for the summary once", () => { + useQueryMock.mockReset().mockReturnValue({ + isLoading: true, + isError: false, + data: null, + }); + renderToStaticMarkup( + + + + , + ); + + const keys = useQueryMock.mock.calls.map( + ([options]) => (options as { queryKey: unknown }).queryKey, + ); + expect(keys).toHaveLength(2); + expect(keys[1]).toEqual(keys[0]); + }); +}); diff --git a/src/components/admin/coach-feedback-section.tsx b/src/components/admin/coach-feedback-section.tsx index 3eb6659bb..1fcdab3bc 100644 --- a/src/components/admin/coach-feedback-section.tsx +++ b/src/components/admin/coach-feedback-section.tsx @@ -51,7 +51,9 @@ export function CoachFeedbackSection() { const fmt = useFormatters(); const query = useQuery({ - queryKey: queryKeys.adminCoachFeedback(), + // The same read as the AI quality section beside it, so one request + // serves both cards. + queryKey: queryKeys.adminAiQuality(), queryFn: async () => { const data = await apiGet<{ summary: FeedbackSummary | null } | null>( "/api/admin/ai-quality",