send fix, send error handling

This commit is contained in:
Timur Ercan
2023-02-09 19:17:34 +01:00
parent 08ec274a22
commit 36df6be703
4 changed files with 28 additions and 13 deletions

View File

@ -430,24 +430,32 @@ async function send(document: any) {
// todo toast
// loading
if (!document || !document.id) return;
return toast
.promise(
try {
const sent = await toast.promise(
fetch(`/api/documents/${document.id}/send`, {
body: "",
headers: {
"Content-Type": "application/json",
},
method: "POST",
}),
})
.then((res: any) => {
if (!res.ok) {
throw new Error(res.status.toString());
}
})
.finally(() => {
location.reload();
}),
{
loading: "Sending...",
success: `Sent!`,
error: "Changes could not send :/",
error: "Could not send :/",
}
)
.finally(() => {
location.reload();
});
);
} catch (err) {
console.log(err);
}
}
export default RecipientsPage;