File size: 870 Bytes
3d700dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { useMutation, useQueryClient } from "@tanstack/react-query";
import AgentProfilesService, {
  type AgentProfileSaveInput,
} from "#/api/agent-profiles-service/agent-profiles-service.api";
import { AGENT_PROFILES_QUERY_KEYS } from "#/hooks/query/query-keys";

export function useSaveAgentProfile() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: ({
      name,
      profile,
    }: {
      name: string;
      profile: AgentProfileSaveInput;
    }) => AgentProfilesService.saveProfile(name, profile),
    onSuccess: async () => {
      // Prefix match invalidates every backend/org-suffixed list key.
      await queryClient.invalidateQueries({
        queryKey: AGENT_PROFILES_QUERY_KEYS.all,
      });
    },
    // Consumers handle errors with try-catch + targeted toasts (409/422).
    meta: { disableToast: true },
  });
}