Skip to content

Commit 780bde7

Browse files
authored
fix: user avatar renders a default avatar for users with no name (#5522)
1 parent cceb7df commit 780bde7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/identity/components/GlobalHeader/GlobalHeader.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ export const GlobalHeader: FC = () => {
7878
}, [orgsList])
7979

8080
const shouldLoadDropdowns = Boolean(activeOrg?.id && activeAccount?.id)
81-
const shouldLoadAvatar = Boolean(
82-
user?.firstName && user?.lastName && user?.email && org?.id
83-
)
81+
82+
const shouldLoadAvatar = Boolean(user?.email && org?.id)
83+
const avatarFirstName =
84+
typeof user?.firstName === 'string' ? user.firstName.trim() : ''
85+
const avatarLastName =
86+
typeof user?.lastName === 'string' ? user.lastName.trim() : ''
87+
8488
const shouldLoadGlobalHeader = Boolean(
8589
shouldLoadDropdowns || shouldLoadAvatar
8690
)
@@ -109,8 +113,8 @@ export const GlobalHeader: FC = () => {
109113
{shouldLoadAvatar && (
110114
<IdentityUserAvatar
111115
email={user.email}
112-
firstName={user.firstName}
113-
lastName={user.lastName}
116+
firstName={avatarFirstName}
117+
lastName={avatarLastName}
114118
orgId={org.id}
115119
/>
116120
)}

src/identity/components/GlobalHeader/IdentityUserAvatar.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class IdentityUserAvatar extends React.Component<Props, State> {
6767
<>
6868
<div className="user-popover-header">
6969
<div className="user-popover-header-name">
70-
{firstName} {lastName}
70+
{firstName ?? null} {lastName ?? null}
7171
</div>
7272
<div className="user-popover-header-email">{email}</div>
7373
<hr />
@@ -111,22 +111,24 @@ class IdentityUserAvatar extends React.Component<Props, State> {
111111
'user-popover--open': this.state.isPopoverOpen,
112112
})
113113

114+
const avatarInitials = this.getInitials()
115+
114116
const {isPopoverOpen} = this.state
115117
return (
116118
<ClickOutside onClickOutside={this.setPopoverStateClosed}>
117119
<div>
118120
{/* Button shape is ButtonShape.Square to make the height and width the same
119121
so we can use the border radius to make it a circle */}
120122
<Button
121-
text={this.getInitials()}
123+
text={avatarInitials}
122124
shape={ButtonShape.Square}
123125
color={
124126
isPopoverOpen ? ComponentColor.Default : ComponentColor.Tertiary
125127
}
126128
onClick={this.togglePopoverState}
127129
className={userAvatarButtonClassName}
128130
testID="global-header--user-avatar"
129-
icon={!this.getInitials() ? IconFont.User : null}
131+
icon={avatarInitials === '' ? IconFont.User : null}
130132
/>
131133
<FlexBox
132134
className={userPopoverClassName}

0 commit comments

Comments
 (0)