1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { ChangeDetectorRef, Component, Input, OnInit, computed, signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatListModule } from '@angular/material/list';
import { MatIconModule } from '@angular/material/icon';
import { RouterModule } from '@angular/router';
import { JwtDecoderService } from '../../jwt-decoder.service';
import { AuthService } from '../../auth.service';
import { jwtDecode } from 'jwt-decode';
export type MenuItem = {
icon: string;
label: string;
route?: string;
role?:string;
}
@Component({
selector: 'app-custom-sidenav',
standalone: true,
imports: [CommonModule, MatListModule, MatIconModule, RouterModule],
templateUrl: './custom-sidenav.component.html',
styleUrls: ['./custom-sidenav.component.scss']
})
export class CustomSidenavComponent implements OnInit{
user: any;
sidenavWidth = '250px';
authTokenPresent = false;
constructor(
private jwtDecoderService: JwtDecoderService,
private authService: AuthService,
private cdr: ChangeDetectorRef
) {}
ngOnInit() {
this.authService.authToken$.subscribe(isLoggedIn => {
this.authTokenPresent = isLoggedIn;
if (this.authTokenPresent) {
const token = sessionStorage.getItem('accessToken')!;
this.user = jwtDecode(token);
const isExpired =
this.user && this.user.exp? this.user.exp < Date.now()/1000:false
if(isExpired){
sessionStorage.removeItem('accessToken');
}
this.user = this.jwtDecoderService.decodeToken(token);
console.log(this.user);
}
this.cdr.detectChanges();
});
}
sideNavCollapsed = signal(false);
@Input() set collapsed(val: boolean) {
this.sideNavCollapsed.set(val);
}
menuItems = signal<MenuItem[]>([
{
icon: 'dashboard',
label: 'Dashboard',
route: 'dashboard',
role: 'COMPANY',
},
{
icon: 'directions_boat',
label: 'Navios',
route: 'navio',
role: 'CANDIDATE',
},
{
icon: 'calendar_today',
label: 'Aceites',
route: 'aceite',
role: 'CANDIDATE'
},
{
icon: 'dock',
label: 'Berços',
route: 'berco',
role: 'CANDIDATE'
},
{
icon:'block',
label:'Black List',
route:'black-list',
role:'COMPANY'
},
{
icon: 'groups',
label: 'Usuários',
route: 'users',
role: 'COMPANY'
}
]);
profilePicSize = computed(() => (this.sideNavCollapsed() ? '32' : '100'));
}