From 3cfae804d1ccf34daa60fdad2d4c1ef4bd27beeb Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Mon, 17 Jun 2024 17:40:32 -0400 Subject: [PATCH 1/4] Fix bug in plug pipelines (#388) This prevented the MethodOverride plug from working, which allows us to make links that have a `DELETE` method for example. Also update the logout button to use delete. --- lib/bike_brigade_web/components/layouts.ex | 2 +- lib/bike_brigade_web/endpoint.ex | 5 +++++ lib/bike_brigade_web/router.ex | 11 +---------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/bike_brigade_web/components/layouts.ex b/lib/bike_brigade_web/components/layouts.ex index eca6a567..0693ea69 100644 --- a/lib/bike_brigade_web/components/layouts.ex +++ b/lib/bike_brigade_web/components/layouts.ex @@ -77,7 +77,7 @@ defmodule BikeBrigadeWeb.Layouts do My Profile - <.sidebar_link selected={@current_page == :logout} href={~p"/logout"} method="post"> + <.sidebar_link selected={@current_page == :logout} href={~p"/logout"} method="delete"> <:icon> diff --git a/lib/bike_brigade_web/endpoint.ex b/lib/bike_brigade_web/endpoint.ex index 0f390f02..19402051 100644 --- a/lib/bike_brigade_web/endpoint.ex +++ b/lib/bike_brigade_web/endpoint.ex @@ -48,6 +48,11 @@ defmodule BikeBrigadeWeb.Endpoint do plug Plug.RequestId plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + plug Plug.MethodOverride plug Plug.Head plug Plug.Session, @session_options diff --git a/lib/bike_brigade_web/router.ex b/lib/bike_brigade_web/router.ex index 1859f7df..8a3773f6 100644 --- a/lib/bike_brigade_web/router.ex +++ b/lib/bike_brigade_web/router.ex @@ -27,15 +27,7 @@ defmodule BikeBrigadeWeb.Router do plug :get_user_from_session end - pipeline :parse_request do - plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], - pass: ["*/*"], - json_decoder: Phoenix.json_library() - end - pipeline :browser do - plug :parse_request plug :accepts, ["html"] plug :sessions plug :fetch_live_flash @@ -46,7 +38,6 @@ defmodule BikeBrigadeWeb.Router do end pipeline :api do - plug :parse_request plug :accepts, ["json"] end @@ -110,7 +101,7 @@ defmodule BikeBrigadeWeb.Router do live "/leaderboard", StatsLive.Leaderboard, :show end - post "/logout", Authentication, :logout + delete "/logout", Authentication, :logout end scope "/", BikeBrigadeWeb do From e0f91efb83b716dd53a73eb2737e65572ad1d540 Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Mon, 17 Jun 2024 17:43:30 -0400 Subject: [PATCH 2/4] Show first name and last initial on rider signup (#377) --- .../live/campaign_signup_live/show.ex | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/bike_brigade_web/live/campaign_signup_live/show.ex b/lib/bike_brigade_web/live/campaign_signup_live/show.ex index 8a7de720..7ebb9fc1 100644 --- a/lib/bike_brigade_web/live/campaign_signup_live/show.ex +++ b/lib/bike_brigade_web/live/campaign_signup_live/show.ex @@ -74,13 +74,13 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do |> redirect(to: ~p"/campaigns/signup/#{socket.assigns.campaign}") end - defp split_first_name(full_name) do - case String.split(full_name, " ") do + defp first_name_and_last_initial(full_name) do + case String.split(full_name, " ", parts: 2) do [first_name, last_name] when is_binary(first_name) and is_binary(last_name) -> - first_name + "#{first_name} #{String.first(last_name)}" - _ -> - full_name + [first_name] -> + first_name end end @@ -189,7 +189,10 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do
- 1} class="mr-1"> <%= task_item.count %><%= Inflex.inflect(task_item.item.name, task_item.count) %> + 1} class="mr-1"><%= task_item.count %><%= Inflex.inflect( + task_item.item.name, + task_item.count + ) %> <%= task_item.item.description %>
@@ -218,13 +221,12 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do
<%= if @task.assigned_rider do %>
- <%= split_first_name(@task.assigned_rider.name) %> + <%= first_name_and_last_initial(@task.assigned_rider.name) %>
You
- <.button :if={task_eligigle_for_unassign(@task, @campaign, @current_rider_id)} phx-click={JS.push("unassign_task", value: %{task_id: @task.id})} From 946ca36abc6f98f27be2b92d0580a7e03695772a Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Mon, 17 Jun 2024 17:43:39 -0400 Subject: [PATCH 3/4] Add prompt if the rider is unassigning a delivery today (#375) --- .../live/campaign_signup_live/show.ex | 18 ++++++++++--- .../live/campaign_signup_live_test.exs | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/bike_brigade_web/live/campaign_signup_live/show.ex b/lib/bike_brigade_web/live/campaign_signup_live/show.ex index 7ebb9fc1..0e9df0fd 100644 --- a/lib/bike_brigade_web/live/campaign_signup_live/show.ex +++ b/lib/bike_brigade_web/live/campaign_signup_live/show.ex @@ -1,4 +1,5 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do + alias BikeBrigade.LocalizedDateTime use BikeBrigadeWeb, :live_view import BikeBrigadeWeb.CampaignHelpers @@ -228,7 +229,12 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do You
<.button - :if={task_eligigle_for_unassign(@task, @campaign, @current_rider_id)} + :if={task_eligigle_for_unassign?(@task, @campaign, @current_rider_id)} + data-confirm={ + if campaign_today?(@campaign), + do: + "This delivery starts today. If you need to unassign yourself, please also text dispatch to let us know!" + } phx-click={JS.push("unassign_task", value: %{task_id: @task.id})} id={"#{@id}-unassign-task-#{@task.id}"} color={:red} @@ -239,7 +245,7 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do <% end %> - <%= if task_eligible_for_signup(@task, @campaign) do %> + <%= if task_eligible_for_signup?(@task, @campaign) do %> <.button phx-click={ JS.push("signup_rider", value: %{task_id: @task.id, rider_id: @current_rider_id}) @@ -268,16 +274,20 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do """ end - defp task_eligible_for_signup(task, campaign) do + defp task_eligible_for_signup?(task, campaign) do # campaign not in past, assigned rider not nil. task.assigned_rider == nil && !campaign_in_past(campaign) end # determine if a rider is eligible to "unassign" themselves - defp task_eligigle_for_unassign(task, campaign, current_rider_id) do + defp task_eligigle_for_unassign?(task, campaign, current_rider_id) do task.assigned_rider.id == current_rider_id && !campaign_in_past(campaign) end + defp campaign_today?(campaign) do + LocalizedDateTime.to_date(campaign.delivery_start) == LocalizedDateTime.today() + end + def initials(name) do name |> String.split(~r/[\s+|-]/, trim: true) diff --git a/test/bike_brigade_web/live/campaign_signup_live_test.exs b/test/bike_brigade_web/live/campaign_signup_live_test.exs index 9758abe1..8457474e 100644 --- a/test/bike_brigade_web/live/campaign_signup_live_test.exs +++ b/test/bike_brigade_web/live/campaign_signup_live_test.exs @@ -192,6 +192,25 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do assert live |> has_element?("#signup-btn-mobile-task-over-#{task.id}") end + test "Rider sees message about texting dispatch if unassigning from a campaign that's today", ctx do + + {:ok, live, html} = live(ctx.conn, ~p"/campaigns/signup/#{ctx.campaign.id}/") + assert html =~ "Sign up" + html = live |> element("#signup-btn-desktop-sign-up-task-#{ctx.task.id}") |> render_click() + assert html =~ "Unassign me" + assert html =~ "This delivery starts today. If you need to unassign yourself, please also text dispatch to let us know!" + + + campaign = make_campaign_in_future(ctx.program.id) + task = fixture(:task, %{campaign: campaign, rider: nil}) + + {:ok, live, html} = live(ctx.conn, ~p"/campaigns/signup/#{campaign.id}/") + + html = live |> element("#signup-btn-desktop-sign-up-task-#{task.id}") |> render_click() + assert html =~ "Unassign me" + refute html =~ "This delivery starts today. If you need to unassign yourself, please also text dispatch to let us know!" + end + test "we see pertinent task information", ctx do {:ok, live, html} = live(ctx.conn, ~p"/campaigns/signup/#{ctx.campaign.id}/") @@ -251,4 +270,12 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do delivery_end: LocalizedDateTime.now() |> DateTime.add(-7, :day) |> DateTime.add(60, :second) }) end + + defp make_campaign_in_future(program_id) do + fixture(:campaign, %{ + program_id: program_id, + delivery_start: LocalizedDateTime.now() |> DateTime.add(7, :day), + delivery_end: LocalizedDateTime.now() |> DateTime.add(7, :day) |> DateTime.add(60, :second) + }) + end end From b9fdf62de6476fcba5f9683c86a8f836feea4c10 Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Mon, 17 Jun 2024 17:44:17 -0400 Subject: [PATCH 4/4] Switch out the project board to the new one (#384) Update README.md Switch out the project board --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bfd154c..297863b8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![CI](https://github.com/mveytsman/bike-brigade/workflows/CI/badge.svg)](https://github.com/mveytsman/bike-brigade/actions?query=workflow%3ACI) # BikeBrigade -**[🎬 Project Board](https://github.com/orgs/bikebrigade/projects/4/views/1)** +**[🎬 Project Board](https://github.com/orgs/bikebrigade/projects/14/)** ## Prerequisities 1. [nix](https://nixos.org/download.html) with [flakes enabled](https://nixos.wiki/wiki/Flakes)