Newer
Older
taehui / taehui-fe / src / query / usePostDrawing.ts
@Taehui Taehui on 17 Mar 612 bytes 2024-03-17 오후 3:50
import { useTaehuiStore } from "@/state/Stores";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation } from "@tanstack/react-query";
import { getMillis } from "taehui-ts/date";

export default function usePostDrawing() {
  const { totem } = useTaehuiStore();

  return useMutation({
    mutationFn: async ({ file }: { file: File }) => {
      const form = new FormData();
      form.append("data", file);
      await wwwAPI.post("/avatar/drawing", form, {
        headers: { millis: getMillis(), totem },
      });
    },
    onSuccess: async () => {
      window.location.reload();
    },
  });
}