Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

803 B
Raw Blame
import { useMutation, useQueryClient } from "@tanstack/react-query";
import type { CreateCustomFieldRequest } from "@/fetchers/custom-field/create-custom-field";
import createCustomField from "@/fetchers/custom-field/create-custom-field";

function useCreateCustomField() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: createCustomField,
    onSuccess: (created, variables: CreateCustomFieldRequest) => {
      queryClient.setQueryData(
        ["custom-fields", variables.projectId],
        (existing: Array<typeof created> | undefined) => {
          if (!existing) return [created];
          return [...existing, created];
        },
      );

      void queryClient.invalidateQueries({ refetchType: "all" });
    },
  });
}

export default useCreateCustomField;