WIP: Implements settings for member fields closes #223 #300

Draft
carla wants to merge 8 commits from feature/223_memberfields_settings into main
2 changed files with 171 additions and 155 deletions
Showing only changes of commit c88f805b6e - Show all commits

View file

@ -17,8 +17,7 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
assigns = assign(assigns, :field_type_label, &MvWeb.Translations.FieldTypes.label/1)
~H"""
<div id={@id}>
<.form_section title={gettext("Custom Fields")}>
<div id={@id} class="mt-8">
<div class="flex">
<p class="text-sm text-base-content/70">
{gettext("These will appear in addition to other data when adding new members.")}
@ -103,9 +102,7 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
</:action>
<:action :let={{_id, custom_field}}>
<.link phx-click={
JS.push("prepare_delete", value: %{id: custom_field.id}, target: @myself)
}>
<.link phx-click={JS.push("prepare_delete", value: %{id: custom_field.id}, target: @myself)}>
{gettext("Delete")}
</.link>
</:action>
@ -175,7 +172,6 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
</div>
</div>
</dialog>
</.form_section>
</div>
"""
end

View file

@ -63,6 +63,7 @@ defmodule MvWeb.GlobalSettingsLive do
</.form>
</.form_section>
<%!-- Memberdata Section --%>
<.form_section title={gettext("Memberdata")}>
<.live_component
module={MvWeb.MemberFieldLive.IndexComponent}
id="member-fields-component"
@ -73,6 +74,7 @@ defmodule MvWeb.GlobalSettingsLive do
module={MvWeb.CustomFieldLive.IndexComponent}
id="custom-fields-component"
/>
</.form_section>
</Layouts.app>
"""
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(