"use client" import { useState, useEffect } from "react" import { useRouter } from "next/navigation" import { useUser } from "@/providers/user-provider" import { Mail, Clock } from "lucide-react" export default function EmailsPage() { const router = useRouter() const { user } = useUser() const [emails, setEmails] = useState([]) useEffect(() => { if (!user) { router.push("/login"); return } if (user.role !== "admin" && user.role !== "super_admin") { router.push("/dashboard"); return } fetch("/api/emails").then((r) => r.ok ? r.json() : { emails: [] }).then((d) => setEmails(d.emails || [])) }, [user, router]) if (!user || (user.role !== "admin" && user.role !== "super_admin")) return null return (

Email Log

Emails are stored locally. To actually deliver them, add EMAIL_API_KEY to your .env.

{emails.length === 0 ? (

No emails sent yet.

) : (
{emails.map((e: any) => { const withMatch = e.bodyText?.match(/With:\s*(.+)/) const withName = withMatch ? withMatch[1].trim() : null return (

{e.subject}

To: {e.recipient}

{withName &&

With: {withName}

}
{new Date(e.createdAt).toLocaleString()}
) })}
)}
) }