fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
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
|
2026-03-04 23:10:37 +00:00
|
|
|
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) ->
|
|
|
|
|
conn
|
2026-03-05 15:29:05 +00:00
|
|
|
|> put_flash(:field_errors, field_errors)
|
|
|
|
|
|> put_flash(:error_adapter, adapter_key)
|
2026-03-04 23:10:37 +00:00
|
|
|
|> redirect(to: ~p"/admin/settings/email")
|
fix email settings: missing providers, a11y, no-JS support
show all 10 providers in three groups (popular, transactional,
advanced) with category headings. fix phx-change clobbering text
fields, async test email sending state, integer parse crash on
bad port. add keyboard focus on card radios, fieldset legend,
WCAG-compliant badge contrast, responsive grid. extract shared
save_config into Mailer, add no-JS controller fallback with
configured_adapter hidden field for adapter change detection.
remove CardRadioScroll JS hook (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 21:26:59 +00:00
|
|
|
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
|