Newer
Older
taehui / taehui-fe / src / app / [language] / forum / query / usePutComment.ts
@Taehui Taehui on 17 Mar 785 bytes 2024-03-17 오후 3:50
import { useTaehuiStore } from "@/state/Stores";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { getMillis } from "taehui-ts/date";

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

  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async ({
      commentID,
      text,
    }: {
      commentID: number;
      text: string;
    }) => {
      await wwwAPI.put(
        `/comment/${commentID}`,
        { text },
        {
          headers: {
            millis: getMillis(),
            totem,
          },
        },
      );
    },
    onSuccess: async () => {
      await queryClient.invalidateQueries({ queryKey: ["comment"] });
    },
  });
}