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.

1.1 KB
Raw Blame
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { ImageUpIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { uploadProjectBackground } from "@/fetchers/project/background";
import { toast } from "@/lib/toast";

type UploadProjectBackgroundVariables = {
  projectId: string;
  file: File;
};

function useUploadProjectBackground() {
  const { t } = useTranslation();
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: ({ projectId, file }: UploadProjectBackgroundVariables) =>
      uploadProjectBackground(projectId, file),
    onSuccess: async (_data, { projectId }) => {
      await Promise.all([
        queryClient.invalidateQueries({ queryKey: ["tasks", projectId] }),
        queryClient.invalidateQueries({ queryKey: ["projects"] }),
      ]);
      toast.success(t("settings:projectGeneral.backgroundUploadSuccess"), {
        icon: ImageUpIcon,
      });
    },
    onError: () => {
      toast.error(t("settings:projectGeneral.backgroundUploadError"));
    },
  });
}

export default useUploadProjectBackground;