loading state send bug

This commit is contained in:
Timur Ercan
2023-02-07 12:54:31 +01:00
parent 5c589adda8
commit f831b1ade1
3 changed files with 22 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ import prisma from "@documenso/prisma";
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import { sendSigningRequest } from "@documenso/lib/mail"; import { sendSigningRequest } from "@documenso/lib/mail";
import { getDocument } from "@documenso/lib/query"; import { getDocument } from "@documenso/lib/query";
import { Document as PrismaDocument } from "@prisma/client"; import { Document as PrismaDocument, SendStatus } from "@prisma/client";
async function postHandler(req: NextApiRequest, res: NextApiResponse) { async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const user = await getUserFromToken(req, res); const user = await getUserFromToken(req, res);
@@ -27,16 +27,19 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
// todo handle sending to single recipient even though more exist // todo handle sending to single recipient even though more exist
const recipients = prisma.recipient.findMany({ const recipients = await prisma.recipient.findMany({
where: { where: {
documentId: +documentId, documentId: +documentId,
// sendStatus: SendStatus.NOT_SENT, // TODO REDO AFTER DEBUG sendStatus: SendStatus.NOT_SENT,
}, },
}); });
if (!recipients.length) return res.status(200).end("");
(await recipients).forEach(async (recipient) => { (await recipients).forEach(async (recipient) => {
await sendSigningRequest(recipient, document) await sendSigningRequest(recipient, document)
.then(() => { .then(() => {
res.status(200).end(); return res.status(200).end();
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
@@ -44,6 +47,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
}); });
}); });
// return res.status(500).end();
// todo check if recipient has an account and show them in their inbox or something // todo check if recipient has an account and show them in their inbox or something
} }

View File

@@ -3,7 +3,13 @@ import { ReactElement, useState } from "react";
import Layout from "../../../components/layout"; import Layout from "../../../components/layout";
import { NextPageWithLayout } from "../../_app"; import { NextPageWithLayout } from "../../_app";
import { classNames, NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib"; import { classNames, NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib";
import { CheckBadgeIcon, CheckIcon, PaperAirplaneIcon, UserPlusIcon, XMarkIcon } from "@heroicons/react/24/outline"; import {
CheckBadgeIcon,
CheckIcon,
PaperAirplaneIcon,
UserPlusIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { getUserFromToken } from "@documenso/lib/server"; import { getUserFromToken } from "@documenso/lib/server";
import { getDocument } from "@documenso/lib/query"; import { getDocument } from "@documenso/lib/query";
import { Document as PrismaDocument } from "@prisma/client"; import { Document as PrismaDocument } from "@prisma/client";
@@ -33,6 +39,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
]; ];
const [signers, setSigners] = useState(props?.document?.Recipient); const [signers, setSigners] = useState(props?.document?.Recipient);
const [loading, setLoading] = useState(false);
return ( return (
<> <>
@@ -54,7 +61,10 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
color="primary" color="primary"
icon={PaperAirplaneIcon} icon={PaperAirplaneIcon}
onClick={() => { onClick={() => {
send(props.document); setLoading(true);
send(props.document).finally(() => {
setLoading(false);
});
}} }}
disabled={(props?.document?.Recipient?.length || 0) === 0} disabled={(props?.document?.Recipient?.length || 0) === 0}
> >
@@ -331,7 +341,7 @@ async function send(document: any) {
// todo toast // todo toast
// loading // loading
if (!document || !document.id) return; if (!document || !document.id) return;
await fetch(`/api/documents/${document.id}/send`, { return await fetch(`/api/documents/${document.id}/send`, {
body: "", body: "",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -41,7 +41,7 @@ export function Button(props: any) {
props.className props.className
)} )}
onClick={props.onClick} onClick={props.onClick}
disabled={props.disabled} disabled={props.disabled || props.loading}
hidden={props.hidden} hidden={props.hidden}
> >
{props.icon ? ( {props.icon ? (