singed mail template and fixes

This commit is contained in:
Timur Ercan
2023-01-30 17:33:03 +01:00
parent f532e7c738
commit 137c22962f
3 changed files with 44 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import {
} from "@documenso/lib/server"; } from "@documenso/lib/server";
import prisma from "@documenso/prisma"; import prisma from "@documenso/prisma";
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import { sendSigningRequest } from "@documenso/lib/mail"; import { sendSignedMail, sendSigningRequest } from "@documenso/lib/mail";
import { SendStatus } from "@prisma/client"; import { SendStatus } from "@prisma/client";
async function postHandler(req: NextApiRequest, res: NextApiResponse) { async function postHandler(req: NextApiRequest, res: NextApiResponse) {
@ -42,13 +42,14 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const recipients = prisma.recipient.findMany({ const recipients = prisma.recipient.findMany({
where: { where: {
documentId: +documentId, documentId: +documentId,
sendStatus: SendStatus.NOT_SENT, // TODO REDO AFTER DEBUG // sendStatus: SendStatus.NOT_SENT, // TODO REDO AFTER DEBUG
}, },
}); });
// 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
(await recipients).forEach(async (recipient) => { (await recipients).forEach(async (recipient) => {
await sendSigningRequest(recipient, document); await sendSigningRequest(recipient, document);
await sendSignedMail(recipient, document);
}); });
// todo way better error handling // todo way better error handling

View File

@ -1,11 +1,46 @@
import { sendMail } from "./sendMail"; import { sendMail } from "./sendMail";
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants"; import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
export const sendSignedMail = async (document: any, recipient: any) => { export const sendSignedMail = async (recipient: any, document: any) => {
// todo check if recipient has an account // todo check if recipient has an account
await sendMail( await sendMail(
document.user.email, document.User.email,
`${recipient.email} signed ${document.title}`, `${recipient.email} signed "${document.title}"`,
`Hi ${document.user.name}, ${recipient.email} has signed your document ${document.title}. Click <a href="${NEXT_PUBLIC_WEBAPP_URL}/document/${document.id}}"> VIEW DOCUMENT</a> to view it now.` `
<div style="background-color: #eaeaea; padding: 2%;">
<div style="text-align:center; margin: auto; font-size: 14px; font-color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo" style="width: 180px; display: block; margin: auto; margin-bottom: 14px;
}">
${document.User.name || recipient.email} has signed your document ${
document.title
}.
<p style="margin: 24px;">
<a href="${NEXT_PUBLIC_WEBAPP_URL}/documents/${
document.id
}" style="background-color: #37f095; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none;">
View Document
</a>
</p>
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">
Click the button to view ${document.title}.<br>
<small>If you have questions about this document, your should ask ${
document.User.name
}.</small>
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">
</div>
<div style="text-align: left; line-height: 18px; color: #666666; margin: 24px">
<div>
<b>Do not forward.</b>
<br>
This email contains a link to a secure document. Keep it secret and do not forward this email.
</div>
<div style="margin-top: 12px">
<b>Need help?</b>
<br>
Contact us at <a href="mailto:hi@documenso.com">hi@documenso.com</a>
</div>
</div>
`
); );
}; };

View File

@ -6,7 +6,7 @@ import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
export const sendSigningRequest = async (recipient: any, document: any) => { export const sendSigningRequest = async (recipient: any, document: any) => {
// todo errror handling // todo errror handling
await sendMail( await sendMail(
"timur.ercan31+234234@gmail.com", document.User.email,
`Please sign ${document.title}`, `Please sign ${document.title}`,
` `
<div style="background-color: #eaeaea; padding: 2%;"> <div style="background-color: #eaeaea; padding: 2%;">
@ -15,7 +15,7 @@ export const sendSigningRequest = async (recipient: any, document: any) => {
}"> }">
${document.User.name} (${document.User.email}) has sent you a document to sign. ${document.User.name} (${document.User.email}) has sent you a document to sign.
<p style="margin: 24px;"> <p style="margin: 24px;">
<a href="${NEXT_PUBLIC_WEBAPP_URL}/document/${document.id}/sign?token=${recipient.token}" style="background-color: #37f095; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none;"> <a href="${NEXT_PUBLIC_WEBAPP_URL}/documents/${document.id}/sign?token=${recipient.token}" style="background-color: #37f095; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none;">
Sign Document Sign Document
</a> </a>
</p> </p>