Move custom fields to global admin settings
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
a92771ffca
commit
ba5fc34d80
14 changed files with 719 additions and 567 deletions
|
|
@ -4,6 +4,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
|
||||
## Features
|
||||
- Edit the association/club name
|
||||
- Manage custom fields
|
||||
- Real-time form validation
|
||||
- Success/error feedback
|
||||
|
||||
|
|
@ -28,7 +29,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:page_title, gettext("Club Settings"))
|
||||
|> assign(:page_title, gettext("Settings"))
|
||||
|> assign(:settings, settings)
|
||||
|> assign_form()}
|
||||
end
|
||||
|
|
@ -38,12 +39,16 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
~H"""
|
||||
<Layouts.app flash={@flash} current_user={@current_user}>
|
||||
<.header>
|
||||
{gettext("Club Settings")}
|
||||
{gettext("Settings")}
|
||||
<:subtitle>
|
||||
{gettext("Manage global settings for the association.")}
|
||||
</:subtitle>
|
||||
</.header>
|
||||
|
||||
<%!-- Club Settings Section --%>
|
||||
<.header>
|
||||
{gettext("Club Settings")}
|
||||
</.header>
|
||||
<.form for={@form} id="settings-form" phx-change="validate" phx-submit="save">
|
||||
<.input
|
||||
field={@form[:club_name]}
|
||||
|
|
@ -56,6 +61,12 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
{gettext("Save Settings")}
|
||||
</.button>
|
||||
</.form>
|
||||
|
||||
<%!-- Custom Fields Section --%>
|
||||
<.live_component
|
||||
module={MvWeb.CustomFieldLive.IndexComponent}
|
||||
id="custom-fields-component"
|
||||
/>
|
||||
</Layouts.app>
|
||||
"""
|
||||
end
|
||||
|
|
@ -66,6 +77,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
assign(socket, form: AshPhoenix.Form.validate(socket.assigns.form, setting_params))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("save", %{"setting" => setting_params}, socket) do
|
||||
case AshPhoenix.Form.submit(socket.assigns.form, params: setting_params) do
|
||||
{:ok, updated_settings} ->
|
||||
|
|
@ -82,6 +94,37 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:custom_field_saved, _custom_field, action}, socket) do
|
||||
send_update(MvWeb.CustomFieldLive.IndexComponent,
|
||||
id: "custom-fields-component",
|
||||
show_form: false
|
||||
)
|
||||
|
||||
{:noreply,
|
||||
put_flash(socket, :info, gettext("Custom field %{action} successfully", action: action))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:custom_field_deleted, _custom_field}, socket) do
|
||||
{:noreply, put_flash(socket, :info, gettext("Custom field deleted successfully"))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:custom_field_delete_error, error}, socket) do
|
||||
{:noreply,
|
||||
put_flash(
|
||||
socket,
|
||||
:error,
|
||||
gettext("Failed to delete custom field: %{error}", error: inspect(error))
|
||||
)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info(:custom_field_slug_mismatch, socket) do
|
||||
{:noreply, put_flash(socket, :error, gettext("Slug does not match. Deletion cancelled."))}
|
||||
end
|
||||
|
||||
defp assign_form(%{assigns: %{settings: settings}} = socket) do
|
||||
form =
|
||||
AshPhoenix.Form.for_update(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue