Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show initials for riders including last name #344

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/bike_brigade_web/live/campaign_signup_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ defmodule BikeBrigadeWeb.CampaignSignupLive.Show do
task.assigned_rider.id == current_rider_id && !campaign_in_past(campaign)
end

defp first_initial(name) do
name |> String.first() |> String.upcase()
defp initials(name) do
name
|> String.split(~r/[\s+|-]/)
|> Enum.map(&String.first/1)
|> Enum.map(&String.upcase/1)
|> Enum.join()
end
end
4 changes: 2 additions & 2 deletions lib/bike_brigade_web/live/campaign_signup_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<:col :let={task} label="Delivery Size">
<.get_delivery_size task={task} />
</:col>
<:col :let={task} label="Recipient"><%= first_initial(task.dropoff_name) %></:col>
<:col :let={task} label="Recipient"><%= initials(task.dropoff_name) %></:col>
<:col :let={task} label="Dropoff Neighbourhood">
<%= Locations.neighborhood(task.dropoff_location) %>
</:col>
Expand All @@ -39,7 +39,7 @@
<ul class="flex flex-col text-xs md:hidden">
<li :for={t <- @tasks} class="w-full mb-8">
<div class="flex justify-between px-4 py-3 font-bold bg-slate-200">
<span data-test-id={"dropoff-name-#{t.id}"}><%= first_initial(t.dropoff_name) %></span>
<span data-test-id={"dropoff-name-#{t.id}"}><%= initials(t.dropoff_name) %></span>
<span>Pickup: <%= pickup_window(@campaign) %></span>
</div>
<div class="flex flex-col bg-white shadow">
Expand Down
8 changes: 3 additions & 5 deletions test/bike_brigade_web/live/campaign_signup_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
res = login_as_rider(ctx)
campaign = fixture(:campaign, %{program_id: program.id})

task = fixture(:task, %{campaign: campaign, rider: nil})
task = fixture(:task, %{campaign: campaign, rider: nil, dropoff_name: "Carl Jo-Hanssen"})

Map.merge(res, %{program: program, campaign: campaign, task: task})
end
Expand Down Expand Up @@ -195,12 +195,10 @@ defmodule BikeBrigadeWeb.CampaignSignupLiveTest do
test "we see pertinent task information", ctx do
{:ok, live, html} = live(ctx.conn, ~p"/campaigns/signup/#{ctx.campaign.id}/")

# we only show the first initial of the dropoff name
# we only show the first initials of the dropoff name, which is Carl Jo-Hansen -> CJH
refute html =~ ctx.task.dropoff_name

assert live |> element("[data-test-id=dropoff-name-#{ctx.task.id}]") |> render =~
ctx.task.dropoff_name |> String.first() |> String.upcase()

assert live |> element("[data-test-id=dropoff-name-#{ctx.task.id}]") |> render =~ "CJH"
assert html =~ BikeBrigade.Locations.neighborhood(ctx.task.dropoff_location)
end

Expand Down
Loading