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 9e7e99e7cf..e60fe33f8f 100644 --- a/lib/dotcom_web/components/live_components/trip_planner_form.ex +++ b/lib/dotcom_web/components/live_components/trip_planner_form.ex @@ -26,7 +26,6 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do defaults = %{ form: %InputForm{} |> InputForm.changeset(form_defaults) |> to_form(), - location_keys: InputForm.Location.fields(), show_datepicker: false } @@ -46,9 +45,10 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do def render(assigns) do ~H"""
+ <.form :let={f} - class="md:grid md:grid-cols-2 gap-x-8 gap-y-2" + class="flex flex-col md:grid md:grid-cols-[1fr_max-content_1fr] gap-x-8 gap-y-4 md:gap-y-2" id={@id} for={@form} method="get" @@ -56,27 +56,25 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do phx-change="handle_change" phx-target={@myself} > -
- <.algolia_autocomplete - config_type="trip-planner" - placeholder="Enter a location" - id={"#{@form_name}--#{field}"} +

FROM

+
<%= inspect f[:from].value, pretty: true %>
+ +

TO

+
<%= inspect f[:to].value, pretty: true %>
+ + <.location_search_box name={"#{@form_name}--from"} field={f[:from]} /> +
+
+ <.location_search_box name={"#{@form_name}--to"} field={f[:to]} /> +
<.input_group legend="When" @@ -111,7 +109,8 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do <%= msg %>
-
+ +
<.fieldset id="modes" legend="Modes"> <.accordion id="accordion"> <:heading> @@ -141,7 +140,7 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do <.icon type="icon-svg" name="icon-accessible-small" class="h-5 w-5" />
-
+
<.button type="submit" phx-disable-with="Planning your trip..."> Get trip suggestions @@ -151,6 +150,30 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do """ end + defp location_search_box(assigns) do + assigns = assigns |> assign(:location_keys, InputForm.Location.fields()) + + ~H""" +
+ <.algolia_autocomplete config_type="trip-planner" placeholder="Enter a location" id={@name}> + <.inputs_for :let={location_f} field={@field} skip_hidden={true}> + + + <.feedback :for={{msg, _} <- @field.errors} :if={used_input?(@field)} kind={:error}> + <%= msg %> + + +
<%= inspect @field, pretty: true %>
+
+ """ + end + @impl true @doc """ If the user selects "now" for the date and time, hide the datepicker. @@ -191,6 +214,35 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerForm do {:noreply, save_form(params, socket)} end + def handle_event( + "swap_direction", + _params, + %{assigns: %{form: %{params: %{"from" => from, "to" => to} = form_params}}} = socket + ) do + new_form_params = + form_params + |> Map.put("to", from) + |> Map.put("from", to) + + send(self(), {:changed_form, new_form_params}) + + # dbg(new_form_params) + + validated_params = + new_form_params + |> InputForm.validate_params() + + # dbg(validated_params) + + new_form = + validated_params + |> Phoenix.Component.to_form() + + # dbg(new_form) + + {:noreply, assign(socket, %{form: new_form})} + end + defp datepicker_config do %{ default_date: Timex.now("America/New_York"),