mirror of
https://github.com/documenso/documenso.git
synced 2025-11-21 04:01:45 +10:00
feat: update resending email template for team
This commit is contained in:
committed by
Mythie
parent
7562a68cca
commit
f2c3371a99
@ -58,10 +58,17 @@ export const resendDocument = async ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
teamEmail: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const customEmail = document?.documentMeta;
|
const customEmail = document?.documentMeta;
|
||||||
|
const isTeamDocument = document?.team !== null;
|
||||||
|
|
||||||
if (!document) {
|
if (!document) {
|
||||||
throw new Error('Document not found');
|
throw new Error('Document not found');
|
||||||
@ -90,9 +97,21 @@ export const resendDocument = async ({
|
|||||||
const { email, name } = recipient;
|
const { email, name } = recipient;
|
||||||
const selfSigner = email === user.email;
|
const selfSigner = email === user.email;
|
||||||
|
|
||||||
const selfSignerCustomEmail = `You have initiated the document ${`"${document.title}"`} that requires you to ${RECIPIENT_ROLES_DESCRIPTION[
|
const { actionVerb } = RECIPIENT_ROLES_DESCRIPTION[recipient.role];
|
||||||
recipient.role
|
const recipientActionVerb = actionVerb.toLowerCase();
|
||||||
].actionVerb.toLowerCase()} it.`;
|
|
||||||
|
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 = {
|
const customEmailTemplate = {
|
||||||
'signer.name': name,
|
'signer.name': name,
|
||||||
@ -106,23 +125,16 @@ export const resendDocument = async ({
|
|||||||
const template = createElement(DocumentInviteEmailTemplate, {
|
const template = createElement(DocumentInviteEmailTemplate, {
|
||||||
documentName: document.title,
|
documentName: document.title,
|
||||||
inviterName: user.name || undefined,
|
inviterName: user.name || undefined,
|
||||||
inviterEmail: user.email,
|
inviterEmail: isTeamDocument ? document.team?.teamEmail?.email || user.email : user.email,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
signDocumentLink,
|
signDocumentLink,
|
||||||
customBody: renderCustomEmailTemplate(
|
customBody: renderCustomEmailTemplate(emailMessage, customEmailTemplate),
|
||||||
selfSigner && !customEmail?.message ? selfSignerCustomEmail : customEmail?.message || '',
|
|
||||||
customEmailTemplate,
|
|
||||||
),
|
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
selfSigner,
|
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(
|
await prisma.$transaction(
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
await mailer.sendMail({
|
await mailer.sendMail({
|
||||||
|
|||||||
Reference in New Issue
Block a user