Extend user reminder API endpoints
This commit is contained in:
@ -144,9 +144,9 @@ export const postGuildReminder = (guild: string) => ({
|
||||
axios.post(`/dashboard/api/guild/${guild}/reminders`, reminder).then((resp) => resp.data),
|
||||
});
|
||||
|
||||
export const deleteGuildReminder = (guild: string) => ({
|
||||
export const deleteReminder = () => ({
|
||||
mutationFn: (reminder: Reminder) =>
|
||||
axios.delete(`/dashboard/api/guild/${guild}/reminders`, {
|
||||
axios.delete(`/dashboard/api/reminders`, {
|
||||
data: {
|
||||
uid: reminder.uid,
|
||||
},
|
||||
@ -187,3 +187,7 @@ export const postUserReminder = () => ({
|
||||
mutationFn: (reminder: Reminder) =>
|
||||
axios.post(`/dashboard/api/user/reminders`, reminder).then((resp) => resp.data),
|
||||
});
|
||||
|
||||
export const patchUserReminder = () => ({
|
||||
mutationFn: (reminder: Reminder) => axios.patch(`/dashboard/api/user/reminders`, reminder),
|
||||
});
|
||||
|
@ -2,7 +2,6 @@ import { LoadTemplate } from "../LoadTemplate";
|
||||
import { useReminder } from "../ReminderContext";
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { postGuildReminder, postGuildTemplate, postUserReminder } from "../../../api";
|
||||
import { useParams } from "wouter";
|
||||
import { useState } from "preact/hooks";
|
||||
import { ICON_FLASH_TIME } from "../../../consts";
|
||||
import { useFlash } from "../../App/FlashContext";
|
||||
@ -96,34 +95,36 @@ export const CreateButtonRow = () => {
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
<div class="button-row-template">
|
||||
<div>
|
||||
<button
|
||||
class="button is-success is-outlined"
|
||||
onClick={() => {
|
||||
templateMutation.mutate(reminder);
|
||||
}}
|
||||
>
|
||||
<span>Create Template</span>{" "}
|
||||
{templateMutation.isLoading ? (
|
||||
<span class="icon">
|
||||
<i class="fas fa-spin fa-cog"></i>
|
||||
</span>
|
||||
) : templateRecentlyCreated ? (
|
||||
<span class="icon">
|
||||
<i class="fas fa-check"></i>
|
||||
</span>
|
||||
) : (
|
||||
<span class="icon">
|
||||
<i class="fas fa-file-spreadsheet"></i>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
{guild && (
|
||||
<div class="button-row-template">
|
||||
<div>
|
||||
<button
|
||||
class="button is-success is-outlined"
|
||||
onClick={() => {
|
||||
templateMutation.mutate(reminder);
|
||||
}}
|
||||
>
|
||||
<span>Create Template</span>{" "}
|
||||
{templateMutation.isLoading ? (
|
||||
<span class="icon">
|
||||
<i class="fas fa-spin fa-cog"></i>
|
||||
</span>
|
||||
) : templateRecentlyCreated ? (
|
||||
<span class="icon">
|
||||
<i class="fas fa-check"></i>
|
||||
</span>
|
||||
) : (
|
||||
<span class="icon">
|
||||
<i class="fas fa-file-spreadsheet"></i>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<LoadTemplate />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<LoadTemplate />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -2,9 +2,10 @@ import { useState } from "preact/hooks";
|
||||
import { Modal } from "../../Modal";
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { useReminder } from "../ReminderContext";
|
||||
import { deleteGuildReminder } from "../../../api";
|
||||
import { deleteReminder } from "../../../api";
|
||||
import { useParams } from "wouter";
|
||||
import { useFlash } from "../../App/FlashContext";
|
||||
import { useGuild } from "../../App/useGuild";
|
||||
|
||||
export const DeleteButton = () => {
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
@ -26,20 +27,26 @@ export const DeleteButton = () => {
|
||||
|
||||
const DeleteModal = ({ setModalOpen }) => {
|
||||
const [reminder] = useReminder();
|
||||
const { guild } = useParams();
|
||||
const guild = useGuild();
|
||||
|
||||
const flash = useFlash();
|
||||
const queryClient = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
...deleteGuildReminder(guild),
|
||||
...deleteReminder(),
|
||||
onSuccess: () => {
|
||||
flash({
|
||||
message: "Reminder deleted",
|
||||
type: "success",
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["GUILD_REMINDERS", guild],
|
||||
});
|
||||
if (guild) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["GUILD_REMINDERS", guild],
|
||||
});
|
||||
} else {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["USER_REMINDERS"],
|
||||
});
|
||||
}
|
||||
setModalOpen(false);
|
||||
},
|
||||
});
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { useRef, useState } from "preact/hooks";
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { patchGuildReminder } from "../../../api";
|
||||
import { useParams } from "wouter";
|
||||
import { patchGuildReminder, patchUserReminder } from "../../../api";
|
||||
import { ICON_FLASH_TIME } from "../../../consts";
|
||||
import { DeleteButton } from "./DeleteButton";
|
||||
import { useReminder } from "../ReminderContext";
|
||||
import { useFlash } from "../../App/FlashContext";
|
||||
import { useGuild } from "../../App/useGuild";
|
||||
|
||||
export const EditButtonRow = () => {
|
||||
const { guild } = useParams();
|
||||
const guild = useGuild();
|
||||
const [reminder, setReminder] = useReminder();
|
||||
|
||||
const [recentlySaved, setRecentlySaved] = useState(false);
|
||||
@ -18,11 +18,17 @@ export const EditButtonRow = () => {
|
||||
|
||||
const flash = useFlash();
|
||||
const mutation = useMutation({
|
||||
...patchGuildReminder(guild),
|
||||
...(guild ? patchGuildReminder(guild) : patchUserReminder()),
|
||||
onSuccess: (response) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["GUILD_REMINDERS", guild],
|
||||
});
|
||||
if (guild) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["GUILD_REMINDERS", guild],
|
||||
});
|
||||
} else {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["USER_REMINDERS"],
|
||||
});
|
||||
}
|
||||
|
||||
if (iconFlashTimeout.current !== null) {
|
||||
clearTimeout(iconFlashTimeout.current);
|
||||
|
Reference in New Issue
Block a user