Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kdembler committed Aug 31, 2023
1 parent d2af87b commit e8e103f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
"tscpaths": "^0.0.9",
"typescript": "^4.9.5"
}
}
}
6 changes: 3 additions & 3 deletions packages/server/src/auth/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { verifySignature } from '@/auth/model/signature'
import { createAuthToken, createEmailToken } from '@/auth/model/token'
import { Context } from '@/common/api'
import { PIONEER_URL } from '@/common/config'
import PioneerEmail from '@/common/email-templates/pioneer-email'
import PioneerEmailTemplate from '@/common/email-templates/pioneer-email'
import { createEmailProvider } from '@/common/utils/email'

const emailProvider = createEmailProvider()
Expand Down Expand Up @@ -69,11 +69,11 @@ export const signup = mutationField('signup', {
to: args.email,
subject: 'Confirm your email for Pioneer',
html: render(
PioneerEmail({
PioneerEmailTemplate({
memberHandle: args.name,
summary: 'Confirm your email for Pioneer',
text: 'Please use the link below to confirm your email address for Pioneer notifications',
cta: {
button: {
label: 'Confirm email',
href: verificationUrl,
},
Expand Down
21 changes: 11 additions & 10 deletions packages/server/src/common/email-templates/pioneer-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ import * as React from 'react'

import { PIONEER_URL } from '../config'

interface PioneerEmailProps {
interface PioneerEmailTemplateProps {
memberHandle: string
text: string
summary: string
cta?: {
button: {
href: string
label: string
}
}

export const PioneerEmail = ({
export const PioneerEmailTemplate = ({
memberHandle = 'bob',
text = 'New council election has just started. Follow the link below to announce your candidacy.',
summary,
cta = {
href: 'https://pioneer.dev',
// button default value only for email development preview
button = {
href: `${PIONEER_URL}/#/election`,
label: 'See on Pioneer',
},
}: PioneerEmailProps) => (
}: PioneerEmailTemplateProps) => (
<Html>
<Head />
<Preview>{summary}</Preview>
Expand All @@ -47,9 +48,9 @@ export const PioneerEmail = ({
<Section style={mainSectionStyle}>
<Heading style={h1Style}>Hi {memberHandle},</Heading>
<Text style={textStyle}>{text}</Text>
{cta && (
<Button href={cta.href} style={ctaStyle} pX={16} pY={12}>
{cta.label}
{button && (
<Button href={button.href} style={ctaStyle} pX={16} pY={12}>
{button.label}
</Button>
)}
</Section>
Expand Down Expand Up @@ -86,7 +87,7 @@ export const PioneerEmail = ({
</Html>
)

export default PioneerEmail
export default PioneerEmailTemplate

const bodyStyle = {
backgroundColor: '#ffffff',
Expand Down
22 changes: 13 additions & 9 deletions packages/server/src/notifier/model/email/forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@react-email/render'
import { match } from 'ts-pattern'

import { PIONEER_URL } from '@/common/config'
import { PioneerEmail } from '@/common/email-templates/pioneer-email'
import { PioneerEmailTemplate } from '@/common/email-templates/pioneer-email'

import { EmailFromNotificationFn, getForumPost, getForumThread } from './utils'

Expand Down Expand Up @@ -30,6 +30,7 @@ export const fromPostAddedNotification: EmailFromNotificationFn = async ({ id, k
const { author, thread, threadId } = await getForumPost(entityId)

const emailSubject = `[Pioneer forum] ${thread}`

const emailSummary: string = match(kind)
.with('FORUM_THREAD_CONTRIBUTOR', 'FORUM_THREAD_CREATOR', () => `${author} replied in the thread ${thread}.`)
.with('FORUM_POST_MENTION', () => `${author} mentioned you in the thread ${thread}.`)
Expand All @@ -40,6 +41,7 @@ export const fromPostAddedNotification: EmailFromNotificationFn = async ({ id, k
() => `${author} posted in the thread ${thread}.`
)
.exhaustive()

const emailText: string = match(kind)
.with('FORUM_THREAD_CONTRIBUTOR', 'FORUM_THREAD_CREATOR', () => `${author} replied in the thread ${thread}.`)
.with('FORUM_POST_MENTION', () => `${author} mentioned you in the thread ${thread}.`)
Expand All @@ -51,12 +53,12 @@ export const fromPostAddedNotification: EmailFromNotificationFn = async ({ id, k
)
.exhaustive()

const renderedEmail = render(
PioneerEmail({
const emailHtml = render(
PioneerEmailTemplate({
memberHandle: member.name,
summary: emailSummary,
text: emailText,
cta: {
button: {
label: 'See on Pioneer',
href: `${PIONEER_URL}/#/forum/thread/${threadId}?post=${entityId}`,
},
Expand All @@ -65,7 +67,7 @@ export const fromPostAddedNotification: EmailFromNotificationFn = async ({ id, k

return {
subject: emailSubject,
html: renderedEmail,
html: emailHtml,
to: member.email,
}
}
Expand All @@ -82,21 +84,23 @@ export const fromThreadCreatedNotification: EmailFromNotificationFn = async ({ i
const { author, title } = await getForumThread(entityId)

const emailSubject = `[Pioneer forum] ${title}`

const emailSummary: string = match(kind)
.with('FORUM_THREAD_MENTION', () => `${author} mentioned you in a new thread ${title}.`)
.with('FORUM_CATEGORY_ENTITY_THREAD', 'FORUM_THREAD_ALL', () => `${author} posted a new thread ${title}.`)
.exhaustive()

const emailText: string = match(kind)
.with('FORUM_THREAD_MENTION', () => `${author} mentioned you in a new thread ${title}.`)
.with('FORUM_CATEGORY_ENTITY_THREAD', 'FORUM_THREAD_ALL', () => `${author} posted a new thread ${title}.`)
.exhaustive()

const renderedEmail = render(
PioneerEmail({
const emailHtml = render(
PioneerEmailTemplate({
memberHandle: member.name,
summary: emailSummary,
text: emailText,
cta: {
button: {
label: 'See on Pioneer',
href: `${PIONEER_URL}/#/forum/thread/${entityId}`,
},
Expand All @@ -105,7 +109,7 @@ export const fromThreadCreatedNotification: EmailFromNotificationFn = async ({ i

return {
subject: emailSubject,
html: renderedEmail,
html: emailHtml,
to: member.email,
}
}

0 comments on commit e8e103f

Please sign in to comment.