Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

feat(navbar): display currently logged in user name #2236

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions src/__tests__/shared/components/navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,22 @@ describe('Navbar', () => {
})

describe('account', () => {
it('should render an account link list', () => {
it("should render a link with the user's identification", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a test to make sure that it renders the user's first and last name

const wrapper = setup(allPermissions)
const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)
const accountLinkList = hospitalRunNavbar.find('.nav-account')
const { children } = accountLinkList.first().props() as any

expect(children[0].props.children).toEqual([undefined, 'settings.label'])
expect(children[0].props.children).not.toBeUndefined()
})

it('should render a setting link list', () => {
const wrapper = setup(allPermissions)
const hospitalRunNavbar = wrapper.find(HospitalRunNavbar)
const accountLinkList = hospitalRunNavbar.find('.nav-account')
const { children } = accountLinkList.first().props() as any

expect(children[1].props.children).toEqual([undefined, 'settings.label'])
})

it('should navigate to /settings when the list option is selected', () => {
Expand All @@ -187,6 +196,7 @@ describe('Navbar', () => {

act(() => {
children[0].props.onClick()
children[1].props.onClick()
})

expect(history.location.pathname).toEqual('/settings')
Expand Down
9 changes: 8 additions & 1 deletion src/shared/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Navbar = () => {
const dispatch = useDispatch()
const history = useHistory()
const { t } = useTranslator()
const { permissions } = useSelector((state: RootState) => state.user)
const { permissions, user } = useSelector((state: RootState) => state.user)

const navigateTo = (location: string) => {
history.push(location)
Expand Down Expand Up @@ -98,6 +98,13 @@ const Navbar = () => {
type: 'link-list-icon',
alignRight: true,
children: [
{
type: 'link',
label: `${t('user.login.success')}${user?.givenName} ${user?.familyName}`,
jackcmeyer marked this conversation as resolved.
Show resolved Hide resolved
onClick: () => {
navigateTo('/settings')
},
},
{
type: 'link',
label: t('settings.label'),
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/enUs/translations/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
required: 'Password is required.',
},
},
success: 'Currently signed in as ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use currentlySignedInAs as the key instead of success. I think that it makes it more clear what the key is supposed to represent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave off the trailing space in the key and make whoever uses this key put a space in.

},
},
}