Skip to content

Commit d77b798

Browse files
committed
show authenticated user in navbar
1 parent 2e5193b commit d77b798

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/app/layout/navbar/navbar.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class NavbarComponent implements OnInit {
1313
@Output() toggleChatEvent: EventEmitter<any> = new EventEmitter();
1414
$el: any;
1515
config: any;
16+
user: any = JSON.parse(localStorage.getItem('user')) || {};
1617

1718
constructor(
1819
el: ElementRef,
@@ -40,6 +41,10 @@ export class NavbarComponent implements OnInit {
4041
this.loginService.logoutUser();
4142
}
4243

44+
firstUserLetter() {
45+
return (this.user.name || this.user.email || 'P')[0].toUpperCase();
46+
}
47+
4348
ngOnInit(): void {
4449
setTimeout(() => {
4550
const $chatNotification = jQuery('#chat-notification');

src/app/layout/navbar/navbar.template.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@
5252
<li class="nav-item dropdown" dropdown placement="bottom right" [autoClose]="false">
5353
<a href="#" dropdownToggle class="nav-link dropdown-toggle dropdown-toggle-notifications"
5454
id="notifications-dropdown-toggle">
55-
<span class="avatar thumb-sm float-left mr-2">
56-
<img class="rounded-circle" src="assets/img/people/a5.jpg" alt="..." />
57-
</span>
58-
<span class="small">Philip <span class="fw-semi-bold">Smith</span></span>
59-
<span class="ml-1 circle bg-warning text-white fw-bold">13</span>
55+
<span class="avatar rounded-circle thumb-sm float-left mr-2">
56+
<img
57+
*ngIf="user.avatar || user.email === 'admin@flatlogic.com'; else firstLetter"
58+
class="rounded-circle"
59+
[src]="user.avatar || 'assets/img/people/a5.jpg'"
60+
alt="..."
61+
/>
62+
<ng-template #firstLetter>{{firstUserLetter}}</ng-template>
63+
</span>
64+
<span class="small">{{user.name || user.email || "Philip smith"}}</span>
65+
<span class="ml-1 circle bg-warning text-white fw-bold">13</span>
6066
</a>
6167
<!-- ready to use notifications dropdown. inspired by smartadmin template.
6268
consists of three components:

src/app/styles/_base.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ app, .app {
9494
}
9595

9696
.avatar{
97-
width: 30px;
97+
display: flex;
98+
align-items: center;
99+
justify-content: center;
100+
overflow: hidden;
101+
height: 40px;
102+
width: 40px;
103+
background: #ffc247;
104+
font-weight: 600;
105+
font-size: 18px;
98106
}
99107

100108
.navbar-nav {

0 commit comments

Comments
 (0)