mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
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';
|
||||
|
||||
export interface TemplateDocumentDeleteProps {
|
||||
inviterName: string;
|
||||
inviterEmail: string;
|
||||
reason: string;
|
||||
documentName: string;
|
||||
assetBaseUrl: string;
|
||||
|
||||
@ -9,14 +9,12 @@ import { TemplateFooter } from '../template-components/template-footer';
|
||||
|
||||
export type DocumentDeleteEmailTemplateProps = Partial<TemplateDocumentDeleteProps>;
|
||||
|
||||
export const DocumentDeleteTemplate = ({
|
||||
inviterName = 'Lucas Smith',
|
||||
inviterEmail = 'lucas@documenso.com',
|
||||
export const DocumentDeleteEmailTemplate = ({
|
||||
documentName = 'Open Source Pledge.pdf',
|
||||
assetBaseUrl = 'http://localhost:3002',
|
||||
reason = 'Unknown',
|
||||
}: 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) => {
|
||||
return new URL(path, assetBaseUrl).toString();
|
||||
@ -45,11 +43,9 @@ export const DocumentDeleteTemplate = ({
|
||||
className="mb-4 h-6"
|
||||
/>
|
||||
<TemplateDocumentDelete
|
||||
inviterName={inviterName}
|
||||
reason={reason}
|
||||
documentName={documentName}
|
||||
assetBaseUrl={assetBaseUrl}
|
||||
inviterEmail={inviterEmail}
|
||||
/>
|
||||
</Section>
|
||||
</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