'use client'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; 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: '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', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ to: to.trim() }) }); 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 /*#__PURE__*/ _jsxs("div", { className: "field-type", style: { marginTop: '1rem' }, children: [ /*#__PURE__*/ _jsx("label", { className: "field-label", children: "Send a test email" }), /*#__PURE__*/ _jsx("p", { style: { opacity: 0.7, fontSize: '.85rem', marginTop: 0 }, children: "Sends through the transport selected above. Save your changes first." }), /*#__PURE__*/ _jsxs("div", { style: { display: 'flex', gap: '.5rem', alignItems: 'center', flexWrap: 'wrap' }, children: [ /*#__PURE__*/ _jsx("input", { type: "email", placeholder: "you@example.com", value: to, onChange: (e)=>setTo(e.target.value), style: { flex: 1, minWidth: '220px' } }), /*#__PURE__*/ _jsx("button", { type: "button", onClick: send, disabled: status.kind === 'sending', className: "btn btn--style-secondary", style: { whiteSpace: 'nowrap' }, children: status.kind === 'sending' ? 'Sending…' : 'Send test' }) ] }), status.kind === 'ok' && /*#__PURE__*/ _jsxs("p", { style: { color: 'var(--theme-success-500, green)', marginTop: '.5rem' }, children: [ "✓ ", status.msg ] }), status.kind === 'error' && /*#__PURE__*/ _jsxs("p", { style: { color: 'var(--theme-error-500, crimson)', marginTop: '.5rem' }, children: [ "✗ ", status.msg ] }) ] }); }; export default TestEmailButton; //# sourceMappingURL=TestEmailButton.js.map