← back to Open Seo

src/client/features/domain/mutations.ts

30 lines

import { useMutation, type QueryClient } from "@tanstack/react-query";
import { saveKeywords } from "@/serverFunctions/keywords";

export function useSaveKeywordsMutation({
  projectId,
  queryClient,
}: {
  projectId: string;
  queryClient: QueryClient;
}) {
  return useMutation({
    mutationFn: (data: {
      projectId: string;
      keywords: string[];
      locationCode?: number;
      metrics?: Array<{
        keyword: string;
        searchVolume?: number | null;
        cpc?: number | null;
        keywordDifficulty?: number | null;
      }>;
    }) => saveKeywords({ data }),
    onSuccess: () => {
      void queryClient.invalidateQueries({
        queryKey: ["savedKeywords", projectId],
      });
    },
  });
}