M-029 Pass 1 batch 2: migrate 5 two-mutation pages to useTrackedMutation

Drains 10 more useMutation sites (52 -> 42). Each migration declares explicit

invalidates per the M-009 contract.

Pages migrated:

  - DashboardPage.tsx        previewDigest + sendDigest both 'noop' (read-only

                              preview / fire-and-forget email — no client cache impact)

  - DiscoveryPage.tsx        claim + dismiss both invalidate

                              [['discovered-certificates'], ['discovery-summary']]

  - NotificationsPage.tsx    markRead + requeue both invalidate [['notifications']]

  - TargetDetailPage.tsx     update + testConnection both invalidate [['target', id]]

  - TargetsPage.tsx          createTarget + deleteTarget both invalidate [['targets']]

Verification:

  legacy useMutation count   52 -> 42 (-10)

  useTrackedMutation count    4 -> 14 (+10)

Closes 14 of 56 sites toward M-029 Pass 1 completion.
This commit is contained in:
shankar0123
2026-04-27 02:40:54 +00:00
parent e9f809b7f9
commit e0a3d50f5e
5 changed files with 34 additions and 31 deletions
+6 -6
View File
@@ -1,5 +1,6 @@
import { useState, useMemo } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';
import { useTrackedMutation } from '../hooks/useTrackedMutation';
import { getNotifications, markNotificationRead, requeueNotification } from '../api/client';
import PageHeader from '../components/PageHeader';
import StatusBadge from '../components/StatusBadge';
@@ -22,7 +23,6 @@ export default function NotificationsPage() {
const [typeFilter, setTypeFilter] = useState('');
const [statusFilter, setStatusFilter] = useState('');
const [activeTab, setActiveTab] = useState<ActiveTab>('all');
const queryClient = useQueryClient();
const { data, isLoading, error, refetch } = useQuery({
// I-005: queryKey carries the active tab so TanStack Query treats
@@ -43,9 +43,9 @@ export default function NotificationsPage() {
refetchInterval: 30000,
});
const markRead = useMutation({
const markRead = useTrackedMutation({
mutationFn: markNotificationRead,
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['notifications'] }),
invalidates: [['notifications']],
});
// I-005: requeue a dead notification. Invalidates both tab cache entries
@@ -60,9 +60,9 @@ export default function NotificationsPage() {
// assertion fails on the extra argument. Keep the arrow even if the context
// object later becomes structurally empty — the contract pins a single-arg
// call and the page must not leak mutation machinery into API boundaries.
const requeue = useMutation({
const requeue = useTrackedMutation({
mutationFn: (id: string) => requeueNotification(id),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['notifications'] }),
invalidates: [['notifications']],
});
const notifications = data?.data || [];