All checks were successful
deploy / deploy (push) Successful in 1m19s
Render all adapter field sections in the form with CSS :has(:checked) controlling visibility. Selecting a provider instantly shows its config fields — no JS, no page reload, no server round-trip needed. - Render all 6 adapter configs with data-adapter attribute - CSS :has(:checked) show/hide rules per adapter in admin stylesheet - Namespace field names per adapter (email[brevo][api_key] etc) - Drop 4 transactional-only providers (Resend, Postmark, Mailgun, MailPace) - Remove noscript "Switch provider" button and controller redirect workaround - Remove configured_adapter hidden input tracking - Hide JS-only test email button for no-JS users via noscript style - LiveView progressively enhances with async save and test email Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.5 KiB
Elixir
50 lines
1.5 KiB
Elixir
defmodule BerrypodWeb.EmailSettingsController do
|
|
@moduledoc """
|
|
No-JS fallback for email settings form submission.
|
|
|
|
With JS enabled, the LiveView handles everything. Without JS,
|
|
the form POSTs here and we redirect back to the LiveView page.
|
|
"""
|
|
use BerrypodWeb, :controller
|
|
|
|
alias Berrypod.Mailer
|
|
|
|
def update(conn, %{"email" => params}) do
|
|
adapter_key = params["adapter"]
|
|
# Fields are namespaced: email[brevo][api_key] → params["brevo"]["api_key"]
|
|
adapter_params = params[adapter_key] || %{}
|
|
|
|
case Mailer.save_config(adapter_key, adapter_params, conn.assigns.current_scope.user.email) do
|
|
{:ok, _adapter_info} ->
|
|
conn
|
|
|> put_flash(:info, "Settings saved — send a test email to check it works")
|
|
|> redirect(to: ~p"/admin/settings/email")
|
|
|
|
{:error, field_errors} when is_map(field_errors) ->
|
|
message = field_errors |> Map.values() |> Enum.join(". ")
|
|
|
|
conn
|
|
|> put_flash(:error, message)
|
|
|> redirect(to: ~p"/admin/settings/email")
|
|
end
|
|
end
|
|
|
|
def test(conn, _params) do
|
|
user = conn.assigns.current_scope.user
|
|
|
|
case Mailer.send_test_email(user.email, Mailer.from_address()) do
|
|
{:ok, _} ->
|
|
Mailer.mark_email_verified()
|
|
|
|
conn
|
|
|> put_flash(:info, "Test email sent to #{user.email}")
|
|
|> redirect(to: ~p"/admin/settings/email")
|
|
|
|
{:error, reason} ->
|
|
conn
|
|
|> put_flash(:error, Mailer.friendly_error(reason))
|
|
|> redirect(to: ~p"/admin/settings/email")
|
|
end
|
|
end
|
|
end
|