The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update email templates with program details and messaging capabilities.
Kiran K3b1a6539099f
diff --git a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts b/apps/web/lib/actions/campaigns/send-campaign-preview-email.tsindex 9c9bb93798..cbbffc9838 100644--- a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts+++ b/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts@@ -2,6 +2,7 @@import { getCampaignOrThrow } from "@/lib/api/campaigns/get-campaign-or-throw";import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";+import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";import { generateCampaignEmailHTML } from "@/lib/api/workflows/generate-campaign-email-html";import { CampaignSchema } from "@/lib/zod/schemas/campaigns";import { sendBatchEmail } from "@dub/email";@@ -33,10 +34,17 @@ export const sendCampaignPreviewEmail = authActionClientconst programId = getDefaultProgramIdOrThrow(workspace);- await getCampaignOrThrow({- programId,- campaignId,- });+ const [program, campaign] = await Promise.all([+ getProgramOrThrow({+ programId,+ workspaceId: workspace.id,+ }),++ getCampaignOrThrow({+ programId,+ campaignId,+ }),+ ]);await sendBatchEmail(emailAddresses.map((email) => ({@@ -44,7 +52,14 @@ export const sendCampaignPreviewEmail = authActionClientto: email,subject: `[TEST] ${subject}`,react: CampaignEmail({+ program: {+ name: program.name,+ slug: program.slug,+ logo: program.logo,+ messagingEnabledAt: program.messagingEnabledAt,+ },campaign: {+ type: campaign.type,subject,body: generateCampaignEmailHTML({bodyJson,diff --git a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts b/apps/web/lib/api/workflows/execute-send-campaign-workflow.tsindex e8a4aa4873..bf90fd3485 100644--- a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts+++ b/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts@@ -118,7 +118,6 @@ export const executeSendCampaignWorkflow = async ({const programEnrollmentsChunks = chunk(programEnrollments, 100);for (const programEnrollmentChunk of programEnrollmentsChunks) {- // Get partner users to notifyconst partnerUsers = programEnrollmentChunk.flatMap((enrollment) =>enrollment.partner.users.filter(({ user }) => user.email) // only include users with an email@@ -158,6 +157,8 @@ export const executeSendCampaignWorkflow = async ({`Workflow ${workflow.id} created ${messages.count} messages for campaign ${campaignId}.`,);+ const { program } = campaign;+// Send emailsconst { data } = await sendBatchEmail(partnerUsers.map((partnerUser) => ({@@ -165,7 +166,14 @@ export const executeSendCampaignWorkflow = async ({to: partnerUser.email!,subject: campaign.subject,react: CampaignEmail({+ program: {+ name: program.name,+ slug: program.slug,+ logo: program.logo,+ messagingEnabledAt: program.messagingEnabledAt,+ },campaign: {+ type: campaign.type,subject: campaign.subject,body: generateCampaignEmailHTML({bodyJson: campaign.bodyJson as any,diff --git a/packages/email/src/react-email.d.ts b/packages/email/src/react-email.d.tsnew file mode 100644index 0000000000..34d6196cf8--- /dev/null+++ b/packages/email/src/react-email.d.ts@@ -0,0 +1,19 @@+declare module "@react-email/components" {+ import * as React from "react";++ export const Html: React.FC<React.HtmlHTMLAttributes<HTMLHtmlElement>>;+ export const Head: React.FC<React.HTMLAttributes<HTMLHeadElement>>;+ export const Body: React.FC<React.HTMLAttributes<HTMLBodyElement>>;+ export const Container: React.FC<React.TableHTMLAttributes<HTMLTableElement>>;+ export const Section: React.FC<React.TableHTMLAttributes<HTMLTableElement>>;+ export const Row: React.FC<React.HTMLAttributes<HTMLTableRowElement>>;+ export const Column: React.FC<+ React.TdHTMLAttributes<HTMLTableDataCellElement>+ >;+ export const Img: React.FC<React.ImgHTMLAttributes<HTMLImageElement>>;+ export const Link: React.FC<React.AnchorHTMLAttributes<HTMLAnchorElement>>;+ export const Text: React.FC<React.HTMLAttributes<HTMLParagraphElement>>;+ export const Heading: React.FC<React.HTMLAttributes<HTMLHeadingElement>>;+ export const Preview: React.FC<{ children: React.ReactNode }>;+ export const Tailwind: React.FC<{ children: React.ReactNode }>;+}diff --git a/packages/email/src/templates/campaign-email.tsx b/packages/email/src/templates/campaign-email.tsxindex d07bf48b0e..a3a00856c7 100644--- a/packages/email/src/templates/campaign-email.tsx+++ b/packages/email/src/templates/campaign-email.tsx@@ -3,20 +3,36 @@ import {Body,Container,Head,+ Heading,Html,Img,+ Link,Preview,Section,Tailwind,} from "@react-email/components";export default function CampaignEmail({+ program = {+ name: "Acme",+ slug: "acme",+ logo: "https://assets.dub.co/misc/acme-logo.png",+ messagingEnabledAt: new Date(),+ },campaign = {+ type: "transactional",subject: "Test Subject",body: `<p xmlns="http://www.w3.org/1999/xhtml">Hi <span class="px-1 py-0.5 bg-blue-100 text-blue-700 rounded font-semibold" data-type="mention" data-id="PartnerName">{{PartnerName}}</span>,</p><p xmlns="http://www.w3.org/1999/xhtml">Thrilled to have you officially join the Acme Ambassador Program!</p><p xmlns="http://www.w3.org/1999/xhtml">As a Acme Ambassador, you're joining the front line of change. You're freeing people from broken healthcare and giving them back control of their health.</p><p xmlns="http://www.w3.org/1999/xhtml">Your 3 quick steps to get started:</p><ol xmlns="http://www.w3.org/1999/xhtml"><li><p>Activate your membership with your 50% off code: <strong>ACME50OFF</strong></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow" href="https://partners.dub.co/programs/acme">Open your dashboard</a> and copy your referral link</p></li><li><p>Share Acme with your loved ones! Use our <a target="_blank" rel="noopener noreferrer nofollow" href="http://acme.dub.sh">Ambassador Hub</a> for all the information you need like message templates, images, and information about Acme.</p></li></ol><p xmlns="http://www.w3.org/1999/xhtml">And a bonus: make your first referral within 7 days and you'll also receive a limited-edition Acme hoodie.</p><img xmlns="http://www.w3.org/1999/xhtml" src="https://dubassets.com/programs/prog_CYCu7IMAapjkRpTnr8F1azjN/lander/image_JjbkiaM" /><p xmlns="http://www.w3.org/1999/xhtml">We're here with you every step of the way.</p><p xmlns="http://www.w3.org/1999/xhtml">To your health,</p><p xmlns="http://www.w3.org/1999/xhtml">The Acme team</p>`,},}: {+ program?: {+ name: string;+ slug: string;+ logo: string | null;+ messagingEnabledAt: Date | null | undefined;+ };campaign?: {+ type: "transactional" | "marketing";subject: string;body: string;};@@ -46,12 +62,47 @@ export default function CampaignEmail({<Img src={DUB_WORDMARK} height="32" alt="Dub" /></Section>- <Section className="my-6">+ <Section className="my-8">+ <div className="flex items-center">+ <Img+ src={program.logo || "https://assets.dub.co/logo.png"}+ width="32"+ height="32"+ alt={program.name}+ className="rounded-full"+ />+ <Section className="ml-4">+ <Heading className="my-0 text-lg font-semibold text-black">+ {program.name}+ </Heading>+ <Link+ className="text-[13px] font-medium text-neutral-500 underline"+ href={`https://partners.dub.co/programs/${program.slug}`}+ >+ View program in Dub+ </Link>+ </Section>+ </div>+ </Section>++ <Section><divid="campaign-email-body"dangerouslySetInnerHTML={{ __html: styledHtml }}/></Section>++ {program?.messagingEnabledAt &&+ campaign.type === "transactional" && (+ <Section className="mt-3">+ <Link+ className="block rounded-lg bg-neutral-900 px-6 py-3 text-center text-[13px] font-medium text-white no-underline"+ href={`https://partners.dub.co/messages/${program.slug}`}+ >+ Reply in Dub+ </Link>+ </Section>+ )}</Container></Body></Tailwind>diff --git a/packages/email/tsconfig.json b/packages/email/tsconfig.jsonindex 8179b775d3..13d68f9337 100644--- a/packages/email/tsconfig.json+++ b/packages/email/tsconfig.json@@ -3,6 +3,7 @@"include": ["src/**/*"],+ "typeRoots": ["node_modules/@types", "src"],"exclude": ["node_modules"],@@ -12,6 +13,7 @@"moduleResolution": "NodeNext","jsx": "react-jsx","jsxImportSource": "react",- "strict": true+ "strict": true,+ "skipLibCheck": true}}\ No newline at end of file