'use client' import { useState } from 'react' /** * Admin UI: a small "send test email" tool for the SiteIntegrations email tab. * Enter an address, click Send, and it POSTs to /api/ipal/test-email, which * sends through the currently-selected transport (SMTP or Graph). Shows the * result inline so you can confirm delivery — or read the exact error — without * leaving the panel. * * Assigned via a `ui` field's admin.components.Field. */ export const TestEmailButton = () => { const [to, setTo] = useState('') const [status, setStatus] = useState< | { kind: 'error'; msg: string } | { kind: 'idle' } | { kind: 'ok'; msg: string } | { kind: 'sending' } >({ kind: 'idle' }) const send = async () => { if (!to.trim()) { setStatus({ kind: 'error', msg: 'Enter a recipient address.' }) return } setStatus({ kind: 'sending' }) try { const res = await fetch('/api/ipal/test-email', { body: JSON.stringify({ to: to.trim() }), credentials: 'include', headers: { 'Content-Type': 'application/json' }, method: 'POST', }) const data = await res.json() if (data.ok) { setStatus({ kind: 'ok', msg: data.message ?? 'Test email sent.' }) } else { setStatus({ kind: 'error', msg: data.error ?? 'Send failed.' }) } } catch { setStatus({ kind: 'error', msg: 'Request failed. Is the server running?' }) } } return (
Sends through the transport selected above. Save your changes first.
✓ {status.msg}
)} {status.kind === 'error' && (✗ {status.msg}
)}