From 554c641201523f3bcc1ac5958edf3239867e6cd3 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Tue, 7 Feb 2023 12:02:57 +0100 Subject: [PATCH] send signing request --- apps/web/pages/api/documents/[id]/send.ts | 1 + apps/web/pages/documents/[id]/recipients.tsx | 16 ++++++++++++++-- packages/lib/query/getDocument.ts | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/web/pages/api/documents/[id]/send.ts b/apps/web/pages/api/documents/[id]/send.ts index 1921a97e1..a774bfcce 100644 --- a/apps/web/pages/api/documents/[id]/send.ts +++ b/apps/web/pages/api/documents/[id]/send.ts @@ -39,6 +39,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { res.status(200).end(); }) .catch((err) => { + console.log(err); return res.status(502).end("Coud not send request for signing."); }); }); diff --git a/apps/web/pages/documents/[id]/recipients.tsx b/apps/web/pages/documents/[id]/recipients.tsx index efff4fe85..950ffa48b 100644 --- a/apps/web/pages/documents/[id]/recipients.tsx +++ b/apps/web/pages/documents/[id]/recipients.tsx @@ -60,8 +60,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => { color="primary" icon={PaperAirplaneIcon} onClick={() => { - alert(); - // todo do stuff + send(props.document); }} disabled={(props?.document?.Recipient?.length || 0) === 0} > @@ -266,4 +265,17 @@ export async function getServerSideProps(context: any) { }; } +async function send(document: any) { + // todo toast + // loading + if (!document || !document.id) return; + await fetch(`/api/documents/${document.id}/send`, { + body: "", + headers: { + "Content-Type": "application/json", + }, + method: "POST", + }); +} + export default RecipientsPage; diff --git a/packages/lib/query/getDocument.ts b/packages/lib/query/getDocument.ts index f922f4c28..aba4a33af 100644 --- a/packages/lib/query/getDocument.ts +++ b/packages/lib/query/getDocument.ts @@ -19,6 +19,7 @@ export const getDocument = async ( }, include: { Recipient: true, + User: { select: { name: true, email: true } }, }, });