diff --git a/lib/dotcom/trip_plan/input_form.ex b/lib/dotcom/trip_plan/input_form.ex index 758c5a6b5a..6456da979e 100644 --- a/lib/dotcom/trip_plan/input_form.ex +++ b/lib/dotcom/trip_plan/input_form.ex @@ -45,7 +45,7 @@ defmodule Dotcom.TripPlan.InputForm do %{ fromPlace: PlanParams.to_place_param(from), toPlace: PlanParams.to_place_param(to), - arriveBy: datetime_type == :arrive_by, + arriveBy: datetime_type == "arrive_by", date: PlanParams.to_date_param(datetime), time: PlanParams.to_time_param(datetime), transportModes: __MODULE__.Modes.selected_mode_keys(modes) |> PlanParams.to_modes_param(), @@ -110,7 +110,7 @@ defmodule Dotcom.TripPlan.InputForm do defp validate_chosen_datetime(changeset) do case get_field(changeset, :datetime_type) do - :now -> + "now" -> force_change(changeset, :datetime, Util.now()) _ -> diff --git a/lib/dotcom_web/components/live_components/trip_planner_form.ex b/lib/dotcom_web/components/live_components/trip_planner_form.ex index e812ec7146..d11032276e 100644 --- a/lib/dotcom_web/components/live_components/trip_planner_form.ex +++ b/lib/dotcom_web/components/live_components/trip_planner_form.ex @@ -20,17 +20,13 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do @impl true def mount(socket) do - form = - %InputForm{} - |> InputForm.changeset(@form_defaults) - |> to_form() - - {:ok, - assign(socket, %{ - form: form, - location_keys: InputForm.Location.fields(), - show_datepicker: false - })} + defaults = %{ + form: %InputForm{} |> InputForm.changeset(@form_defaults) |> to_form(), + location_keys: InputForm.Location.fields(), + show_datepicker: false + } + + {:ok, assign(socket, defaults)} end @impl true @@ -46,7 +42,7 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do phx-submit="save_form" phx-target={@myself} > -
+
<.algolia_autocomplete config_type="trip-planner" placeholder="Enter a location" @@ -149,7 +145,12 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do If the user selects arrive by or leave at, then we show the datepicker and set the time to the nearest 5 minutes. """ def handle_event("toggle_datepicker", %{"input_form" => %{"datetime_type" => "now"}}, socket) do - {:noreply, assign(socket, show_datepicker: false)} + new_socket = + socket + |> assign(show_datepicker: false) + |> push_event("set-datetime", %{datetime: nearest_5_minutes()}) + + {:noreply, new_socket} end def handle_event("toggle_datepicker", _, socket) do diff --git a/lib/dotcom_web/live/trip_planner.ex b/lib/dotcom_web/live/trip_planner.ex index 5ce4f3ca36..bda76d9ba5 100644 --- a/lib/dotcom_web/live/trip_planner.ex +++ b/lib/dotcom_web/live/trip_planner.ex @@ -43,7 +43,7 @@ defmodule DotcomWeb.Live.TripPlanner do to <%= @submitted_values.to.name %>
using <%= Modes.selected_modes(@submitted_values.modes) %>, - <%= if @submitted_values.datetime_type == :arrive_by, do: "Arriving by", else: "Leaving" %> <%= @submitted_values.datetime + <%= if @submitted_values.datetime_type == "arrive_by", do: "Arriving by", else: "Leaving" %> <%= @submitted_values.datetime |> Timex.format!("{Mfull} {D}, {h12}:{m} {AM}") %>