diff --git a/lib/mv_web/live/member_live/show.ex b/lib/mv_web/live/member_live/show.ex
index d84fca4..52c009a 100644
--- a/lib/mv_web/live/member_live/show.ex
+++ b/lib/mv_web/live/member_live/show.ex
@@ -131,15 +131,26 @@ defmodule MvWeb.MemberLive.Show do
<%!-- Custom Fields Section --%>
- <%= if Enum.any?(@member.custom_field_values) do %>
+ <%= if Enum.any?(@custom_fields_with_values) do %>
<.section_box title={gettext("Custom Fields")}>
- <%= for cfv <- sort_custom_field_values(@member.custom_field_values) do %>
- <% custom_field = cfv.custom_field %>
- <% value_type = custom_field && custom_field.value_type %>
- <.data_field label={custom_field && custom_field.name}>
- {format_custom_field_value(cfv.value, value_type)}
+ <%= for {custom_field, cfv} <- @custom_fields_with_values do %>
+ <.data_field label={custom_field.name}>
+ <%= if cfv && cfv.value do %>
+ <%= if custom_field.value_type == :email && cfv.value.value && String.trim(cfv.value.value) != "" do %>
+
+ {cfv.value.value}
+
+ <% else %>
+ {format_custom_field_value(cfv.value, custom_field.value_type)}
+ <% end %>
+ <% else %>
+ {format_custom_field_value(nil, custom_field.value_type)}
+ <% end %>
<% end %>
@@ -175,7 +186,7 @@ defmodule MvWeb.MemberLive.Show do
@impl true
def mount(_params, _session, socket) do
- {:ok, socket}
+ {:ok, assign(socket, :custom_fields_with_values, [])}
end
@impl true
@@ -187,10 +198,28 @@ defmodule MvWeb.MemberLive.Show do
member = Ash.read_one!(query)
+ # Load all custom fields to display all of them, even if they have no values
+ {:ok, custom_fields} = Mv.Membership.list_custom_fields()
+
+ # Create a map of custom_field_id -> custom_field_value for quick lookup
+ custom_field_values_map =
+ member.custom_field_values
+ |> Enum.map(fn cfv -> {cfv.custom_field_id, cfv} end)
+ |> Map.new()
+
+ # Match all custom fields with their values (if they exist)
+ custom_fields_with_values =
+ Enum.map(custom_fields, fn cf ->
+ cfv = Map.get(custom_field_values_map, cf.id)
+ {cf, cfv}
+ end)
+ |> Enum.sort_by(fn {cf, _cfv} -> cf.name end)
+
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
- |> assign(:member, member)}
+ |> assign(:member, member)
+ |> assign(:custom_fields_with_values, custom_fields_with_values)}
end
defp page_title(:show), do: gettext("Show Member")
@@ -272,19 +301,13 @@ defmodule MvWeb.MemberLive.Show do
defp format_date(date), do: to_string(date)
- # Sorts custom field values by custom field name
- defp sort_custom_field_values(custom_field_values) do
- Enum.sort_by(custom_field_values, fn cfv ->
- (cfv.custom_field && cfv.custom_field.name) || ""
- end)
- end
-
# Formats custom field value based on type
+ # Returns empty string for nil/empty values (consistent with member fields behavior)
defp format_custom_field_value(%Ash.Union{value: value, type: type}, _expected_type) do
format_custom_field_value(value, type)
end
- defp format_custom_field_value(nil, _type), do: "—"
+ defp format_custom_field_value(nil, _type), do: ""
defp format_custom_field_value(value, :boolean) when is_boolean(value) do
if value, do: gettext("Yes"), else: gettext("No")
@@ -295,11 +318,7 @@ defmodule MvWeb.MemberLive.Show do
end
defp format_custom_field_value(value, :email) when is_binary(value) do
- assigns = %{email: value}
-
- ~H"""
-
{@email}
- """
+ if String.trim(value) == "", do: "", else: value
end
defp format_custom_field_value(value, :integer) when is_integer(value) do
@@ -307,7 +326,7 @@ defmodule MvWeb.MemberLive.Show do
end
defp format_custom_field_value(value, _type) when is_binary(value) do
- if String.trim(value) == "", do: "—", else: value
+ if String.trim(value) == "", do: "", else: value
end
defp format_custom_field_value(value, _type), do: to_string(value)