fix: labels for custom fields in join requests
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
a6f6f402af
commit
0a7bbc7fa6
4 changed files with 88 additions and 12 deletions
|
|
@ -216,19 +216,48 @@ defmodule MvWeb.JoinLive do
|
|||
|
||||
defp build_join_fields_with_labels(allowlist) do
|
||||
member_field_strings = Mv.Constants.member_fields() |> Enum.map(&Atom.to_string/1)
|
||||
custom_field_name_by_id = custom_field_name_map(allowlist, member_field_strings)
|
||||
|
||||
Enum.map(allowlist, fn %{id: id, required: required} ->
|
||||
label =
|
||||
if id in member_field_strings do
|
||||
MemberFields.label(String.to_existing_atom(id))
|
||||
else
|
||||
gettext("Field")
|
||||
Map.get(custom_field_name_by_id, id, gettext("Field"))
|
||||
end
|
||||
|
||||
%{id: id, label: label, required: required}
|
||||
end)
|
||||
end
|
||||
|
||||
defp custom_field_name_map(allowlist, member_field_strings) do
|
||||
custom_field_ids =
|
||||
allowlist
|
||||
|> Enum.map(& &1.id)
|
||||
|> Enum.reject(&(&1 in member_field_strings))
|
||||
|
||||
case custom_field_ids do
|
||||
[] ->
|
||||
%{}
|
||||
|
||||
ids ->
|
||||
Mv.Membership.CustomField
|
||||
|> Ash.Query.select([:id, :name])
|
||||
|> Ash.read(domain: Mv.Membership, authorize?: false)
|
||||
|> case do
|
||||
{:ok, fields} ->
|
||||
allowed_ids = MapSet.new(ids)
|
||||
|
||||
fields
|
||||
|> Enum.filter(&MapSet.member?(allowed_ids, &1.id))
|
||||
|> Map.new(&{&1.id, &1.name})
|
||||
|
||||
{:error, _} ->
|
||||
%{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp initial_form_params(join_fields) do
|
||||
join_fields
|
||||
|> Enum.map(fn f -> {f.id, ""} end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue