File tree Expand file tree Collapse file tree 4 files changed +67
-10
lines changed Expand file tree Collapse file tree 4 files changed +67
-10
lines changed Original file line number Diff line number Diff line change 20
20
"
21
21
>
22
22
<v-btn
23
- v-for =" link in links"
24
- :key =" link.label"
23
+ v-for =" route in $router.options.routes.filter(
24
+ (r) =>
25
+ r.meta &&
26
+ r.meta.showInNav &&
27
+ r.meta.showInNav.some(
28
+ (role) => authenticatedUser.roles.map(r => r.id).includes(role)
29
+ )
30
+ )"
31
+ :key =" route.name"
25
32
text
26
- :to =" { name: link.label }"
33
+ :to =" { name: route.name }"
27
34
active-class =" primary--text"
28
- >{{ link.label }}</v-btn
35
+ >{{ route.name }}</v-btn
29
36
>
30
37
</div >
31
38
@@ -157,10 +164,10 @@ export default Vue.extend({
157
164
if (storedUser ) {
158
165
this .$store .commit (" SET_AUTHENTICATED_USER" , {
159
166
user: JSON .parse (storedUser ),
160
- });
161
- }
162
- // Refresh user data in case of an update
163
- this .$store .dispatch (" getAuthenticatedUser" );
167
+ });
168
+ }
169
+ // Refresh user data in case of an update
170
+ this .$store .dispatch (" getAuthenticatedUser" );
164
171
},
165
172
methods: {
166
173
signOut() {
Original file line number Diff line number Diff line change @@ -5,13 +5,16 @@ import Home from '../views/Home.vue'
5
5
import SignIn from '../views/SignIn.vue'
6
6
import SignUp from '../views/SignUp.vue'
7
7
import Clock from '../views/Clock.vue'
8
+ import Approvals from '../views/Approvals.vue'
8
9
import Availability from '../views/Availability.vue'
9
10
import Schedule from '../views/Schedule.vue'
10
11
import Messages from '../views/messages/Messages.vue'
11
12
import Conversation from '../views/messages/Conversation.vue'
12
13
13
14
Vue . use ( VueRouter )
14
15
16
+ const EMPLOYEE = 1 , MANAGER = 2
17
+
15
18
const routes = [
16
19
{
17
20
path : '/' ,
@@ -27,27 +30,47 @@ const routes = [
27
30
path : '/sign-up' ,
28
31
alias : '/confirmed' ,
29
32
name : 'signUp' ,
30
- component : SignUp
33
+ component : SignUp ,
31
34
} ,
32
35
{
33
36
path : '/clock' ,
34
37
name : 'clock' ,
35
38
component : Clock ,
39
+ meta : {
40
+ showInNav : [ EMPLOYEE ]
41
+ }
42
+ } ,
43
+ {
44
+ path : '/approvals' ,
45
+ name : 'approvals' ,
46
+ component : Approvals ,
47
+ meta : {
48
+ showInNav : [ MANAGER ]
49
+ }
36
50
} ,
37
51
{
38
52
path : '/availability' ,
39
53
name : 'availability' ,
40
54
component : Availability ,
55
+ meta : {
56
+ showInNav : [ EMPLOYEE , MANAGER ]
57
+ }
41
58
} ,
42
59
{
43
60
path : '/schedule' ,
44
61
name : 'schedule' ,
45
62
component : Schedule ,
63
+ meta : {
64
+ showInNav : [ EMPLOYEE , MANAGER ]
65
+ }
46
66
} ,
47
67
{
48
68
path : '/messages' ,
49
69
name : 'messages' ,
50
70
component : Messages ,
71
+ meta : {
72
+ showInNav : [ EMPLOYEE , MANAGER ]
73
+ } ,
51
74
children : [ {
52
75
name : 'conversation' ,
53
76
path : 'conversation/:conversationId' ,
@@ -62,4 +85,12 @@ const router = new VueRouter({
62
85
routes
63
86
} )
64
87
88
+ const userRole = 1
89
+
90
+ router . beforeEach ( ( to , from , next ) => {
91
+ if ( to . meta . showInNav && ! to . meta . showInNav . includes ( userRole ) )
92
+ next ( { name : 'home' } )
93
+ else next ( )
94
+ } )
95
+
65
96
export default router
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ axios.interceptors.response.use(response => {
248
248
console . log ( error . request )
249
249
250
250
// TODO: this is stupid, don't keep this. use custom axios config
251
- if ( error . request . responseURL == 'http://localhost:5000/api/ users/me' ) return
251
+ if ( error . request . responseURL == 'http://localhost:5000/users/me' ) return
252
252
253
253
if ( res . message || res . response . error ) {
254
254
message = res . message || res . response . error
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <v-container class =" home fill-height d-flex flex-column justify-center align-center" >
3
+ <h2 class =" text-h2 font-weight-bold mb-2" >Aprovals</h2 >
4
+ </v-container >
5
+ </template >
6
+
7
+ <script >
8
+ import { mapState , mapActions } from ' vuex'
9
+
10
+ export default {
11
+ name: ' approvals' ,
12
+ computed: {
13
+ ... mapState ([' authenticatedUser' ])
14
+ },
15
+ methods: {
16
+ ... mapActions ([' signOut' ])
17
+ }
18
+ }
19
+ </script >
You can’t perform that action at this time.
0 commit comments