mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 11:41:44 +10:00
feat: seperate text for email when document is being sent from team
This commit is contained in:
committed by
Mythie
parent
7a1341eb74
commit
7562a68cca
@ -12,6 +12,8 @@ export interface TemplateDocumentInviteProps {
|
|||||||
assetBaseUrl: string;
|
assetBaseUrl: string;
|
||||||
role: RecipientRole;
|
role: RecipientRole;
|
||||||
selfSigner: boolean;
|
selfSigner: boolean;
|
||||||
|
isTeamInvite: boolean;
|
||||||
|
teamName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TemplateDocumentInvite = ({
|
export const TemplateDocumentInvite = ({
|
||||||
@ -21,6 +23,8 @@ export const TemplateDocumentInvite = ({
|
|||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
role,
|
role,
|
||||||
selfSigner,
|
selfSigner,
|
||||||
|
isTeamInvite,
|
||||||
|
teamName,
|
||||||
}: TemplateDocumentInviteProps) => {
|
}: TemplateDocumentInviteProps) => {
|
||||||
const { actionVerb, progressiveVerb } = RECIPIENT_ROLES_DESCRIPTION[role];
|
const { actionVerb, progressiveVerb } = RECIPIENT_ROLES_DESCRIPTION[role];
|
||||||
|
|
||||||
@ -36,6 +40,12 @@ export const TemplateDocumentInvite = ({
|
|||||||
<br />
|
<br />
|
||||||
{`"${documentName}"`}
|
{`"${documentName}"`}
|
||||||
</>
|
</>
|
||||||
|
) : isTeamInvite ? (
|
||||||
|
<>
|
||||||
|
{`${inviterName} on behalf of ${teamName} has invited you to ${actionVerb.toLowerCase()}`}
|
||||||
|
<br />
|
||||||
|
{`"${documentName}"`}
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{`${inviterName} has invited you to ${actionVerb.toLowerCase()}`}
|
{`${inviterName} has invited you to ${actionVerb.toLowerCase()}`}
|
||||||
|
|||||||
@ -23,6 +23,9 @@ export type DocumentInviteEmailTemplateProps = Partial<TemplateDocumentInvitePro
|
|||||||
customBody?: string;
|
customBody?: string;
|
||||||
role: RecipientRole;
|
role: RecipientRole;
|
||||||
selfSigner?: boolean;
|
selfSigner?: boolean;
|
||||||
|
isTeamInvite?: boolean;
|
||||||
|
teamName?: string;
|
||||||
|
teamEmail?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DocumentInviteEmailTemplate = ({
|
export const DocumentInviteEmailTemplate = ({
|
||||||
@ -34,11 +37,15 @@ export const DocumentInviteEmailTemplate = ({
|
|||||||
customBody,
|
customBody,
|
||||||
role,
|
role,
|
||||||
selfSigner = false,
|
selfSigner = false,
|
||||||
|
isTeamInvite = false,
|
||||||
|
teamName,
|
||||||
}: DocumentInviteEmailTemplateProps) => {
|
}: DocumentInviteEmailTemplateProps) => {
|
||||||
const action = RECIPIENT_ROLES_DESCRIPTION[role].actionVerb.toLowerCase();
|
const action = RECIPIENT_ROLES_DESCRIPTION[role].actionVerb.toLowerCase();
|
||||||
|
|
||||||
const previewText = selfSigner
|
const previewText = selfSigner
|
||||||
? `Please ${action} your document ${documentName}`
|
? `Please ${action} your document ${documentName}`
|
||||||
|
: isTeamInvite
|
||||||
|
? `${inviterName} on behalf of ${teamName} has invited you to ${action} ${documentName}`
|
||||||
: `${inviterName} has invited you to ${action} ${documentName}`;
|
: `${inviterName} has invited you to ${action} ${documentName}`;
|
||||||
|
|
||||||
const getAssetUrl = (path: string) => {
|
const getAssetUrl = (path: string) => {
|
||||||
@ -76,6 +83,8 @@ export const DocumentInviteEmailTemplate = ({
|
|||||||
assetBaseUrl={assetBaseUrl}
|
assetBaseUrl={assetBaseUrl}
|
||||||
role={role}
|
role={role}
|
||||||
selfSigner={selfSigner}
|
selfSigner={selfSigner}
|
||||||
|
isTeamInvite={isTeamInvite}
|
||||||
|
teamName={teamName}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@ -58,6 +58,12 @@ export const SEND_SIGNING_EMAIL_JOB_DEFINITION = {
|
|||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
documentMeta: true,
|
documentMeta: true,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
teamEmail: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.recipient.findFirstOrThrow({
|
prisma.recipient.findFirstOrThrow({
|
||||||
@ -67,7 +73,7 @@ export const SEND_SIGNING_EMAIL_JOB_DEFINITION = {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { documentMeta } = document;
|
const { documentMeta, team } = document;
|
||||||
|
|
||||||
if (recipient.role === RecipientRole.CC) {
|
if (recipient.role === RecipientRole.CC) {
|
||||||
return;
|
return;
|
||||||
@ -75,6 +81,7 @@ export const SEND_SIGNING_EMAIL_JOB_DEFINITION = {
|
|||||||
|
|
||||||
const customEmail = document?.documentMeta;
|
const customEmail = document?.documentMeta;
|
||||||
const isDirectTemplate = document.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
const isDirectTemplate = document.source === DocumentSource.TEMPLATE_DIRECT_LINK;
|
||||||
|
const isTeamDocument = document.teamId !== null;
|
||||||
|
|
||||||
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
const recipientEmailType = RECIPIENT_ROLE_TO_EMAIL_TYPE[recipient.role];
|
||||||
|
|
||||||
@ -96,6 +103,11 @@ export const SEND_SIGNING_EMAIL_JOB_DEFINITION = {
|
|||||||
emailSubject = `Please ${recipientActionVerb} this document created by your direct template`;
|
emailSubject = `Please ${recipientActionVerb} this document created by your direct template`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTeamDocument && team) {
|
||||||
|
emailSubject = `${team.name} invited you to ${recipientActionVerb} a document`;
|
||||||
|
emailMessage = `${user.name} on behalf of ${team.name} has invited you to ${recipientActionVerb} the document "${document.title}".`;
|
||||||
|
}
|
||||||
|
|
||||||
const customEmailTemplate = {
|
const customEmailTemplate = {
|
||||||
'signer.name': name,
|
'signer.name': name,
|
||||||
'signer.email': email,
|
'signer.email': email,
|
||||||
@ -108,12 +120,15 @@ export const SEND_SIGNING_EMAIL_JOB_DEFINITION = {
|
|||||||
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 ? team?.teamEmail?.email || user.email : user.email,
|
||||||
assetBaseUrl,
|
assetBaseUrl,
|
||||||
signDocumentLink,
|
signDocumentLink,
|
||||||
customBody: renderCustomEmailTemplate(emailMessage, customEmailTemplate),
|
customBody: renderCustomEmailTemplate(emailMessage, customEmailTemplate),
|
||||||
role: recipient.role,
|
role: recipient.role,
|
||||||
selfSigner,
|
selfSigner,
|
||||||
|
isTeamInvite: isTeamDocument,
|
||||||
|
teamName: team?.name,
|
||||||
|
teamEmail: team?.teamEmail?.email,
|
||||||
});
|
});
|
||||||
|
|
||||||
await io.runTask('send-signing-email', async () => {
|
await io.runTask('send-signing-email', async () => {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import path from 'node:path';
|
|||||||
import { hashSync } from '@documenso/lib/server-only/auth/hash';
|
import { hashSync } from '@documenso/lib/server-only/auth/hash';
|
||||||
|
|
||||||
import { prisma } from '..';
|
import { prisma } from '..';
|
||||||
import { DocumentDataType, DocumentSource, Role } from '../client';
|
import { DocumentDataType, DocumentSource, Role, TeamMemberRole } from '../client';
|
||||||
|
|
||||||
export const seedDatabase = async () => {
|
export const seedDatabase = async () => {
|
||||||
const examplePdf = fs
|
const examplePdf = fs
|
||||||
@ -67,4 +67,64 @@ export const seedDatabase = async () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const testUsers = [
|
||||||
|
'test@documenso.com',
|
||||||
|
'test2@documenso.com',
|
||||||
|
'test3@documenso.com',
|
||||||
|
'test4@documenso.com',
|
||||||
|
];
|
||||||
|
|
||||||
|
const createdUsers = [];
|
||||||
|
|
||||||
|
for (const email of testUsers) {
|
||||||
|
const testUser = await prisma.user.upsert({
|
||||||
|
where: {
|
||||||
|
email: email,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
name: 'Test User',
|
||||||
|
email: email,
|
||||||
|
emailVerified: new Date(),
|
||||||
|
password: hashSync('password'),
|
||||||
|
roles: [Role.USER],
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
createdUsers.push(testUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
const team1 = await prisma.team.create({
|
||||||
|
data: {
|
||||||
|
name: 'Team 1',
|
||||||
|
url: 'team1',
|
||||||
|
ownerUserId: createdUsers[0].id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const team2 = await prisma.team.create({
|
||||||
|
data: {
|
||||||
|
name: 'Team 2',
|
||||||
|
url: 'team2',
|
||||||
|
ownerUserId: createdUsers[1].id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const team of [team1, team2]) {
|
||||||
|
await prisma.teamMember.createMany({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
teamId: team.id,
|
||||||
|
userId: createdUsers[1].id,
|
||||||
|
role: TeamMemberRole.MEMBER,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
teamId: team.id,
|
||||||
|
userId: createdUsers[2].id,
|
||||||
|
role: TeamMemberRole.MEMBER,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user