chore(meds): centralise the medication api-token query key

A bare ["medications", id, "api-endpoint"] tuple escaped the
factory rule via useMemo; the new medicationApiEndpoint key in
the factory restores the single source of truth.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc-André BombeckandClaude Opus 4.7 committed 2026-05-29 00:53:23 +02:00
1 parent 9532f14f3b
commit 56523bafb1
2 files changed
+17 -8

No files matched your search

@@ -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<string | null>(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<ApiEndpointStatus>({
queryKey,
+10
View File
@@ -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 `<ApiTokensRow>` was using.
*/
medicationApiEndpoint: (medicationId: string) =>
["medications", medicationId, "api-endpoint"] as const,
gamificationAchievements: () => ["gamification", "achievements"] as const,