diff --git a/lib/shift73k/shifts/templates/shift_template.ex b/lib/shift73k/shifts/templates/shift_template.ex index 56ae8ac5..37c4949d 100644 --- a/lib/shift73k/shifts/templates/shift_template.ex +++ b/lib/shift73k/shifts/templates/shift_template.ex @@ -57,6 +57,7 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do [] end end) + |> validate_not_nil([:time_zone]) |> validate_inclusion(:time_zone, Tzdata.zone_list(), message: "must be a valid IANA tz database time zone" ) @@ -72,4 +73,14 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do |> Map.from_struct() |> Map.drop([:__meta__, :id, :inserted_at, :updated_at, :user, :is_fave_of_user]) end + + def validate_not_nil(changeset, fields) do + Enum.reduce(fields, changeset, fn field, changeset -> + if get_field(changeset, field) == nil do + add_error(changeset, field, "nil") + else + changeset + end + end) + end end diff --git a/lib/shift73k_web/live/shift_assign_live/delete_component.html.heex b/lib/shift73k_web/live/shift_assign_live/delete_component.html.heex new file mode 100644 index 00000000..0f3a91d7 --- /dev/null +++ b/lib/shift73k_web/live/shift_assign_live/delete_component.html.heex @@ -0,0 +1,35 @@ +
+ + + + +
\ No newline at end of file diff --git a/lib/shift73k_web/live/shift_assign_live/delete_component.html.leex b/lib/shift73k_web/live/shift_assign_live/delete_component.html.leex deleted file mode 100644 index 81aa79a6..00000000 --- a/lib/shift73k_web/live/shift_assign_live/delete_component.html.leex +++ /dev/null @@ -1,31 +0,0 @@ - - diff --git a/lib/shift73k_web/live/shift_assign_live/index.ex b/lib/shift73k_web/live/shift_assign_live/index.ex index 670c32b9..24777847 100644 --- a/lib/shift73k_web/live/shift_assign_live/index.ex +++ b/lib/shift73k_web/live/shift_assign_live/index.ex @@ -1,5 +1,6 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do use Shift73kWeb, :live_view + import Shift73k, only: [app_time_zone: 0] alias Shift73k.Repo alias Shift73k.Shifts diff --git a/lib/shift73k_web/live/shift_assign_live/index.html.leex b/lib/shift73k_web/live/shift_assign_live/index.html.heex similarity index 75% rename from lib/shift73k_web/live/shift_assign_live/index.html.leex rename to lib/shift73k_web/live/shift_assign_live/index.html.heex index 9c88881c..ce1d37a4 100644 --- a/lib/shift73k_web/live/shift_assign_live/index.html.leex +++ b/lib/shift73k_web/live/shift_assign_live/index.html.heex @@ -23,14 +23,19 @@ %> <% end %> - -
" id="#templateDetailsCol" phx-hook="BsCollapse"> + + <% template_details_div_class = "col-12 col-lg-9 col-xl-8 col-xxl-7 collapse" + template_details_div_class = if @show_template_details, do: "#{template_details_div_class} show", else: template_details_div_class %> +
@@ -40,8 +45,8 @@
<%= label stf, :subject, "Subject/Title", class: "form-label" %> -
- <%= icon_div @socket, "bi-tag", [class: "icon is-left text-muted fs-5"] %> +
+ <%= text_input stf, :subject, value: input_value(stf, :subject), class: input_class(stf, :subject, "form-control"), @@ -56,25 +61,27 @@
-
+
<%= label stf, :time_start, "Start", class: "form-label" %> <%= time_input stf, :time_start, precision: :minute, value: input_value(stf, :time_start), class: input_class(stf, :time_start, "form-control"), disabled: @shift_template.id != @custom_shift.id, - aria_describedby: error_ids(stf, :time_start) + aria_describedby: error_ids(stf, :time_start), + required: true %>
-
+
<%= label stf, :time_end, "End", class: "form-label" %> <%= time_input stf, :time_end, precision: :minute, value: input_value(stf, :time_end), class: input_class(stf, :time_end, "form-control"), disabled: @shift_template.id != @custom_shift.id, - aria_describedby: error_ids(stf, :time_end) + aria_describedby: error_ids(stf, :time_end), + required: true %>
@@ -82,18 +89,18 @@
Shift length: <%= @shift_length %>
-
+
<%= error_tag stf, :time_start %>
-
+
<%= error_tag stf, :time_end %>
<%= label stf, :location, class: "form-label" %> -
- <%= icon_div @socket, "bi-geo", [class: "icon is-left text-muted fs-5"] %> +
+ <%= text_input stf, :location, value: input_value(stf, :location), class: input_class(stf, :location, "form-control"), @@ -107,18 +114,19 @@
<%= label stf, :time_zone, class: "form-label" %> -
- <%= icon_div @socket, "bi-map", [class: "icon is-left text-muted fs-5"] %> +
+ <%= text_input stf, :time_zone, value: input_value(stf, :time_zone), class: input_class(stf, :time_zone, "form-control"), disabled: @shift_template.id != @custom_shift.id, phx_debounce: 250, - list: "tz_list" + list: "tz_list", + placeholder: "Default: #{app_time_zone()}" %> <%= for tz_name <- Tzdata.zone_list() do %> - + <% end %> end @@ -131,7 +139,7 @@
<%= label stf, :description, class: "form-label" %> -
+
<%= textarea stf, :description, value: input_value(stf, :description), @@ -173,17 +181,17 @@ <%= Calendar.strftime(@cursor_date, "%B %Y") %>
-
@@ -203,7 +211,7 @@ <%= for week <- @week_rows do %> <%= for day <- week do %> - + <%= Calendar.strftime(day, "%d") %><%= if day.month != @cursor_date.month, do: "-#{Calendar.strftime(day, "%b")}" %> @@ -235,19 +243,16 @@
- - -
diff --git a/lib/shift73k_web/live/shift_template_live/form_component.ex b/lib/shift73k_web/live/shift_template_live/form_component.ex index d4263bcd..ef000a36 100644 --- a/lib/shift73k_web/live/shift_template_live/form_component.ex +++ b/lib/shift73k_web/live/shift_template_live/form_component.ex @@ -1,5 +1,6 @@ defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do use Shift73kWeb, :live_component + import Shift73k, only: [app_time_zone: 0] alias Shift73k.Shifts.Templates alias Shift73k.Shifts.Templates.ShiftTemplate diff --git a/lib/shift73k_web/live/shift_template_live/form_component.html.heex b/lib/shift73k_web/live/shift_template_live/form_component.html.heex index a2ce3b52..66f944d9 100644 --- a/lib/shift73k_web/live/shift_template_live/form_component.html.heex +++ b/lib/shift73k_web/live/shift_template_live/form_component.html.heex @@ -1,11 +1,6 @@
- <%= form_for @changeset, "#", [ - id: "shift_template-form", - phx_target: @myself, - phx_change: "validate", - phx_submit: "save" - ], fn f -> %> + <.form let={f} for={@changeset} phx-change="validate" phx-submit="save" phx-target={@myself} id="shift_template-form"> - <% end %> +