mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
When a dataroom link has file requests enabled and notifications turned on, the team (admin, managers, link owner) receives an email notification when a visitor uploads documents to the dataroom. Uses the same delayed trigger strategy as existing new document notifications: - Cancels any pending notification for the same dataroom+link - Triggers a new notification with a 5-minute delay - The trigger task collects all uploads in that window and sends a single email Components: - Trigger.dev task: send-dataroom-upload-notification (5-min batched) - Email template: DataroomUploadNotification - API endpoint: /api/jobs/send-dataroom-upload-notification - Modified upload route to trigger notification when link.enableNotification is on Co-authored-by: Marc Seitz <[email protected]>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import DataroomUploadNotification from "@/components/emails/dataroom-upload-notification";
|
|
|
|
import { sendEmail } from "@/lib/resend";
|
|
|
|
export const sendDataroomUploadNotification = async ({
|
|
ownerEmail,
|
|
dataroomId,
|
|
dataroomName,
|
|
uploaderEmail,
|
|
documentNames,
|
|
linkName,
|
|
teamMembers,
|
|
}: {
|
|
ownerEmail: string;
|
|
dataroomId: string;
|
|
dataroomName: string;
|
|
uploaderEmail: string | null;
|
|
documentNames: string[];
|
|
linkName: string;
|
|
teamMembers?: string[];
|
|
}) => {
|
|
const documentCount = documentNames.length;
|
|
const documentLabel = documentCount === 1 ? "document" : "documents";
|
|
|
|
let subjectLine = `${documentCount} new ${documentLabel} uploaded to ${dataroomName}`;
|
|
if (uploaderEmail) {
|
|
subjectLine = `${uploaderEmail} uploaded ${documentCount} ${documentLabel} to ${dataroomName}`;
|
|
}
|
|
|
|
const emailTemplate = DataroomUploadNotification({
|
|
dataroomId,
|
|
dataroomName,
|
|
uploaderEmail,
|
|
documentNames,
|
|
linkName,
|
|
});
|
|
|
|
try {
|
|
const data = await sendEmail({
|
|
to: ownerEmail,
|
|
cc: teamMembers,
|
|
subject: subjectLine,
|
|
react: emailTemplate,
|
|
test: process.env.NODE_ENV === "development",
|
|
system: true,
|
|
});
|
|
|
|
return { success: true, data };
|
|
} catch (error) {
|
|
return { success: false, error };
|
|
}
|
|
};
|