diff --git a/src/components/medications/sections/api-tokens-row.tsx b/src/components/medications/sections/api-tokens-row.tsx index 57455f81f..e79468ce8 100644 --- a/src/components/medications/sections/api-tokens-row.tsx +++ b/src/components/medications/sections/api-tokens-row.tsx @@ -16,7 +16,7 @@ * without a manual refresh. */ -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useState } from "react"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner"; import { Copy, KeyRound } from "lucide-react"; @@ -48,13 +48,12 @@ export function ApiTokensRow({ const [mintedToken, setMintedToken] = useState(null); const [busy, setBusy] = useState(false); - // Per-medication api-endpoint status reads under a dedicated key - // that rides the `["medications", id, …]` prefix so the bundle - // invalidation in `medicationDependentKeys` catches it. - const queryKey = useMemo( - () => ["medications", medicationId, "api-endpoint"] as const, - [medicationId], - ); + // v1.5.5 F-1 H-2 — single source of truth for the per-medication + // api-endpoint key. The earlier inline `useMemo` minted the same + // tuple as a bare array, slipping past `healthlog/queryKey-factory`. + // Reading from the factory keeps the bundle invalidation + + // `setQueryData` shape stable across consumers. + const queryKey = queryKeys.medicationApiEndpoint(medicationId); const { data: status } = useQuery({ queryKey, diff --git a/src/lib/query-keys.ts b/src/lib/query-keys.ts index 7aeacb03f..b973cac7e 100644 --- a/src/lib/query-keys.ts +++ b/src/lib/query-keys.ts @@ -130,6 +130,16 @@ export const queryKeys = { ["dashboard-medication-compliance", days] as const, medicationPhaseConfig: (medicationId: string) => ["phase-config", medicationId] as const, + /** + * v1.5.5 F-1 H-2 — per-medication api-endpoint status (enabled + + * active-token-count) used by the detail-page Externe Integration + * row. The key rides under the `["medications", id, …]` prefix so + * `medicationDependentKeys` catches it on token mint / disable. + * Centralising the tuple closes the bare-array bypass the + * useMemo inside `` was using. + */ + medicationApiEndpoint: (medicationId: string) => + ["medications", medicationId, "api-endpoint"] as const, gamificationAchievements: () => ["gamification", "achievements"] as const,