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 -4
View File
@@ -1,6 +1,7 @@
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useTrackedMutation } from '../hooks/useTrackedMutation';
import { getTargets, createTarget, deleteTarget, getAgents } from '../api/client';
import PageHeader from '../components/PageHeader';
import DataTable from '../components/DataTable';
@@ -242,13 +243,14 @@ function CreateTargetWizard({ onClose, onSuccess }: { onClose: () => void; onSuc
return result;
};
const mutation = useMutation({
const mutation = useTrackedMutation({
mutationFn: () => createTarget({
name,
type: targetType,
agent_id: agentId,
config: buildConfigPayload(),
}),
invalidates: [['targets']],
onSuccess: () => onSuccess(),
onError: (err: Error) => setError(err.message),
});
@@ -407,9 +409,9 @@ export default function TargetsPage() {
queryFn: () => getTargets(),
});
const deleteMutation = useMutation({
const deleteMutation = useTrackedMutation({
mutationFn: deleteTarget,
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['targets'] }),
invalidates: [['targets']],
});
const columns: Column<Target>[] = [