From 53c6c5599a995e453d5d7bcef4daccb2239dec09 Mon Sep 17 00:00:00 2001
From: Apoorv Mishra
Date: Wed, 23 Aug 2023 18:43:52 +0530
Subject: [PATCH] Go-To Actions with transactions emails (#5728)
* feat: go-to actions for emails
* fix: comment
* fix: tsc without previewText
* fix: goToAction
* fix: link to original template
* fix: final comments
---
server/emails/mailer.tsx | 71 ++++++++++++++++--
.../templates/CollectionCreatedEmail.tsx | 11 ++-
.../emails/templates/CommentCreatedEmail.tsx | 11 ++-
.../templates/CommentMentionedEmail.tsx | 11 ++-
.../templates/ConfirmUserDeleteEmail.tsx | 2 +-
.../templates/DocumentMentionedEmail.tsx | 11 ++-
.../DocumentPublishedOrUpdatedEmail.tsx | 13 ++--
.../emails/templates/ExportFailureEmail.tsx | 12 ++-
.../emails/templates/ExportSuccessEmail.tsx | 11 ++-
.../emails/templates/InviteAcceptedEmail.tsx | 2 +-
server/emails/templates/InviteEmail.tsx | 6 +-
.../emails/templates/InviteReminderEmail.tsx | 7 +-
server/emails/templates/SigninEmail.tsx | 5 +-
.../emails/templates/WebhookDisabledEmail.tsx | 7 +-
server/emails/templates/WelcomeEmail.tsx | 8 +-
.../templates/components/EmailLayout.tsx | 75 ++++++++++++++++---
16 files changed, 200 insertions(+), 63 deletions(-)
diff --git a/server/emails/mailer.tsx b/server/emails/mailer.tsx
index 1c9186654..ab303792d 100644
--- a/server/emails/mailer.tsx
+++ b/server/emails/mailer.tsx
@@ -56,6 +56,64 @@ export class Mailer {
}
}
+ template = ({
+ title,
+ bodyContent,
+ headCSS = "",
+ bgColor = "#FFFFFF",
+ lang,
+ dir = "ltr" /* https://www.w3.org/TR/html4/struct/dirlang.html#blocklevel-bidi */,
+ }: Oy.CustomTemplateRenderOptions) => {
+ if (!title) {
+ throw new Error("`title` is a required option for `renderTemplate`");
+ } else if (!bodyContent) {
+ throw new Error(
+ "`bodyContent` is a required option for `renderTemplate`"
+ );
+ }
+
+ // the template below is a slightly modified form of https://github.com/revivek/oy/blob/master/src/utils/HTML4.js
+ return `
+
+
+
+
+
+
+
+ ${title}
+
+
+
+
+
+
+ ${bodyContent}
+
+
+ `;
+ };
+
sendMail = async (data: SendMailOptions): Promise => {
const { transporter } = this;
@@ -67,11 +125,14 @@ export class Mailer {
return;
}
- const html = Oy.renderTemplate(data.component, {
- title: data.subject,
- headCSS: [baseStyles, data.headCSS].join(" "),
- previewText: data.previewText ?? "",
- });
+ const html = Oy.renderTemplate(
+ data.component,
+ {
+ title: data.subject,
+ headCSS: [baseStyles, data.headCSS].join(" "),
+ } as Oy.RenderOptions,
+ this.template
+ );
try {
Logger.info("email", `Sending email "${data.subject}" to ${data.to}`);
diff --git a/server/emails/templates/CollectionCreatedEmail.tsx b/server/emails/templates/CollectionCreatedEmail.tsx
index 143b77cf1..ad9a5fca3 100644
--- a/server/emails/templates/CollectionCreatedEmail.tsx
+++ b/server/emails/templates/CollectionCreatedEmail.tsx
@@ -68,8 +68,13 @@ Open Collection: ${teamUrl}${collection.url}
}
protected render({ collection, teamUrl, unsubscribeUrl }: Props) {
+ const collectionLink = `${teamUrl}${collection.url}`;
+
return (
-
+
@@ -80,9 +85,7 @@ Open Collection: ${teamUrl}${collection.url}
-
- Open Collection
-
+ Open Collection
diff --git a/server/emails/templates/CommentCreatedEmail.tsx b/server/emails/templates/CommentCreatedEmail.tsx
index e7a0f99d8..2642fb847 100644
--- a/server/emails/templates/CommentCreatedEmail.tsx
+++ b/server/emails/templates/CommentCreatedEmail.tsx
@@ -147,17 +147,20 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
unsubscribeUrl,
body,
}: Props) {
- const link = `${teamUrl}${document.url}?commentId=${commentId}&ref=notification-email`;
+ const threadLink = `${teamUrl}${document.url}?commentId=${commentId}&ref=notification-email`;
return (
-
+
{document.title}
{actorName} {isReply ? "replied to a thread in" : "commented on"}{" "}
- {document.title} {" "}
+ {document.title} {" "}
{collection.name ? `in the ${collection.name} collection` : ""}.
{body && (
@@ -170,7 +173,7 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
>
)}
- Open Thread
+ Open Thread
diff --git a/server/emails/templates/CommentMentionedEmail.tsx b/server/emails/templates/CommentMentionedEmail.tsx
index 10b4ac1e5..526bef481 100644
--- a/server/emails/templates/CommentMentionedEmail.tsx
+++ b/server/emails/templates/CommentMentionedEmail.tsx
@@ -130,17 +130,20 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
unsubscribeUrl,
body,
}: Props) {
- const link = `${teamUrl}${document.url}?commentId=${commentId}&ref=notification-email`;
+ const threadLink = `${teamUrl}${document.url}?commentId=${commentId}&ref=notification-email`;
return (
-
+
{document.title}
{actorName} mentioned you in a comment on{" "}
- {document.title} {" "}
+ {document.title} {" "}
{collection.name ? `in the ${collection.name} collection` : ""}.
{body && (
@@ -153,7 +156,7 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}
>
)}
- Open Thread
+ Open Thread
diff --git a/server/emails/templates/ConfirmUserDeleteEmail.tsx b/server/emails/templates/ConfirmUserDeleteEmail.tsx
index 6aa467227..9e38d40c5 100644
--- a/server/emails/templates/ConfirmUserDeleteEmail.tsx
+++ b/server/emails/templates/ConfirmUserDeleteEmail.tsx
@@ -38,7 +38,7 @@ Code: ${deleteConfirmationCode}
protected render({ deleteConfirmationCode }: Props) {
return (
-
+
diff --git a/server/emails/templates/DocumentMentionedEmail.tsx b/server/emails/templates/DocumentMentionedEmail.tsx
index dd5ddaab5..d76c3e157 100644
--- a/server/emails/templates/DocumentMentionedEmail.tsx
+++ b/server/emails/templates/DocumentMentionedEmail.tsx
@@ -58,20 +58,23 @@ Open Document: ${teamUrl}${document.url}
}
protected render({ document, actorName, teamUrl }: Props) {
- const link = `${teamUrl}${document.url}?ref=notification-email`;
+ const documentLink = `${teamUrl}${document.url}?ref=notification-email`;
return (
-
+
You were mentioned
{actorName} mentioned you in the document{" "}
- {document.title} .
+ {document.title} .
- Open Document
+ Open Document
diff --git a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx
index e993dd67e..56949be93 100644
--- a/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx
+++ b/server/emails/templates/DocumentPublishedOrUpdatedEmail.tsx
@@ -144,11 +144,14 @@ Open Document: ${teamUrl}${document.url}
unsubscribeUrl,
body,
}: Props) {
- const link = `${teamUrl}${document.url}?ref=notification-email`;
+ const documentLink = `${teamUrl}${document.url}?ref=notification-email`;
const eventName = this.eventName(eventType);
return (
-
+
@@ -157,8 +160,8 @@ Open Document: ${teamUrl}${document.url}
{actorName} {eventName} the document{" "}
- {document.title} , in the {collection.name}{" "}
- collection.
+ {document.title} , in the{" "}
+ {collection.name} collection.
{body && (
<>
@@ -170,7 +173,7 @@ Open Document: ${teamUrl}${document.url}
>
)}
- Open Document
+ Open Document
diff --git a/server/emails/templates/ExportFailureEmail.tsx b/server/emails/templates/ExportFailureEmail.tsx
index 037786f2b..0d011071f 100644
--- a/server/emails/templates/ExportFailureEmail.tsx
+++ b/server/emails/templates/ExportFailureEmail.tsx
@@ -55,25 +55,23 @@ section to try again – if the problem persists please contact support.
}
protected render({ teamUrl, unsubscribeUrl }: Props & BeforeSendProps) {
+ const exportLink = `${teamUrl}/settings/export`;
+
return (
-
+
Your Data Export
Sorry, your requested data export has failed, please visit the{" "}
-
+
admin section
. to try again – if the problem persists please contact support.
- Go to export
+ Go to export
diff --git a/server/emails/templates/ExportSuccessEmail.tsx b/server/emails/templates/ExportSuccessEmail.tsx
index fbf7886f5..ccd543bcf 100644
--- a/server/emails/templates/ExportSuccessEmail.tsx
+++ b/server/emails/templates/ExportSuccessEmail.tsx
@@ -57,8 +57,13 @@ Your requested data export is complete, the exported files are also available in
}
protected render({ id, teamUrl, unsubscribeUrl }: Props & BeforeSendProps) {
+ const downloadLink = `${teamUrl}/api/fileOperations.redirect?id=${id}`;
+
return (
-
+
@@ -77,9 +82,7 @@ Your requested data export is complete, the exported files are also available in
-
- Download
-
+ Download
diff --git a/server/emails/templates/InviteAcceptedEmail.tsx b/server/emails/templates/InviteAcceptedEmail.tsx
index 20b769cac..69c7287f2 100644
--- a/server/emails/templates/InviteAcceptedEmail.tsx
+++ b/server/emails/templates/InviteAcceptedEmail.tsx
@@ -60,7 +60,7 @@ Open ${env.APP_NAME}: ${teamUrl}
unsubscribeUrl,
}: Props & BeforeSendProps) {
return (
-
+
diff --git a/server/emails/templates/InviteEmail.tsx b/server/emails/templates/InviteEmail.tsx
index ab4a41f05..929fbe2e8 100644
--- a/server/emails/templates/InviteEmail.tsx
+++ b/server/emails/templates/InviteEmail.tsx
@@ -47,8 +47,10 @@ Join now: ${teamUrl}
}
protected render({ teamName, actorName, actorEmail, teamUrl }: Props) {
+ const inviteLink = `${teamUrl}?ref=invite-email`;
+
return (
-
+
@@ -62,7 +64,7 @@ Join now: ${teamUrl}
- Join now
+ Join now
diff --git a/server/emails/templates/InviteReminderEmail.tsx b/server/emails/templates/InviteReminderEmail.tsx
index c509391b9..c01ccf7ee 100644
--- a/server/emails/templates/InviteReminderEmail.tsx
+++ b/server/emails/templates/InviteReminderEmail.tsx
@@ -52,8 +52,9 @@ If you haven't signed up yet, you can do so here: ${teamUrl}
}
protected render({ teamName, actorName, actorEmail, teamUrl }: Props) {
+ const inviteLink = `${teamUrl}?ref=invite-reminder-email`;
return (
-
+
@@ -69,9 +70,7 @@ If you haven't signed up yet, you can do so here: ${teamUrl}
If you haven't signed up yet, you can do so here:
-
- Join now
-
+ Join now
diff --git a/server/emails/templates/SigninEmail.tsx b/server/emails/templates/SigninEmail.tsx
index 453e525ac..f3be4b8d2 100644
--- a/server/emails/templates/SigninEmail.tsx
+++ b/server/emails/templates/SigninEmail.tsx
@@ -46,7 +46,10 @@ signin page at: ${teamUrl}
}
return (
-
+
diff --git a/server/emails/templates/WebhookDisabledEmail.tsx b/server/emails/templates/WebhookDisabledEmail.tsx
index 785bafd39..55414754d 100644
--- a/server/emails/templates/WebhookDisabledEmail.tsx
+++ b/server/emails/templates/WebhookDisabledEmail.tsx
@@ -39,8 +39,9 @@ Webhook settings: ${teamUrl}/settings/webhooks
}
protected render({ webhookName, teamUrl }: Props) {
+ const webhookSettingsLink = `${teamUrl}/settings/webhooks`;
return (
-
+
@@ -52,9 +53,7 @@ Webhook settings: ${teamUrl}/settings/webhooks
-
- Webhook settings
-
+ Webhook settings
diff --git a/server/emails/templates/WelcomeEmail.tsx b/server/emails/templates/WelcomeEmail.tsx
index d65d472a3..f8eb428c7 100644
--- a/server/emails/templates/WelcomeEmail.tsx
+++ b/server/emails/templates/WelcomeEmail.tsx
@@ -44,8 +44,10 @@ ${teamUrl}/home
}
protected render({ teamUrl }: Props) {
+ const welcomLink = `${teamUrl}/home?ref=welcome-email`;
+
return (
-
+
@@ -65,9 +67,7 @@ ${teamUrl}/home
-
- Open {env.APP_NAME}
-
+ Open {env.APP_NAME}
diff --git a/server/emails/templates/components/EmailLayout.tsx b/server/emails/templates/components/EmailLayout.tsx
index ff3c68ba6..b72c2c041 100644
--- a/server/emails/templates/components/EmailLayout.tsx
+++ b/server/emails/templates/components/EmailLayout.tsx
@@ -2,15 +2,72 @@ import { Table, TBody, TR, TD } from "oy-vey";
import * as React from "react";
import theme from "@shared/styles/theme";
-const EmailLayout: React.FC = ({ children }) => (
-
-);
+const EmailLayout: React.FC<{
+ bgcolor?: string;
+ previewText: string;
+ goToAction?: { url: string; name: string };
+}> = ({ previewText, bgcolor = "#FFFFFF", goToAction, children }) => {
+ let markup;
+ if (goToAction) {
+ markup = JSON.stringify({
+ "@context": "http://schema.org",
+ "@type": "EmailMessage",
+ potentialAction: {
+ "@type": "ViewAction",
+ url: goToAction.url,
+ name: goToAction.name,
+ },
+ });
+ }
+ return (
+ <>
+ {markup ? (
+
+ ) : null}
+
+
+
+
+ {previewText}
+
+
+
+
+
+ >
+ );
+};
export default EmailLayout;