add send test email button to campaign form
All checks were successful
deploy / deploy (push) Successful in 1m22s

Sends the campaign to the admin's own email address as a preview,
with [Test] prefix in subject line. Uses the same HTML template
and formatting as real sends. Does not affect campaign status or
sent counts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-28 23:52:11 +00:00
parent aa008f83b2
commit 7f6fd012a5
3 changed files with 67 additions and 0 deletions

View File

@@ -74,6 +74,29 @@ defmodule BerrypodWeb.Admin.Newsletter.CampaignForm do
end
end
def handle_event("send_test", _params, socket) do
params = current_form_params(socket)
to_email = socket.assigns.current_scope.user.email
if params["subject"] == "" || params["body"] == "" do
{:noreply, put_flash(socket, :error, "Fill in subject and body first")}
else
# Build a temporary campaign struct for the notifier
campaign = %Newsletter.Campaign{
subject: params["subject"],
body: params["body"]
}
case Newsletter.Notifier.deliver_test(campaign, to_email) do
{:ok, _} ->
{:noreply, put_flash(socket, :info, "Test email sent to #{to_email}")}
{:error, _} ->
{:noreply, put_flash(socket, :error, "Failed to send test email")}
end
end
end
def handle_event("schedule", _params, socket) do
params = current_form_params(socket)
scheduled_at = parse_schedule_time(params["scheduled_at"])
@@ -184,6 +207,14 @@ defmodule BerrypodWeb.Admin.Newsletter.CampaignForm do
Save draft
</.button>
<button
type="button"
phx-click="send_test"
class="admin-btn admin-btn-ghost"
>
<.icon name="hero-envelope" class="size-4" /> Send test
</button>
<button
type="button"
phx-click="send_now"