131 lines
4.3 KiB
JavaScript
131 lines
4.3 KiB
JavaScript
'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', {
|
|
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 /*#__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: {
|
|
fontSize: '.85rem',
|
|
marginTop: 0,
|
|
opacity: 0.7
|
|
},
|
|
children: "Sends through the transport selected above. Save your changes first."
|
|
}),
|
|
/*#__PURE__*/ _jsxs("div", {
|
|
style: {
|
|
alignItems: 'center',
|
|
display: 'flex',
|
|
flexWrap: 'wrap',
|
|
gap: '.5rem'
|
|
},
|
|
children: [
|
|
/*#__PURE__*/ _jsx("input", {
|
|
onChange: (e)=>setTo(e.target.value),
|
|
placeholder: "[email protected]",
|
|
style: {
|
|
flex: 1,
|
|
minWidth: '220px'
|
|
},
|
|
type: "email",
|
|
value: to
|
|
}),
|
|
/*#__PURE__*/ _jsx("button", {
|
|
className: "btn btn--style-secondary",
|
|
disabled: status.kind === 'sending',
|
|
onClick: send,
|
|
style: {
|
|
whiteSpace: 'nowrap'
|
|
},
|
|
type: "button",
|
|
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
|