Use username as fallback
This commit is contained in:
parent
e82c9c0bd4
commit
1651d52c18
6 changed files with 12 additions and 5 deletions
|
@ -376,4 +376,8 @@ defmodule ChoreTracker.Accounts do
|
|||
{:error, :user, changeset, _} -> {:error, changeset}
|
||||
end
|
||||
end
|
||||
|
||||
def display_user(%User{} = user) do
|
||||
user.display_name || user.username
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
defmodule ChoreTrackerWeb.Layouts do
|
||||
use ChoreTrackerWeb, :html
|
||||
alias ChoreTracker.Accounts
|
||||
|
||||
embed_templates "layouts/*"
|
||||
|
||||
|
@ -9,7 +10,7 @@ defmodule ChoreTrackerWeb.Layouts do
|
|||
<nav class="flex items-center gap-4 px-6 justify-end">
|
||||
<%= if @current_user do %>
|
||||
<p class="text-sm font-medium mr-2">
|
||||
<%= @current_user.display_name %>
|
||||
<%= Accounts.display_user(@current_user) %>
|
||||
</p>
|
||||
<.header_link href={~p"/users/settings"}>
|
||||
Settings
|
||||
|
|
|
@ -113,6 +113,6 @@ defmodule ChoreTrackerWeb.ChoreLive.FormComponent do
|
|||
|> Enum.map(& &1.data.id)
|
||||
|
||||
Accounts.list_users()
|
||||
|> Enum.map(&[key: &1.display_name, value: &1.id, selected: &1.id in existing_ids])
|
||||
|> Enum.map(&[key: Accounts.display_user(&1), value: &1.id, selected: &1.id in existing_ids])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
defmodule ChoreTrackerWeb.ChoreLive.Show do
|
||||
alias ChoreTracker.Chores.Chore
|
||||
use ChoreTrackerWeb, :live_view
|
||||
|
||||
alias ChoreTracker.Chores
|
||||
alias ChoreTracker.Accounts
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<% else %>
|
||||
<ul>
|
||||
<%= for assignee <- @chore.assignees do %>
|
||||
<li><%= assignee.display_name %></li>
|
||||
<li><%= Accounts.display_user(assignee) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
@ -56,7 +56,7 @@
|
|||
<p>There are no logs</p>
|
||||
<% else %>
|
||||
<.table id="chore_logs" rows={@chore.logs}>
|
||||
<:col :let={chore_log} label="User"><%= chore_log.user.display_name %></:col>
|
||||
<:col :let={chore_log} label="User"><%= Accounts.display_user(chore_log.user) %></:col>
|
||||
<:col :let={chore_log} label="Execution date">
|
||||
<span class="flex gap-3">
|
||||
<span>
|
||||
|
|
|
@ -38,7 +38,7 @@ defmodule ChoreTrackerWeb.OverviewLive do
|
|||
<:col :let={chore} label="Next assignee">
|
||||
<%= case Chores.next_chore_assignee(chore) do
|
||||
nil -> "No assignee"
|
||||
%Accounts.User{} = user -> user.display_name
|
||||
%Accounts.User{} = user -> Accounts.display_user(user)
|
||||
end %>
|
||||
</:col>
|
||||
<:action :let={chore}>
|
||||
|
|
Loading…
Reference in a new issue