Skip to content

Commit

Permalink
feat: display profile name in non-learning header navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Apr 12, 2024
1 parent 6d7cf99 commit f7d9fb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/DesktopHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ class DesktopHeader extends React.Component {
userMenu,
avatar,
username,
name,
intl,
} = this.props;

return (
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
<MenuTrigger
tag="button"
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { name || username })}
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
>
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
{username} <CaretIcon role="img" aria-hidden focusable="false" />
{name || username} <CaretIcon role="img" aria-hidden focusable="false" />
</MenuTrigger>
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
{userMenu.map(({ type, href, content }) => (
Expand Down Expand Up @@ -178,6 +179,7 @@ DesktopHeader.propTypes = {
logoDestination: PropTypes.string,
avatar: PropTypes.string,
username: PropTypes.string,
name: PropTypes.string,
loggedIn: PropTypes.bool,

// i18n
Expand Down Expand Up @@ -207,6 +209,7 @@ DesktopHeader.defaultProps = {
logoDestination: null,
avatar: null,
username: null,
name: null,
loggedIn: false,
appMenu: null,
};
Expand Down
1 change: 1 addition & 0 deletions src/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const Header = ({ intl }) => {
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
loggedIn: authenticatedUser !== null,
username: authenticatedUser !== null ? authenticatedUser.username : null,
name: authenticatedUser !== null ? authenticatedUser.name : null,
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
mainMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : mainMenu,
userMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : userMenu,
Expand Down
5 changes: 4 additions & 1 deletion src/MobileHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class MobileHeader extends React.Component {
loggedIn,
avatar,
username,
name,
stickyOnMobile,
intl,
mainMenu,
Expand Down Expand Up @@ -139,7 +140,7 @@ class MobileHeader extends React.Component {
aria-label={intl.formatMessage(messages['header.label.account.menu'])}
title={intl.formatMessage(messages['header.label.account.menu'])}
>
<Avatar size="1.5rem" src={avatar} alt={username} />
<Avatar size="1.5rem" src={avatar} alt={name || username} />
</MenuTrigger>
<MenuContent tag="ul" className="nav flex-column pin-left pin-right border-top shadow py-2">
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
Expand Down Expand Up @@ -173,6 +174,7 @@ MobileHeader.propTypes = {
logoDestination: PropTypes.string,
avatar: PropTypes.string,
username: PropTypes.string,
name: PropTypes.string,
loggedIn: PropTypes.bool,
stickyOnMobile: PropTypes.bool,

Expand All @@ -189,6 +191,7 @@ MobileHeader.defaultProps = {
logoDestination: null,
avatar: null,
username: null,
name: null,
loggedIn: false,
stickyOnMobile: true,

Expand Down

0 comments on commit f7d9fb4

Please sign in to comment.