The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
render email template
Kiran K40b95a194bc8
diff --git a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts b/apps/web/lib/actions/campaigns/send-campaign-preview-email.tsindex f232d404f1..7bfca98af9 100644--- a/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts+++ b/apps/web/lib/actions/campaigns/send-campaign-preview-email.ts@@ -39,7 +39,7 @@ export const sendCampaignPreviewEmail = authActionClient},});- const response = await sendBatchEmail(+ await sendBatchEmail(emailAddresses.map((email) => ({variant: "notifications",to: email,@@ -52,6 +52,4 @@ export const sendCampaignPreviewEmail = authActionClient}),})),);-- console.log(response);});diff --git a/packages/email/src/templates/campaign-email.tsx b/packages/email/src/templates/campaign-email.tsxindex f0baa225d6..e8a3907dd7 100644--- a/packages/email/src/templates/campaign-email.tsx+++ b/packages/email/src/templates/campaign-email.tsx@@ -9,6 +9,8 @@ import {Section,Tailwind,} from "@react-email/components";+import StarterKit from "@tiptap/starter-kit";+import { renderToReactElement } from "@tiptap/static-renderer";export default function CampaignEmail({campaign = {@@ -21,9 +23,150 @@ export default function CampaignEmail({}: {campaign?: {subject: string;- bodyJson: Record<string, any>;+ bodyJson: any;};}) {+ const bodyHtml = renderToReactElement({+ extensions: [+ StarterKit.configure({+ heading: {+ levels: [1, 2],+ },+ }),+ ],+ options: {+ nodeMapping: {+ heading: ({ node, children }) => {+ // Extract level value safely for server component+ const nodeAttrs = node.attrs || {};+ const level = nodeAttrs.level || 1;++ // Only support H1 and H2 as per toolbar+ if (level === 1) {+ return (+ <h1+ style={{+ fontSize: "24px",+ fontWeight: "bold",+ margin: "16px 0 8px 0",+ color: "#374151",+ lineHeight: "1.2",+ }}+ >+ {children}+ </h1>+ );+ } else if (level === 2) {+ return (+ <h2+ style={{+ fontSize: "20px",+ fontWeight: "bold",+ margin: "16px 0 8px 0",+ color: "#374151",+ lineHeight: "1.2",+ }}+ >+ {children}+ </h2>+ );+ }+ // Fallback for any other heading levels (render as paragraph)+ return (+ <p+ style={{+ fontSize: "16px",+ fontWeight: "bold",+ margin: "16px 0 8px 0",+ color: "#374151",+ lineHeight: "1.5",+ }}+ >+ {children}+ </p>+ );+ },+ paragraph: ({ children }) => (+ <p+ style={{+ margin: "0 0 16px 0",+ lineHeight: "1.5",+ color: "#4B5563",+ }}+ >+ {children}+ </p>+ ),+ hardBreak: () => <br />,+ image: ({ node }) => {+ const nodeAttrs = node.attrs || {};+ return (+ <img+ src={nodeAttrs.src}+ alt={nodeAttrs.alt || ""}+ style={{+ maxWidth: "100%",+ height: "auto",+ display: "block",+ margin: "16px 0",+ borderRadius: "8px",+ }}+ />+ );+ },+ mention: ({ node }) => {+ const nodeAttrs = node.attrs || {};+ return (+ <span+ style={{+ padding: "2px 4px",+ backgroundColor: "#DBEAFE",+ color: "#1D4ED8",+ borderRadius: "4px",+ fontWeight: "600",+ fontSize: "14px",+ }}+ >+ {`{{${nodeAttrs.id}}}`}+ </span>+ );+ },+ },+ markMapping: {+ bold: ({ children }) => (+ <strong style={{ fontWeight: "bold" }}>{children}</strong>+ ),+ italic: ({ children }) => (+ <em style={{ fontStyle: "italic" }}>{children}</em>+ ),+ link: ({ node, children }) => {+ const nodeAttrs = node.attrs || {};+ return (+ <a+ href={nodeAttrs.href}+ style={{+ color: "#3B82F6",+ textDecoration: "underline",+ textUnderlineOffset: "2px",+ }}+ >+ {children}+ </a>+ );+ },+ },+ unhandledNode: ({ node }) => {+ console.warn(`Unhandled node: ${node.type.name}`);+ return null;+ },+ unhandledMark: ({ mark }) => {+ console.warn(`Unhandled mark: ${mark.type.name}`);+ return null;+ },+ },+ content: campaign.bodyJson,+ });+return (<Html><Head />@@ -35,10 +178,7 @@ export default function CampaignEmail({<Img src={DUB_WORDMARK} height="32" alt="Dub" /></Section>- <Section className="my-6">- {/* TODO: Render email body */}- <div dangerouslySetInnerHTML={{ __html: "WIP" }} />- </Section>+ <Section className="my-6">{bodyHtml}</Section></Container></Body></Tailwind>