Fix import/export showing "Malformed base64"

This commit is contained in:
jude 2024-03-26 17:43:35 +00:00
parent 67b6f30c62
commit ba3c76c25f

View File

@ -3,6 +3,8 @@ import { useRef, useState } from "preact/hooks";
import { useParams } from "wouter"; import { useParams } from "wouter";
import axios from "axios"; import axios from "axios";
import { useFlash } from "../App/FlashContext"; import { useFlash } from "../App/FlashContext";
import { useGuild } from "../App/useGuild";
import { useQueryClient } from "react-query";
export const Import = () => { export const Import = () => {
const [modalOpen, setModalOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false);
@ -27,7 +29,7 @@ export const Import = () => {
}; };
const ImportModal = ({ setModalOpen }) => { const ImportModal = ({ setModalOpen }) => {
const { guild } = useParams(); const guild = useGuild();
const aRef = useRef<HTMLAnchorElement>(); const aRef = useRef<HTMLAnchorElement>();
const inputRef = useRef<HTMLInputElement>(); const inputRef = useRef<HTMLInputElement>();
@ -35,6 +37,8 @@ const ImportModal = ({ setModalOpen }) => {
const [isImporting, setIsImporting] = useState(false); const [isImporting, setIsImporting] = useState(false);
const queryClient = useQueryClient();
return ( return (
<Modal <Modal
setModalOpen={setModalOpen} setModalOpen={setModalOpen}
@ -121,7 +125,7 @@ const ImportModal = ({ setModalOpen }) => {
axios axios
.put(`/dashboard/api/guild/${guild}/export/reminders`, { .put(`/dashboard/api/guild/${guild}/export/reminders`, {
body: JSON.stringify({ body: dataUrl.split(",")[1] }), body: dataUrl.split(",")[1],
}) })
.then(({ data }) => { .then(({ data }) => {
setIsImporting(false); setIsImporting(false);
@ -130,6 +134,9 @@ const ImportModal = ({ setModalOpen }) => {
flash({ message: data.error, type: "error" }); flash({ message: data.error, type: "error" });
} else { } else {
flash({ message: data.message, type: "success" }); flash({ message: data.message, type: "success" });
queryClient.invalidateQueries({
queryKey: ["GUILD_REMINDERS", guild],
});
} }
}) })
.then(() => { .then(() => {