The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix CampaignEmail
Steven Tey3b69ce370c85
diff --git a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts b/apps/web/lib/actions/campaigns/send-campaign-preview-email.tsindex c69088939e..9c9bb93798 100644--- a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts+++ b/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts@@ -38,14 +38,6 @@ export const sendCampaignPreviewEmail = authActionClientcampaignId,});- const bodyHtml = generateCampaignEmailHTML({- bodyJson,- variables: {- PartnerName: "Partner",- PartnerEmail: "[email protected]",- },- });-await sendBatchEmail(emailAddresses.map((email) => ({variant: "notifications",@@ -54,7 +46,13 @@ export const sendCampaignPreviewEmail = authActionClientreact: CampaignEmail({campaign: {subject,- body: bodyHtml,+ body: generateCampaignEmailHTML({+ bodyJson,+ variables: {+ PartnerName: "Partner",+ PartnerEmail: "[email protected]",+ },+ }),},}),})),diff --git a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts b/apps/web/lib/api/workflows/execute-send-campaign-workflow.tsindex 69a2933e73..e8a4aa4873 100644--- a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts+++ b/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts@@ -1,7 +1,7 @@import { WorkflowCondition, WorkflowContext } from "@/lib/types";import { WORKFLOW_ACTION_TYPES } from "@/lib/zod/schemas/workflows";import { sendBatchEmail } from "@dub/email";-import NewMessageFromProgram from "@dub/email/templates/new-message-from-program";+import CampaignEmail from "@dub/email/templates/campaign-email";import { prisma } from "@dub/prisma";import { chunk } from "@dub/utils";import { NotificationEmailType, Workflow } from "@prisma/client";@@ -164,29 +164,17 @@ export const executeSendCampaignWorkflow = async ({variant: "notifications",to: partnerUser.email!,subject: campaign.subject,- react: NewMessageFromProgram({- program: {- name: campaign.program.name,- logo: campaign.program.logo,- slug: campaign.program.slug,- },- messages: [- {- text: generateCampaignEmailHTML({- bodyJson: campaign.bodyJson as any,- variables: {- PartnerName: partnerUser.partner.name,- PartnerEmail: partnerUser.partner.email,- },- }),- createdAt: new Date(),- user: {- name: campaign.program.name,- image: campaign.program.logo,+ react: CampaignEmail({+ campaign: {+ subject: campaign.subject,+ body: generateCampaignEmailHTML({+ bodyJson: campaign.bodyJson as any,+ variables: {+ PartnerName: partnerUser.partner.name,+ PartnerEmail: partnerUser.partner.email,},- },- ],- email: partnerUser.email!,+ }),+ },}),tags: [{ name: "type", value: "notification-email" }],headers: {diff --git a/packages/email/src/templates/campaign-email.tsx b/packages/email/src/templates/campaign-email.tsxindex d468d42502..d07bf48b0e 100644--- a/packages/email/src/templates/campaign-email.tsx+++ b/packages/email/src/templates/campaign-email.tsx@@ -13,7 +13,7 @@ import {export default function CampaignEmail({campaign = {subject: "Test Subject",- body: "",+ 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>`,},}: {campaign?: {@@ -21,6 +21,20 @@ export default function CampaignEmail({body: string;};}) {+ // Wrap the HTML with styles to prevent overflow from large images+ const styledHtml = `+ <div style="max-width: 100%; overflow: hidden;">+ <style>+ #campaign-email-body img {+ max-width: 100% !important;+ height: auto !important;+ margin: 12px auto !important;+ }+ </style>+ ${campaign.body}+ </div>+ `;+return (<Html><Head />@@ -33,7 +47,10 @@ export default function CampaignEmail({</Section><Section className="my-6">- <div dangerouslySetInnerHTML={{ __html: campaign.body }} />+ <div+ id="campaign-email-body"+ dangerouslySetInnerHTML={{ __html: styledHtml }}+ /></Section></Container></Body>