rework email settings for true progressive enhancement
All checks were successful
deploy / deploy (push) Successful in 1m19s
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>
This commit is contained in:
@@ -10,27 +10,22 @@ defmodule BerrypodWeb.EmailSettingsController do
|
||||
alias Berrypod.Mailer
|
||||
|
||||
def update(conn, %{"email" => params}) do
|
||||
selected = params["adapter"]
|
||||
configured = params["configured_adapter"]
|
||||
adapter_key = params["adapter"]
|
||||
# Fields are namespaced: email[brevo][api_key] → params["brevo"]["api_key"]
|
||||
adapter_params = params[adapter_key] || %{}
|
||||
|
||||
if selected != configured do
|
||||
# User changed adapter radio but config fields are for the old adapter.
|
||||
# Redirect to show the new adapter's config fields.
|
||||
redirect(conn, to: ~p"/admin/settings/email?adapter=#{selected}")
|
||||
else
|
||||
case Mailer.save_config(selected, 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")
|
||||
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(". ")
|
||||
{: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?adapter=#{selected}")
|
||||
end
|
||||
conn
|
||||
|> put_flash(:error, message)
|
||||
|> redirect(to: ~p"/admin/settings/email")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user