diff --git a/lib/moon/components/checkbox.ex b/lib/moon/components/checkbox.ex
index b0065bd93..ef893279f 100644
--- a/lib/moon/components/checkbox.ex
+++ b/lib/moon/components/checkbox.ex
@@ -20,12 +20,14 @@ defmodule Moon.Components.Checkbox do
field={@field}
click={@click}
class="z-10 absolute left-0 opacity-0"
+ checked_value="true"
+ unchecked_value="false"
opts={disabled: @disabled}
/>
{fake_checkbox(
assigns,
- selected: Phoenix.HTML.Form.input_value(form, field) || @checked
+ selected: is_true(Phoenix.HTML.Form.input_value(form, field)) || is_true(@checked)
)}
@@ -34,6 +36,10 @@ defmodule Moon.Components.Checkbox do
"""
end
+ def is_true(val) do
+ Enum.member?([true, "true"], val)
+ end
+
def fake_checkbox(assigns, selected: selected) do
~F"""
@@ -86,46 +67,38 @@ defmodule MoonWeb.Pages.Components.CheckboxPage do
"""
end
- def get_agrees_to_terms_of_service(user_changeset) do
- if user_changeset.changes[:agrees_to_terms_of_service] == false do
- false
- else
- user_changeset.data.agrees_to_terms_of_service
- end
- end
-
- def handle_event(
- "register_form_update",
- %{
- "user" => %{
- "agrees_to_marketing_emails" => agrees_to_marketing_emails,
- "agrees_to_terms_of_service" => agrees_to_terms_of_service
- }
- },
- socket
- ) do
+ def mount(params, _session, socket) do
user_changeset =
User.changeset(%User{}, %{
- agrees_to_terms_of_service: agrees_to_terms_of_service,
- agrees_to_marketing_emails: agrees_to_marketing_emails
+ agrees_to_terms_of_service: false,
+ agrees_to_marketing_emails: true
})
- {:noreply, assign(socket, user_changeset: user_changeset)}
+ {:ok,
+ assign(socket,
+ user_changeset: user_changeset,
+ theme_name: params["theme_name"] || "sportsbet-dark",
+ active_page: __MODULE__
+ )}
+ end
+
+ def handle_params(_params, uri, socket) do
+ {:noreply, assign(socket, uri: uri)}
+ end
+
+ def get_agrees_to_terms_of_service(user_changeset) do
+ Moon.Components.Checkbox.is_true(user_changeset.changes[:agrees_to_terms_of_service]) ||
+ Moon.Components.Checkbox.is_true(user_changeset.data.agrees_to_terms_of_service)
end
def handle_event(
"register_form_update",
%{
- "user" => %{
- "agrees_to_terms_of_service" => agrees_to_terms_of_service
- }
+ "user" => params
},
socket
) do
- user_changeset =
- User.changeset(%User{}, %{
- agrees_to_terms_of_service: agrees_to_terms_of_service
- })
+ user_changeset = User.changeset(%User{}, params)
{:noreply, assign(socket, user_changeset: user_changeset)}
end