disable send if nothing to send

This commit is contained in:
Timur Ercan
2023-02-07 18:36:26 +01:00
parent 2ba4c0a816
commit 3817dc5118

View File

@ -67,10 +67,9 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
}); });
}} }}
disabled={ disabled={
(props?.document?.Recipient?.length || 0) === 0 || (signers.length || 0) === 0 ||
!props?.document?.Recipient?.some( !signers.some((r: any) => r.sendStatus === "NOT_SENT") ||
(r: any) => r.sendStatus === "NOT_SENT" loading
)
} }
> >
Send Send
@ -346,13 +345,22 @@ async function send(document: any) {
// todo toast // todo toast
// loading // loading
if (!document || !document.id) return; if (!document || !document.id) return;
return await fetch(`/api/documents/${document.id}/send`, { return toast
.promise(
fetch(`/api/documents/${document.id}/send`, {
body: "", body: "",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
method: "POST", method: "POST",
}).finally(() => { }),
{
loading: "Sending...",
success: `Sent!`,
error: "Changes could not send :/",
}
)
.finally(() => {
location.reload(); location.reload();
}); });
} }