feat: send delete email is added
This commit is contained in:
@@ -2,8 +2,6 @@ import { Section, Text } from '../components';
|
|||||||
import { TemplateDocumentImage } from './template-document-image';
|
import { TemplateDocumentImage } from './template-document-image';
|
||||||
|
|
||||||
export interface TemplateDocumentDeleteProps {
|
export interface TemplateDocumentDeleteProps {
|
||||||
inviterName: string;
|
|
||||||
inviterEmail: string;
|
|
||||||
reason: string;
|
reason: string;
|
||||||
documentName: string;
|
documentName: string;
|
||||||
assetBaseUrl: string;
|
assetBaseUrl: string;
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import { TemplateFooter } from '../template-components/template-footer';
|
|||||||
|
|
||||||
export type DocumentDeleteEmailTemplateProps = Partial<TemplateDocumentDeleteProps>;
|
export type DocumentDeleteEmailTemplateProps = Partial<TemplateDocumentDeleteProps>;
|
||||||
|
|
||||||
export const DocumentDeleteTemplate = ({
|
export const DocumentDeleteEmailTemplate = ({
|
||||||
inviterName = 'Lucas Smith',
|
|
||||||
inviterEmail = 'lucas@documenso.com',
|
|
||||||
documentName = 'Open Source Pledge.pdf',
|
documentName = 'Open Source Pledge.pdf',
|
||||||
assetBaseUrl = 'http://localhost:3002',
|
assetBaseUrl = 'http://localhost:3002',
|
||||||
reason = 'Unknown',
|
reason = 'Unknown',
|
||||||
}: DocumentDeleteEmailTemplateProps) => {
|
}: DocumentDeleteEmailTemplateProps) => {
|
||||||
const previewText = `${inviterName} has cancelled the document ${documentName}, you don't need to sign it anymore.`;
|
const previewText = `Admin has deleted your document ${documentName}.`;
|
||||||
|
|
||||||
const getAssetUrl = (path: string) => {
|
const getAssetUrl = (path: string) => {
|
||||||
return new URL(path, assetBaseUrl).toString();
|
return new URL(path, assetBaseUrl).toString();
|
||||||
@@ -45,11 +43,9 @@ export const DocumentDeleteTemplate = ({
|
|||||||
className="mb-4 h-6"
|
className="mb-4 h-6"
|
||||||
/>
|
/>
|
||||||
<TemplateDocumentDelete
|
<TemplateDocumentDelete
|
||||||
inviterName={inviterName}
|
|
||||||
reason={reason}
|
reason={reason}
|
||||||
documentName={documentName}
|
documentName={documentName}
|
||||||
assetBaseUrl={assetBaseUrl}
|
assetBaseUrl={assetBaseUrl}
|
||||||
inviterEmail={inviterEmail}
|
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
</Container>
|
</Container>
|
||||||
@@ -66,4 +62,4 @@ export const DocumentDeleteTemplate = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DocumentDeleteTemplate;
|
export default DocumentDeleteEmailTemplate;
|
||||||
|
|||||||
51
packages/lib/server-only/document/send-delete-email.ts
Normal file
51
packages/lib/server-only/document/send-delete-email.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { createElement } from 'react';
|
||||||
|
|
||||||
|
import { mailer } from '@documenso/email/mailer';
|
||||||
|
import { render } from '@documenso/email/render';
|
||||||
|
import { DocumentDeleteEmailTemplate } from '@documenso/email/templates/document-delete';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||||
|
|
||||||
|
export interface SendDeleteEmailOptions {
|
||||||
|
documentId: number;
|
||||||
|
reason: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sendDeleteEmail = async ({ documentId, reason }: SendDeleteEmailOptions) => {
|
||||||
|
const document = await prisma.document.findFirst({
|
||||||
|
where: {
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
User: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!document) {
|
||||||
|
throw new Error('Document not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { email, name } = document.User;
|
||||||
|
|
||||||
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
|
const template = createElement(DocumentDeleteEmailTemplate, {
|
||||||
|
documentName: document.title,
|
||||||
|
assetBaseUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
await mailer.sendMail({
|
||||||
|
to: {
|
||||||
|
address: email,
|
||||||
|
name: name || '',
|
||||||
|
},
|
||||||
|
from: {
|
||||||
|
name: process.env.NEXT_PRIVATE_SMTP_FROM_NAME || 'Documenso',
|
||||||
|
address: process.env.NEXT_PRIVATE_SMTP_FROM_ADDRESS || 'noreply@documenso.com',
|
||||||
|
},
|
||||||
|
subject: 'Document Deleted!',
|
||||||
|
html: render(template),
|
||||||
|
text: render(template, { plainText: true }),
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user