diff --git a/apps/frontend/src/components/EmailComms/EmailEditorOverviewPage.tsx b/apps/frontend/src/components/EmailComms/EmailEditorOverviewPage.tsx index df7a80e..54f2c98 100644 --- a/apps/frontend/src/components/EmailComms/EmailEditorOverviewPage.tsx +++ b/apps/frontend/src/components/EmailComms/EmailEditorOverviewPage.tsx @@ -25,6 +25,7 @@ export function EmailEditor() { try { const templates = await apiClient.getEmailTemplates(); if (templates && templates.length > 0) { + let loadedMeta = false; setEmails((prev) => { const next = { ...prev }; templates.forEach((t: any) => { @@ -34,11 +35,34 @@ export function EmailEditor() { else if (t.type === 'email_subscribers') tab = 'mass'; if (tab) { + const bodyMatch = t.bodyHtml.match( + /([\s\S]*?)/, + ); + const body = bodyMatch ? bodyMatch[1].trim() : t.bodyHtml; + next[tab] = { subject: t.subject, - body: t.bodyHtml, + body: body, }; } + + if (!loadedMeta) { + const metaMatch = t.bodyHtml.match(//); + if (metaMatch) { + try { + const meta = JSON.parse(metaMatch[1]); + if (meta.sig) setSig(meta.sig); + if (meta.ctaText) setCtaText(meta.ctaText); + if (meta.ctaLink) setCtaLink(meta.ctaLink); + loadedMeta = true; // Use the first found metadata + } catch (e) { + console.error( + 'Failed to parse metadata from email template', + e, + ); + } + } + } }); return next; }); @@ -60,13 +84,15 @@ export function EmailEditor() { const buildFullHTML = () => { const email = emails[activeTab]; - return ` - - ${email.body} - ${buildSignatureHTML(sig)} - ${ctaText ? `
${ctaText}
` : ''} - - `; + const metadata = { sig, ctaText, ctaLink }; + return ` + + + ${email.body} + + ${buildSignatureHTML(sig)} + ${ctaText ? `
${ctaText}
` : ''} +`; }; const handleSave = async () => { diff --git a/apps/frontend/src/components/EmailComms/SignatureEditorCard.tsx b/apps/frontend/src/components/EmailComms/SignatureEditorCard.tsx index 319a382..7e28a6a 100644 --- a/apps/frontend/src/components/EmailComms/SignatureEditorCard.tsx +++ b/apps/frontend/src/components/EmailComms/SignatureEditorCard.tsx @@ -25,11 +25,27 @@ export default function SignatureEditor({
{field('Full Name', 'name', 'Your name')} - {field('Position', 'position', 'Your title')} - - {field('Email', 'email', 'you@company.com')} + {field('Email', 'email', 'mallory@fenwaycommunitycenter.org')} + {field('Pronouns', 'pronouns', '(she/her)')} + {field('Website', 'website', 'https://fenwaycommunitycenter.org/')} + {field( + 'LinkedIn', + 'linkedin', + 'https://www.linkedin.com/company/fenwaycommunitycenter', + )} + {field('X (Twitter)', 'X', 'https://twitter.com/...')} + {field( + 'Facebook', + 'facebook', + 'https://www.facebook.com/fenwaycommunitycenter', + )}
+ {field( + 'Image Upload (CDN URL placeholder)', + 'imageUrl', + 'https://example.com/image.png', + )}
); } diff --git a/apps/frontend/src/components/EmailComms/types.ts b/apps/frontend/src/components/EmailComms/types.ts index 31c15df..b1c7c3c 100644 --- a/apps/frontend/src/components/EmailComms/types.ts +++ b/apps/frontend/src/components/EmailComms/types.ts @@ -11,6 +11,7 @@ export type Signature = { linkedin: string; X: string; facebook: string; + imageUrl: string; }; export type EmailData = { @@ -61,12 +62,13 @@ export const defaultEmails: EmailsState = { export const DEFAULT_SIGNATURE: Signature = { name: 'Mallory Rohig', position: 'Executive Director', - email: 'filler-email@gmail.com', + email: 'mallory@fenwaycommunitycenter.org', pronouns: '(she/her)', website: 'https://fenwaycommunitycenter.org/', - linkedin: 'https://www.linkedin.com/company/fenwaycommunitycenter/', - X: 'https://fenwaycommunitycenter.org/?share=x&nb=1', - facebook: 'https://fenwaycommunitycenter.org/?share=facebook&nb=1', + linkedin: 'https://www.linkedin.com/company/fenwaycommunitycenter', + X: '', + facebook: 'https://www.facebook.com/fenwaycommunitycenter', + imageUrl: '', }; export const TAB_CONFIG: { id: TabId; label: string }[] = [ @@ -94,12 +96,14 @@ export function buildSignatureHTML(sig: Signature): string { : '', ].join(''); + const imageSrc = sig.imageUrl ? sig.imageUrl : FCCEmailMallory; + return ` @@ -112,6 +116,13 @@ export function buildSignatureHTML(sig: Signature): string {
- ${sig.name} + ${ + sig.email + ? `

+ ${sig.email} +

` + : '' + } ${ sig.website ? `