refactor: fix review issues
This commit is contained in:
parent
cc1df449c6
commit
f8e1d39964
5 changed files with 49 additions and 44 deletions
|
|
@ -6,8 +6,8 @@ defmodule MvWeb.JoinLive do
|
|||
use MvWeb, :live_view
|
||||
|
||||
alias Ash.Resource.Info
|
||||
alias Mv.Membership.CustomFieldLookup
|
||||
alias Mv.Membership
|
||||
alias Mv.Membership.CustomFieldLookup
|
||||
alias MvWeb.JoinRateLimit
|
||||
alias MvWeb.Translations.MemberFields
|
||||
|
||||
|
|
@ -81,14 +81,12 @@ defmodule MvWeb.JoinLive do
|
|||
<% end %>
|
||||
|
||||
<%= for field <- @join_fields do %>
|
||||
<div class={
|
||||
if field.input_type == "checkbox", do: "flex items-end gap-3", else: ""
|
||||
}>
|
||||
<label for={"join-field-#{field.id}"} class="label">
|
||||
<span class="label-text">{field.label}{if field.required, do: " *"}</span>
|
||||
</label>
|
||||
<%= if field.input_type == "checkbox" do %>
|
||||
<input type="hidden" name={field.id} value="off" />
|
||||
<%= if field.input_type == "checkbox" do %>
|
||||
<input type="hidden" name={field.id} value="off" />
|
||||
<label
|
||||
for={"join-field-#{field.id}"}
|
||||
class="label cursor-pointer justify-start gap-3"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
name={field.id}
|
||||
|
|
@ -97,7 +95,17 @@ defmodule MvWeb.JoinLive do
|
|||
required={field.required}
|
||||
class="checkbox checkbox-sm"
|
||||
/>
|
||||
<% else %>
|
||||
<span class="label-text">
|
||||
{field.label}<span :if={field.required} aria-hidden="true"> *</span>
|
||||
</span>
|
||||
</label>
|
||||
<% else %>
|
||||
<div>
|
||||
<label for={"join-field-#{field.id}"} class="label">
|
||||
<span class="label-text">
|
||||
{field.label}<span :if={field.required} aria-hidden="true"> *</span>
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
type={field.input_type}
|
||||
name={field.id}
|
||||
|
|
@ -106,8 +114,8 @@ defmodule MvWeb.JoinLive do
|
|||
required={field.required}
|
||||
class="input input-bordered w-full"
|
||||
/>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%!--
|
||||
|
|
@ -274,7 +282,8 @@ defmodule MvWeb.JoinLive do
|
|||
field_atom ->
|
||||
Mv.Membership.Member
|
||||
|> Info.attribute(field_atom)
|
||||
|> attribute_to_input_type()
|
||||
|> Map.get(:type)
|
||||
|> input_type_for()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -285,21 +294,17 @@ defmodule MvWeb.JoinLive do
|
|||
|> Enum.find(&(Atom.to_string(&1) == field_id))
|
||||
end
|
||||
|
||||
defp custom_field_input_type(type), do: attribute_to_input_type(%{type: type})
|
||||
defp custom_field_input_type(type), do: input_type_for(type)
|
||||
|
||||
defp attribute_to_input_type(%{type: type}) when type in [:date, Ash.Type.Date], do: "date"
|
||||
|
||||
defp attribute_to_input_type(%{type: type}) when type in [:integer, Ash.Type.Integer],
|
||||
do: "number"
|
||||
|
||||
defp attribute_to_input_type(%{type: type}) when type in [:boolean, Ash.Type.Boolean],
|
||||
do: "checkbox"
|
||||
|
||||
defp attribute_to_input_type(%{type: type}) when type in [:email, Mv.Membership.Email],
|
||||
do: "email"
|
||||
|
||||
defp attribute_to_input_type(%{type: _}), do: "text"
|
||||
defp attribute_to_input_type(nil), do: "text"
|
||||
defp input_type_for(:date), do: "date"
|
||||
defp input_type_for(Ash.Type.Date), do: "date"
|
||||
defp input_type_for(:integer), do: "number"
|
||||
defp input_type_for(Ash.Type.Integer), do: "number"
|
||||
defp input_type_for(:boolean), do: "checkbox"
|
||||
defp input_type_for(Ash.Type.Boolean), do: "checkbox"
|
||||
defp input_type_for(:email), do: "email"
|
||||
defp input_type_for(Mv.Membership.Email), do: "email"
|
||||
defp input_type_for(_), do: "text"
|
||||
|
||||
defp checkbox_checked?(value) when value in [true, "true", "on", "1"], do: true
|
||||
defp checkbox_checked?(_), do: false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue