Newer
Older
taehui / taehui-fe / src / query / useWipeTotem.ts
@Taehui Taehui on 18 Mar 842 bytes v1.0.0
import { useTaehuiStore } from "@/state/Stores";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { toast } from "react-toastify";
import { getMillis } from "taehui-ts/date";

export default function useWipeTotem() {
  const { taehuiAvatarName, wipeSession, saveTotem } = useTaehuiStore();

  const t = useTranslations();

  return useMutation({
    mutationFn: async ({ totem }: { totem: string }) => {
      const { data } = await wwwAPI.delete("/avatar/totem", {
        headers: {
          millis: getMillis(),
          totem,
        },
      });
      return data;
    },
    onSuccess: async () => {
      toast.success(t("notLoggedInText", { avatarName: taehuiAvatarName }));
      wipeSession();
      saveTotem();
    },
  });
}