'use client'; import { useState, useEffect } from 'react'; import { theme } from '../emails/theme'; const templates = [ { id: 'welcome', name: 'Welcome Email', }, { id: 'transaction-complete', name: 'Transaction Complete', }, { id: 'event-ticket', name: 'Event Ticket', }, { id: 'payment-request', name: 'Payment Request', }, { id: 'referral-success', name: 'Referral Success', }, ]; export default function Home() { const [selectedTemplate, setSelectedTemplate] = useState(templates[0]); const [htmlContent, setHtmlContent] = useState(''); const [loading, setLoading] = useState(true); const loadTemplate = async (templateId: string) => { setLoading(true); try { const response = await fetch(`/api/email/${templateId}`); const html = await response.text(); setHtmlContent(html); } catch (error) { console.error('Error loading template:', error); } finally { setLoading(false); } }; const handleTemplateChange = (template: typeof templates[0]) => { setSelectedTemplate(template); loadTemplate(template.id); }; const handleDownload = () => { const blob = new Blob([htmlContent], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${selectedTemplate.id}.html`; a.click(); URL.revokeObjectURL(url); }; // Load initial template useEffect(() => { loadTemplate(selectedTemplate.id); }, []); return (

Amba Email Templates

Preview and test all email templates

{selectedTemplate.name}

{loading ? (

Loading template...

) : (