Newer
Older
taehui / taehui-fe / src / forum / usePutAutoEssay.ts
@Taehui Taehui on 9 Mar 1 KB 2024-03-09 오후 8:25
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { wwwAXIOSNew } from "src/Www";
import { getMillis } from "taehui-ts/date";
import { useAvatarStore, useForumStore } from "src/Stores";
import { toast } from "react-toastify";
import { useTranslation } from "react-i18next";

export default function usePutAutoEssay(
  forumID: string | undefined,
  title: string,
  text: string,
) {
  const { t } = useTranslation();

  const { autoEssayID } = useForumStore();

  const { totem } = useAvatarStore();

  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async () => {
      await wwwAXIOSNew.put(
        `/autoEssay/${autoEssayID}`,
        {
          title,
          text,
        },
        {
          headers: {
            millis: getMillis(),
            totem,
          },
        },
      );
    },
    onSuccess: async () => {
      toast.success(t("postedAutoEssay"));
      await queryClient.invalidateQueries({ queryKey: ["autoEssay"] });
    },
  });
}