Admin Dashboard
Choose who should receive this newsletter.
`); } catch (err) { toast('Failed to load send options', 'error'); } } async function executeSend(e, id) { e.preventDefault(); const form = e.target; const sendTo = form.sendTo.value; let tags = null; if (sendTo === 'tags') { tags = Array.from(form.querySelectorAll('input[name="selectedTags"]:checked')).map(cb => cb.value); if (tags.length === 0) { toast('Select at least one tag', 'error'); return; } } closeModal(); toast('Sending emails...', 'info'); try { const res = await fetch(`/api/newsletters/${id}/send`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tags }) }); const data = await res.json(); if (!res.ok) { throw new Error(data.error); } toast(`Sent to ${data.sent} subscribers!`, 'success'); if (data.failed > 0) { console.warn('Failed sends:', data.errors); } } catch (err) { toast(err.message || 'Failed to send', 'error'); } }