'use client'; import { useState, useEffect } from 'react'; import { useSearchParams } from 'next/navigation'; import Link from 'next/link'; interface Email { key: string; subject: string; date: string; processed: string; processedAt: string | null; processedBy: string | null; queuedTo: string | null; status: string | null; } export default function Emails() { const searchParams = useSearchParams(); const bucket = searchParams.get('bucket'); const mailbox = searchParams.get('mailbox'); const [emails, setEmails] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (!bucket || !mailbox) { setError('Missing parameters'); setLoading(false); return; } const auth = localStorage.getItem('auth'); if (!auth) { setError('Not authenticated'); setLoading(false); return; } fetch(`/api/emails?bucket=${bucket}&mailbox=${encodeURIComponent(mailbox)}`, { headers: { Authorization: `Basic ${auth}` } }) .then(res => { if (!res.ok) throw new Error('Failed to fetch emails'); return res.json(); }) .then(data => { const sorted = data.sort((a: Email, b: Email) => new Date(b.date).getTime() - new Date(a.date).getTime()); setEmails(sorted); }) .catch(err => setError(err.message)) .finally(() => setLoading(false)); }, [bucket, mailbox]); if (loading) return
Loading...
; if (error) return
{error}
; const formatDate = (dateStr: string | null) => { if (!dateStr) return 'N/A'; const date = new Date(dateStr); return date.toLocaleString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false }); }; return (

Emails for {mailbox} in {bucket}

{emails.length === 0 ? ( ) : emails.map((e: Email) => ( ))}
Subject Date Processed Processed At Processed By Queued To Status Actions
No emails found
{e.subject} {formatDate(e.date)} {e.processed === 'true' ? 'Yes' : 'No'} {formatDate(e.processedAt)} {e.processedBy || '-'} {e.queuedTo || '-'} {e.status ? ( {e.status} ) : '-'} View
); }