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 8fbfb6a1..dd76d29f 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 @@ -224,7 +225,12 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do <.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} @@ -235,7 +241,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}) @@ -264,16 +270,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