From f2c3371a9933de33d8c33c97c312093eb0cbce01 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Fri, 12 Jul 2024 17:47:26 +0000 Subject: [PATCH] feat: update resending email template for team --- .../server-only/document/resend-document.tsx | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/lib/server-only/document/resend-document.tsx b/packages/lib/server-only/document/resend-document.tsx index c8a51cac4..8ea39445c 100644 --- a/packages/lib/server-only/document/resend-document.tsx +++ b/packages/lib/server-only/document/resend-document.tsx @@ -58,10 +58,17 @@ export const resendDocument = async ({ }, }, documentMeta: true, + team: { + select: { + teamEmail: true, + name: true, + }, + }, }, }); const customEmail = document?.documentMeta; + const isTeamDocument = document?.team !== null; if (!document) { throw new Error('Document not found'); @@ -90,9 +97,21 @@ export const resendDocument = async ({ const { email, name } = recipient; const selfSigner = email === user.email; - const selfSignerCustomEmail = `You have initiated the document ${`"${document.title}"`} that requires you to ${RECIPIENT_ROLES_DESCRIPTION[ - recipient.role - ].actionVerb.toLowerCase()} it.`; + const { actionVerb } = RECIPIENT_ROLES_DESCRIPTION[recipient.role]; + const recipientActionVerb = actionVerb.toLowerCase(); + + let emailMessage = customEmail?.message || ''; + let emailSubject = `Reminder: Please ${recipientActionVerb} this document`; + + if (selfSigner) { + emailMessage = `You have initiated the document ${`"${document.title}"`} that requires you to ${recipientActionVerb} it.`; + emailSubject = `Reminder: Please ${recipientActionVerb} your document`; + } + + if (isTeamDocument && document.team) { + emailSubject = `Reminder: ${document.team.name} invited you to ${recipientActionVerb} a document`; + emailMessage = `${user.name} on behalf of ${document.team.name} has invited you to ${recipientActionVerb} the document "${document.title}".`; + } const customEmailTemplate = { 'signer.name': name, @@ -106,23 +125,16 @@ export const resendDocument = async ({ const template = createElement(DocumentInviteEmailTemplate, { documentName: document.title, inviterName: user.name || undefined, - inviterEmail: user.email, + inviterEmail: isTeamDocument ? document.team?.teamEmail?.email || user.email : user.email, assetBaseUrl, signDocumentLink, - customBody: renderCustomEmailTemplate( - selfSigner && !customEmail?.message ? selfSignerCustomEmail : customEmail?.message || '', - customEmailTemplate, - ), + customBody: renderCustomEmailTemplate(emailMessage, customEmailTemplate), role: recipient.role, selfSigner, + isTeamInvite: isTeamDocument, + teamName: document.team?.name, }); - const { actionVerb } = RECIPIENT_ROLES_DESCRIPTION[recipient.role]; - - const emailSubject = selfSigner - ? `Reminder: Please ${actionVerb.toLowerCase()} your document` - : `Reminder: Please ${actionVerb.toLowerCase()} this document`; - await prisma.$transaction( async (tx) => { await mailer.sendMail({