From f4838fcc2cf68c10effaef5ee3c21cde6dd13ac2 Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Fri, 26 Apr 2024 11:33:06 -0400 Subject: [PATCH] Show initials for riders including last name --- lib/bike_brigade_web/live/campaign_signup_live/show.ex | 8 ++++++-- .../live/campaign_signup_live/show.html.heex | 4 ++-- test/bike_brigade_web/live/campaign_signup_live_test.exs | 8 +++----- 3 files changed, 11 insertions(+), 9 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 2ecaed4c..b29e8f94 100644 --- a/lib/bike_brigade_web/live/campaign_signup_live/show.ex +++ b/lib/bike_brigade_web/live/campaign_signup_live/show.ex @@ -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 diff --git a/lib/bike_brigade_web/live/campaign_signup_live/show.html.heex b/lib/bike_brigade_web/live/campaign_signup_live/show.html.heex index 6d7d0c43..82167f74 100644 --- a/lib/bike_brigade_web/live/campaign_signup_live/show.html.heex +++ b/lib/bike_brigade_web/live/campaign_signup_live/show.html.heex @@ -19,7 +19,7 @@ <:col :let={task} label="Delivery Size"> <.get_delivery_size task={task} /> - <:col :let={task} label="Recipient"><%= first_initial(task.dropoff_name) %> + <:col :let={task} label="Recipient"><%= initials(task.dropoff_name) %> <:col :let={task} label="Dropoff Neighbourhood"> <%= Locations.neighborhood(task.dropoff_location) %> @@ -39,7 +39,7 @@