'use client' import { useTranslation } from '@payloadcms/ui' import { useState } from 'react' import { ipalT } from '../../../modules/admin-i18n/t.js' /** * Admin UI: a small "send test e-mail" tool for the SiteIntegrations e-mail 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 without leaving the panel. * * Assigned via a `ui` field's admin.components.Field. Texts: `testEmail*` keys. */ export const TestEmailButton = () => { const { t } = useTranslation() const text = (key: Parameters[1], vars?: Record) => ipalT(t as never, key, vars) 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: text('testEmailInvalidRecipient') }) 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 ?? text('testEmailSent', { to: to.trim() }) }) } else { setStatus({ kind: 'error', msg: data.error ?? text('testEmailFailed') }) } } catch { setStatus({ kind: 'error', msg: text('testEmailNoConnection') }) } } return (

{text('testEmailHint')}

setTo(e.target.value)} placeholder="anna@example.com" style={{ flex: 1, minWidth: '220px' }} type="email" value={to} />
{status.kind === 'ok' && (

✓ {status.msg}

)} {status.kind === 'error' && (

✗ {status.msg}

)}
) } export default TestEmailButton