import { useMutation, useQueryClient } from "@tanstack/react-query"; import { toast } from "react-toastify"; import { useTranslation } from "react-i18next"; import { isClientFault, wwwAXIOS } from "src/Www"; import { GetCommentaryAPI } from "src/wwwAPI"; export default function useWipeCommentary() { const queryClient = useQueryClient(); const { t } = useTranslation(); return useMutation({ mutationFn: async ({ commentaryID, avatarCipher, }: { commentaryID: number; avatarCipher: string; }) => { await wwwAXIOS.delete<GetCommentaryAPI>("/commentary", { params: { commentaryID, avatarCipher, }, }); }, onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ["commentary"] }); }, onError: (e) => { if (isClientFault(e)) { toast.error(t("failedValidateCipher")); } }, }); }