mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
loading state send bug
This commit is contained in:
@ -7,7 +7,7 @@ import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { sendSigningRequest } from "@documenso/lib/mail";
|
||||
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) {
|
||||
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
|
||||
|
||||
const recipients = prisma.recipient.findMany({
|
||||
const recipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
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 sendSigningRequest(recipient, document)
|
||||
.then(() => {
|
||||
res.status(200).end();
|
||||
return res.status(200).end();
|
||||
})
|
||||
.catch((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
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,13 @@ import { ReactElement, useState } from "react";
|
||||
import Layout from "../../../components/layout";
|
||||
import { NextPageWithLayout } from "../../_app";
|
||||
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 { getDocument } from "@documenso/lib/query";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
@ -33,6 +39,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
||||
];
|
||||
|
||||
const [signers, setSigners] = useState(props?.document?.Recipient);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -54,7 +61,10 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
||||
color="primary"
|
||||
icon={PaperAirplaneIcon}
|
||||
onClick={() => {
|
||||
send(props.document);
|
||||
setLoading(true);
|
||||
send(props.document).finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
}}
|
||||
disabled={(props?.document?.Recipient?.length || 0) === 0}
|
||||
>
|
||||
@ -331,7 +341,7 @@ async function send(document: any) {
|
||||
// todo toast
|
||||
// loading
|
||||
if (!document || !document.id) return;
|
||||
await fetch(`/api/documents/${document.id}/send`, {
|
||||
return await fetch(`/api/documents/${document.id}/send`, {
|
||||
body: "",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@ -41,7 +41,7 @@ export function Button(props: any) {
|
||||
props.className
|
||||
)}
|
||||
onClick={props.onClick}
|
||||
disabled={props.disabled}
|
||||
disabled={props.disabled || props.loading}
|
||||
hidden={props.hidden}
|
||||
>
|
||||
{props.icon ? (
|
||||
|
||||
Reference in New Issue
Block a user