feat: show only edit or list view in settings
This commit is contained in:
parent
38d106a69e
commit
4a6e7cf51a
2 changed files with 32 additions and 1 deletions
|
|
@ -178,6 +178,9 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def update(assigns, socket) do
|
def update(assigns, socket) do
|
||||||
|
# Track previous show_form state to detect when form is closed
|
||||||
|
previous_show_form = Map.get(socket.assigns, :show_form, false)
|
||||||
|
|
||||||
# If show_form is explicitly provided in assigns, reset editing state
|
# If show_form is explicitly provided in assigns, reset editing state
|
||||||
socket =
|
socket =
|
||||||
if Map.has_key?(assigns, :show_form) and assigns.show_form == false do
|
if Map.has_key?(assigns, :show_form) and assigns.show_form == false do
|
||||||
|
|
@ -188,6 +191,13 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
|
||||||
socket
|
socket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Detect when form is closed (show_form changes from true to false)
|
||||||
|
new_show_form = Map.get(assigns, :show_form, false)
|
||||||
|
|
||||||
|
if previous_show_form and not new_show_form do
|
||||||
|
send(self(), {:editing_section_changed, nil})
|
||||||
|
end
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
socket
|
socket
|
||||||
|> assign(assigns)
|
|> assign(assigns)
|
||||||
|
|
@ -202,6 +212,11 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("new_custom_field", _params, socket) do
|
def handle_event("new_custom_field", _params, socket) do
|
||||||
|
# Only send event if form was not already open
|
||||||
|
if not socket.assigns[:show_form] do
|
||||||
|
send(self(), {:editing_section_changed, :custom_fields})
|
||||||
|
end
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:show_form, true)
|
|> assign(:show_form, true)
|
||||||
|
|
@ -213,6 +228,11 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
|
||||||
def handle_event("edit_custom_field", %{"id" => id}, socket) do
|
def handle_event("edit_custom_field", %{"id" => id}, socket) do
|
||||||
custom_field = Ash.get!(Mv.Membership.CustomField, id)
|
custom_field = Ash.get!(Mv.Membership.CustomField, id)
|
||||||
|
|
||||||
|
# Only send event if form was not already open
|
||||||
|
if not socket.assigns[:show_form] do
|
||||||
|
send(self(), {:editing_section_changed, :custom_fields})
|
||||||
|
end
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:show_form, true)
|
|> assign(:show_form, true)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
||||||
socket
|
socket
|
||||||
|> assign(:page_title, gettext("Settings"))
|
|> assign(:page_title, gettext("Settings"))
|
||||||
|> assign(:settings, settings)
|
|> assign(:settings, settings)
|
||||||
|
|> assign(:active_editing_section, nil)
|
||||||
|> assign_form()}
|
|> assign_form()}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,12 +66,14 @@ defmodule MvWeb.GlobalSettingsLive do
|
||||||
<%!-- Memberdata Section --%>
|
<%!-- Memberdata Section --%>
|
||||||
<.form_section title={gettext("Memberdata")}>
|
<.form_section title={gettext("Memberdata")}>
|
||||||
<.live_component
|
<.live_component
|
||||||
|
:if={@active_editing_section != :custom_fields}
|
||||||
module={MvWeb.MemberFieldLive.IndexComponent}
|
module={MvWeb.MemberFieldLive.IndexComponent}
|
||||||
id="member-fields-component"
|
id="member-fields-component"
|
||||||
settings={@settings}
|
settings={@settings}
|
||||||
/>
|
/>
|
||||||
<%!-- Custom Fields Section --%>
|
<%!-- Custom Fields Section --%>
|
||||||
<.live_component
|
<.live_component
|
||||||
|
:if={@active_editing_section != :member_fields}
|
||||||
module={MvWeb.CustomFieldLive.IndexComponent}
|
module={MvWeb.CustomFieldLive.IndexComponent}
|
||||||
id="custom-fields-component"
|
id="custom-fields-component"
|
||||||
/>
|
/>
|
||||||
|
|
@ -113,7 +116,9 @@ defmodule MvWeb.GlobalSettingsLive do
|
||||||
)
|
)
|
||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
put_flash(socket, :info, gettext("Custom field %{action} successfully", action: action))}
|
socket
|
||||||
|
|> assign(:active_editing_section, nil)
|
||||||
|
|> put_flash(:info, gettext("Custom field %{action} successfully", action: action))}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
@ -163,6 +168,11 @@ defmodule MvWeb.GlobalSettingsLive do
|
||||||
{:noreply, put_flash(socket, :error, error_message)}
|
{:noreply, put_flash(socket, :error, error_message)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info({:editing_section_changed, section}, socket) do
|
||||||
|
{:noreply, assign(socket, :active_editing_section, section)}
|
||||||
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:member_field_saved, _member_field, action}, socket) do
|
def handle_info({:member_field_saved, _member_field, action}, socket) do
|
||||||
# Reload settings to get updated member_field_visibility
|
# Reload settings to get updated member_field_visibility
|
||||||
|
|
@ -178,6 +188,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:settings, updated_settings)
|
|> assign(:settings, updated_settings)
|
||||||
|
|> assign(:active_editing_section, nil)
|
||||||
|> put_flash(:info, gettext("Member field %{action} successfully", action: action))}
|
|> put_flash(:info, gettext("Member field %{action} successfully", action: action))}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue