"use client"; import { useState } from "react"; import { EMAIL_TEMPLATES, EmailTemplate } from "@/lib/types/smtp"; export default function EmailsPage() { const [selectedTemplate, setSelectedTemplate] = useState('welcome'); const [testEmail, setTestEmail] = useState(''); const [sending, setSending] = useState(false); const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null); const [showSendModal, setShowSendModal] = useState(false); const handleSendTest = async () => { if (!testEmail) { alert('Please enter a test email address'); return; } setSending(true); setMessage(null); try { const response = await fetch('/api/admin/emails/send-test', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ template: selectedTemplate, email: testEmail, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Failed to send'); } setMessage({ type: 'success', text: data.message }); setShowSendModal(false); setTestEmail(''); } catch (error: any) { setMessage({ type: 'error', text: error.message || 'Failed to send test email' }); } finally { setSending(false); } }; const previewUrl = `/api/admin/emails/preview?template=${selectedTemplate}`; return (
{/* Hero Section with Gradient */}

Email Templates

Verwalte und teste E-Mail-Vorlagen

{/* Status Message */} {message && (
{message.type === 'success' ? '✓' : '⚠️'} {message.text}
)}
{/* Template List */}
📧

Templates

{EMAIL_TEMPLATES.map((template) => ( ))}
{/* Send Test Button */}
{/* Preview */}
👁️

Preview

{EMAIL_TEMPLATES.find(t => t.name === selectedTemplate)?.subject}