From c88f805b6ebdaab646b2e485481deda3c7e8f5fa Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 16 Dec 2025 17:16:29 +0100 Subject: [PATCH] style: combines member and custom fields in settings --- .../live/custom_field_live/index_component.ex | 286 +++++++++--------- lib/mv_web/live/global_settings_live.ex | 40 ++- 2 files changed, 171 insertions(+), 155 deletions(-) diff --git a/lib/mv_web/live/custom_field_live/index_component.ex b/lib/mv_web/live/custom_field_live/index_component.ex index ca67799..5de2ebf 100644 --- a/lib/mv_web/live/custom_field_live/index_component.ex +++ b/lib/mv_web/live/custom_field_live/index_component.ex @@ -17,165 +17,161 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do assigns = assign(assigns, :field_type_label, &MvWeb.Translations.FieldTypes.label/1) ~H""" -
- <.form_section title={gettext("Custom Fields")}> -
-

- {gettext("These will appear in addition to other data when adding new members.")} -

-
- <.button - class="ml-auto" - variant="primary" - phx-click="new_custom_field" - phx-target={@myself} - > - <.icon name="hero-plus" /> {gettext("New Custom field")} - -
+
+
+

+ {gettext("These will appear in addition to other data when adding new members.")} +

+
+ <.button + class="ml-auto" + variant="primary" + phx-click="new_custom_field" + phx-target={@myself} + > + <.icon name="hero-plus" /> {gettext("New Custom field")} +
- <%!-- Show form when creating or editing --%> -
- <.live_component - module={MvWeb.CustomFieldLive.FormComponent} - id={@form_id} - custom_field={@editing_custom_field} - on_save={ - fn custom_field, action -> send(self(), {:custom_field_saved, custom_field, action}) end - } - on_cancel={fn -> send_update(__MODULE__, id: @id, show_form: false) end} - /> -
- - <%!-- Hide table when form is visible --%> - <.table - :if={!@show_form} - id="custom_fields" - rows={@streams.custom_fields} - row_click={ - fn {_id, custom_field} -> - JS.push("edit_custom_field", value: %{id: custom_field.id}, target: @myself) - end +
+ <%!-- Show form when creating or editing --%> +
+ <.live_component + module={MvWeb.CustomFieldLive.FormComponent} + id={@form_id} + custom_field={@editing_custom_field} + on_save={ + fn custom_field, action -> send(self(), {:custom_field_saved, custom_field, action}) end } + on_cancel={fn -> send_update(__MODULE__, id: @id, show_form: false) end} + /> +
+ + <%!-- Hide table when form is visible --%> + <.table + :if={!@show_form} + id="custom_fields" + rows={@streams.custom_fields} + row_click={ + fn {_id, custom_field} -> + JS.push("edit_custom_field", value: %{id: custom_field.id}, target: @myself) + end + } + > + <:col :let={{_id, custom_field}} label={gettext("Name")}>{custom_field.name} + + <:col :let={{_id, custom_field}} label={gettext("Value Type")}> + {@field_type_label.(custom_field.value_type)} + + + <:col :let={{_id, custom_field}} label={gettext("Description")}> + {custom_field.description} + + + <:col + :let={{_id, custom_field}} + label={gettext("Required")} + class="max-w-[9.375rem] text-center" > - <:col :let={{_id, custom_field}} label={gettext("Name")}>{custom_field.name} + + {gettext("Required")} + + + {gettext("Optional")} + + - <:col :let={{_id, custom_field}} label={gettext("Value Type")}> - {@field_type_label.(custom_field.value_type)} - + <:col + :let={{_id, custom_field}} + label={gettext("Show in overview")} + class="max-w-[9.375rem] text-center" + > + + {gettext("Yes")} + + + {gettext("No")} + + - <:col :let={{_id, custom_field}} label={gettext("Description")}> - {custom_field.description} - + <:action :let={{_id, custom_field}}> + <.link phx-click={ + JS.push("edit_custom_field", value: %{id: custom_field.id}, target: @myself) + }> + {gettext("Edit")} + + - <:col - :let={{_id, custom_field}} - label={gettext("Required")} - class="max-w-[9.375rem] text-center" - > - - {gettext("Required")} - - - {gettext("Optional")} - - + <:action :let={{_id, custom_field}}> + <.link phx-click={JS.push("prepare_delete", value: %{id: custom_field.id}, target: @myself)}> + {gettext("Delete")} + + + - <:col - :let={{_id, custom_field}} - label={gettext("Show in overview")} - class="max-w-[9.375rem] text-center" - > - - {gettext("Yes")} - - - {gettext("No")} - - - - <:action :let={{_id, custom_field}}> - <.link phx-click={ - JS.push("edit_custom_field", value: %{id: custom_field.id}, target: @myself) - }> - {gettext("Edit")} - - - - <:action :let={{_id, custom_field}}> - <.link phx-click={ - JS.push("prepare_delete", value: %{id: custom_field.id}, target: @myself) - }> - {gettext("Delete")} - - - - - <%!-- Delete Confirmation Modal --%> - -
""" end diff --git a/lib/mv_web/live/global_settings_live.ex b/lib/mv_web/live/global_settings_live.ex index 87a1a4d..bd57d55 100644 --- a/lib/mv_web/live/global_settings_live.ex +++ b/lib/mv_web/live/global_settings_live.ex @@ -63,16 +63,18 @@ defmodule MvWeb.GlobalSettingsLive do <%!-- Memberdata Section --%> - <.live_component - module={MvWeb.MemberFieldLive.IndexComponent} - id="member-fields-component" - settings={@settings} - /> - <%!-- Custom Fields Section --%> - <.live_component - module={MvWeb.CustomFieldLive.IndexComponent} - id="custom-fields-component" - /> + <.form_section title={gettext("Memberdata")}> + <.live_component + module={MvWeb.MemberFieldLive.IndexComponent} + id="member-fields-component" + settings={@settings} + /> + <%!-- Custom Fields Section --%> + <.live_component + module={MvWeb.CustomFieldLive.IndexComponent} + id="custom-fields-component" + /> + """ end @@ -158,6 +160,24 @@ defmodule MvWeb.GlobalSettingsLive do {:noreply, put_flash(socket, :error, error_message)} end + @impl true + def handle_info({:member_field_saved, _member_field, action}, socket) do + # Reload settings to get updated member_field_visibility + {:ok, updated_settings} = Membership.get_settings() + + # Send update to member fields component to close form + send_update(MvWeb.MemberFieldLive.IndexComponent, + id: "member-fields-component", + show_form: false, + settings: updated_settings + ) + + {:noreply, + socket + |> assign(:settings, updated_settings) + |> put_flash(:info, gettext("Member field %{action} successfully", action: action))} + end + defp assign_form(%{assigns: %{settings: settings}} = socket) do form = AshPhoenix.Form.for_update(