Skip to content

Commit f0fe03c

Browse files
authored
feat: standardize the design and content of all email templates (#6553)
1 parent 3043d4e commit f0fe03c

File tree

10 files changed

+141
-1947
lines changed

10 files changed

+141
-1947
lines changed

.changeset/cyan-ears-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Standardize the design and content of all email templates for consistency.

packages/services/emails/src/mjml.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type RawValue = {
88
readonly content: string;
99
};
1010
type SpecialValues = RawValue;
11-
type ValueExpression = string | SpecialValues;
11+
type ValueExpression = string | SpecialValues | MJMLValue;
1212

1313
export function mjml(parts: TemplateStringsArray, ...values: ValueExpression[]): MJMLValue {
1414
let content = '';
@@ -29,6 +29,8 @@ export function mjml(parts: TemplateStringsArray, ...values: ValueExpression[]):
2929
content += token.content;
3030
} else if (typeof token === 'string') {
3131
content += escapeHtml(token);
32+
} else if (token.kind === 'mjml') {
33+
content += token.content;
3234
} else {
3335
throw new TypeError('mjml: Unexpected value expression.');
3436
}
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
import { mjml } from '../mjml';
1+
import { button, email, mjml, paragraph } from './components';
22

33
export function renderAuditLogsReportEmail(input: {
44
organizationName: string;
55
formattedStartDate: string;
66
formattedEndDate: string;
77
url: string;
88
}) {
9-
return mjml`
10-
<mjml>
11-
<mj-body>
12-
<mj-section>
13-
<mj-column>
14-
<mj-image width="150px" src="https://graphql-hive.com/logo.png"></mj-image>
15-
<mj-divider border-color="#ca8a04"></mj-divider>
16-
<mj-text>
17-
Audit Logs for your organization ${input.organizationName} from ${input.formattedStartDate} to ${input.formattedEndDate}
18-
</mj-text>.
19-
<mj-button href="${input.url}" background-color="#ca8a04">
20-
Download Audit Logs CSV
21-
</mj-button>
22-
</mj-column>
23-
</mj-section>
24-
</mj-body>
25-
</mjml>
26-
`.content;
9+
return email({
10+
title: 'Your Requested Audit Logs Are Ready',
11+
body: mjml`
12+
${paragraph(mjml`You requested audit logs for ${input.formattedStartDate}${input.formattedEndDate}, and they are now ready for download.`)}
13+
${paragraph('Click the link below to download your CSV file:')}
14+
${button({ url: input.url, text: 'Download Audit Logs' })}
15+
${paragraph(`If you didn't request this, please contact [email protected].`)}
16+
`,
17+
});
2718
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { mjml, type MJMLValue } from '../mjml';
2+
3+
export { mjml };
4+
5+
export function paragraph(content: string | MJMLValue) {
6+
return mjml`
7+
<mj-text padding-bottom="10px" line-height="1.6" font-size="16px">
8+
${content}
9+
</mj-text>
10+
`;
11+
}
12+
13+
export function button(input: { url: string; text: string }) {
14+
return mjml`
15+
<mj-button align="left" href="${input.url}" font-size="16px" border-radius="3px" color="#fff" background-color="#245850">
16+
${input.text}
17+
</mj-button>
18+
`;
19+
}
20+
21+
export function email(input: { title: string | MJMLValue; body: MJMLValue }) {
22+
return mjml`
23+
<mjml>
24+
<mj-body>
25+
<mj-section background-color="#e6eded">
26+
<mj-column>
27+
<mj-text color="#245850" font-size="28px" font-weight="300">
28+
Hive
29+
</mj-text>
30+
</mj-column>
31+
</mj-section>
32+
33+
<mj-section>
34+
<mj-column>
35+
<mj-text color="#245850" font-size="24px" font-weight="300" padding-bottom="20px">
36+
${input.title}
37+
</mj-text>
38+
${input.body}
39+
</mj-column>
40+
</mj-section>
41+
<mj-section>
42+
<mj-column>
43+
<mj-divider border-width="1px" border-color="#eeeeee"></mj-divider>
44+
<mj-text align="center" padding-bottom="20px" line-height="1.6" font-size="14px" color="#888888">
45+
© ${mjml.raw(String(new Date().getFullYear()))} Hive. All rights reserved.
46+
</mj-text>
47+
</mj-column>
48+
</mj-section>
49+
</mj-body>
50+
</mjml>
51+
`.content;
52+
}

0 commit comments

Comments
 (0)