'use client'; import { useEffect, useMemo, useState } from 'react'; import { templateCatalog, type TemplateCategory } from '../emails/registry'; import { theme } from '../emails/theme'; import type { Locale } from '../emails/i18n/types'; import type { ShopSummaryPeriod } from '../emails/shop-summary'; const periods: ShopSummaryPeriod[] = [ 'daily', 'weekly', 'monthly', 'quarterly', 'yearly', ]; export default function Home() { const [selectedId, setSelectedId] = useState(templateCatalog[0].id); const [locale, setLocale] = useState('en'); const [period, setPeriod] = useState('weekly'); const [htmlContent, setHtmlContent] = useState(''); const [loading, setLoading] = useState(true); const selected = useMemo( () => templateCatalog.find((t) => t.id === selectedId) || templateCatalog[0], [selectedId] ); const grouped = useMemo(() => { return templateCatalog.reduce>( (acc, item) => { if (!acc[item.category]) acc[item.category] = []; acc[item.category].push(item); return acc; }, {} as Record ); }, []); const loadTemplate = async (id: string, nextLocale: Locale, nextPeriod: ShopSummaryPeriod) => { setLoading(true); try { const params = new URLSearchParams({ locale: nextLocale }); if (id === 'shop-summary') params.set('period', nextPeriod); const response = await fetch(`/api/email/${id}?${params.toString()}`); const html = await response.text(); setHtmlContent(html); } catch (error) { console.error(error); setHtmlContent('

Failed to render template.

'); } finally { setLoading(false); } }; useEffect(() => { loadTemplate(selectedId, locale, period); }, [selectedId, locale, period]); 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 = `${selectedId}-${locale}.html`; a.click(); URL.revokeObjectURL(url); }; return (

Gishen Pharmacy

Email Templates

Shared previews for Ecom, Admin, and B2B · brand colors & logo from Gishen apps

{selectedId === 'shop-summary' && ( )}
{selected.name} /api/email/{selected.id}?locale={locale} {selectedId === 'shop-summary' ? `&period=${period}` : ''}
{loading ? (
Rendering…
) : (