Update interface for template import/export

This commit is contained in:
jude 2024-11-16 14:35:19 +00:00
parent 0a9c390f32
commit 0f9d3eda9a

View File

@ -33,6 +33,7 @@ const ImportModal = ({ setModalOpen }) => {
const aRef = useRef<HTMLAnchorElement>(); const aRef = useRef<HTMLAnchorElement>();
const inputRef = useRef<HTMLInputElement>(); const inputRef = useRef<HTMLInputElement>();
const selectRef = useRef<HTMLSelectElement>();
const flash = useFlash(); const flash = useFlash();
const [isImporting, setIsImporting] = useState(false); const [isImporting, setIsImporting] = useState(false);
@ -55,17 +56,16 @@ const ImportModal = ({ setModalOpen }) => {
> >
<> <>
<div class="control"> <div class="control">
<div class="field"> <div class="field select">
<label> <select
<input name="exportSelect"
type="radio" style={{ width: "100%" }}
class="default-width" value="reminders"
name="exportSelect" ref={selectRef}
value="reminders" >
checked <option value="reminders">Reminders</option>
/> <option value="reminder_templates">Reminder templates</option>
Reminders </select>
</label>
</div> </div>
</div> </div>
<br /> <br />
@ -90,7 +90,9 @@ const ImportModal = ({ setModalOpen }) => {
id="export-data" id="export-data"
onClick={() => onClick={() =>
axios axios
.get(`/dashboard/api/guild/${guild}/export/reminders`) .get(
`/dashboard/api/guild/${guild}/export/${selectRef.current.value}`,
)
.then(({ data, status }) => { .then(({ data, status }) => {
if (status === 200) { if (status === 200) {
aRef.current.href = `data:text/plain;charset=utf-8,${encodeURIComponent( aRef.current.href = `data:text/plain;charset=utf-8,${encodeURIComponent(
@ -124,11 +126,15 @@ const ImportModal = ({ setModalOpen }) => {
setIsImporting(true); setIsImporting(true);
axios axios
.put(`/dashboard/api/guild/${guild}/export/reminders`, { .put(
body: dataUrl.split(",")[1], `/dashboard/api/guild/${guild}/export/${selectRef.current.value}`,
}) {
body: dataUrl.split(",")[1],
},
)
.then(({ data }) => { .then(({ data }) => {
setIsImporting(false); setIsImporting(false);
setModalOpen(false);
if (data.error) { if (data.error) {
flash({ message: data.error, type: "error" }); flash({ message: data.error, type: "error" });
@ -137,6 +143,9 @@ const ImportModal = ({ setModalOpen }) => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
queryKey: ["GUILD_REMINDERS", guild], queryKey: ["GUILD_REMINDERS", guild],
}); });
queryClient.invalidateQueries({
queryKey: ["GUILD_TEMPLATES", guild],
});
} }
}) })
.then(() => { .then(() => {