Skip to content
Open
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
16 changes: 12 additions & 4 deletions app/views/shared/_navbar_user.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="navbar-user-button relative" id="avatar" data-controller="dropdown">
<% user = current_user %>
<% person = user&.person %>
<% avatar_image = person&.avatar&.attached? ? person.avatar.variant(:thumbnail) : "missing.png" %>
<% has_avatar = person&.avatar&.attached? %>

<button
type="button"
Expand All @@ -12,9 +12,17 @@
<span class="sr-only">Open user menu</span>
<span class="absolute -inset-1.5"></span>

<%= image_tag avatar_image,
id: "avatar-image",
class: "size-10 rounded-full bg-gray-800 outline -outline-offset-1 outline-white/10" %>
<% if has_avatar %>
<%= image_tag person.avatar.variant(:thumbnail),
id: "avatar-image",
class: "size-10 rounded-full bg-gray-800 outline -outline-offset-1 outline-white/10" %>
<% else %>
<span id="avatar-image"
class="size-10 rounded-full bg-sky-200 text-sky-700 font-bold text-lg
flex items-center justify-center border border-sky-300 shadow-sm">
<%= (person&.first_name.presence || user.first_name.presence || user.email).to_s.first.upcase %>
</span>
<% end %>
</button>

<!-- Dropdown menu -->
Expand Down
5 changes: 3 additions & 2 deletions spec/system/navbar_avatar_updates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
person.reload
expect(person.avatar).not_to be_attached

avatar_img = find("#avatar-image")
expect(avatar_img[:src]).to include("missing")
avatar_el = find("#avatar-image")
expect(avatar_el.tag_name).to eq("span")
expect(avatar_el.text).to eq(person.first_name.first.upcase)
end
end
end