1
1
import React from "react" ;
2
2
import { Link } from "react-router-dom" ;
3
3
4
+ import useCurrentUser from "./hooks/useCurrentUser" ;
5
+
4
6
import playerSvg from "./assets/icons/player.svg" ;
5
7
import skull from "./assets/icons/skull.svg" ;
6
8
import sword from "./assets/icons/sword.svg" ;
@@ -12,30 +14,34 @@ interface GamesHQRouteOption {
12
14
name : string ;
13
15
icon : string ;
14
16
to : string ;
17
+ necessaryCapability : string ;
15
18
}
16
19
export const AppMenu = ( { children } : { children : JSX . Element } ) => {
20
+ const { currentUser } = useCurrentUser ( ) ;
21
+
17
22
const inspectRoutes = [
18
- { name : "Inspect Arena" , to : "/inspect/arena" , icon : playerSvg } ,
23
+ { name : "Inspect Arena" , to : "/inspect/arena" , icon : playerSvg , necessaryCapability : "THE_ARENA_READ" } ,
19
24
] ;
20
25
21
26
const databaseRoutes = [
22
27
/* { name: "Players", to: "/players", icon: playerSvg }, */
23
- { name : "Weapons" , to : "/weapons" , icon : sword } ,
28
+ { name : "Weapons" , to : "/weapons" , icon : sword , necessaryCapability : "WEAPONS_READ" } ,
24
29
/* { name: "Traits", to: "/traits", icon: trait }, */
25
30
] ;
26
31
27
32
const towerRoutes = [
28
- { name : "Tower Game" , to : "/tower/status" , icon : playerSvg } ,
29
- { name : "Enemies" , to : "/enemies" , icon : skull } ,
30
- { name : "Floors" , to : "/floors" , icon : floor } ,
33
+ { name : "Tower Game" , to : "/tower/status" , icon : playerSvg , necessaryCapability : "THE_TOWER_READ" } ,
34
+ { name : "Enemies" , to : "/enemies" , icon : skull , necessaryCapability : "ENEMY_READ" } ,
35
+ { name : "Floors" , to : "/floors" , icon : floor , necessaryCapability : "THE_TOWER_READ" } ,
31
36
] ;
32
37
33
- const arenaRoutes = [ { name : "Zones" , to : "/zones" , icon : zone } ] ;
38
+ const arenaRoutes = [ { name : "Zones" , to : "/zones" , icon : zone , necessaryCapability : "ZONE_READ" } ] ;
34
39
35
- const gameDevRoutes = [ { name : "Games" , to : "/games" , icon : games } ] ;
40
+ const gameDevRoutes = [ { name : "Games" , to : "/games" , icon : games , necessaryCapability : "MY_GAME_READ" } ] ;
36
41
37
42
const generateRouteList = ( route : GamesHQRouteOption [ ] ) => {
38
- return route . map ( ( route , i ) => (
43
+
44
+ return route . map ( ( route , i ) => ( route . necessaryCapability && currentUser ?. capabilities . includes ( route . necessaryCapability ) &&
39
45
< ul className = "pt-4" key = { i } >
40
46
< Link to = { route . to } className = "items-center" >
41
47
< li className = "flex text-gray-400 hover:text-gray-700 items-center" >
@@ -46,6 +52,7 @@ export const AppMenu = ({ children }: { children: JSX.Element }) => {
46
52
</ ul >
47
53
) ) ;
48
54
} ;
55
+
49
56
return (
50
57
< div className = "flex h-screen bg-white" >
51
58
< nav className = "w-80 font-medium text-base bg-gray-50 h-full py-4" >
@@ -54,34 +61,48 @@ export const AppMenu = ({ children }: { children: JSX.Element }) => {
54
61
</ div >
55
62
< div className = "px-8 flex-col flex" >
56
63
< span className = "pt-4" />
57
- < span className = "uppercase py-1 text-xs text-gray-400 font-semibold" >
58
- MY GAMES
59
- </ span >
60
-
61
- { generateRouteList ( gameDevRoutes ) }
62
-
63
- < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
64
- INSPECT LIVE GAMES
65
- </ span >
66
-
67
- { generateRouteList ( inspectRoutes ) }
64
+ { currentUser ?. capabilities . includes ( 'MY_GAME_READ' ) && (
65
+ < >
66
+ < span className = "uppercase py-1 text-xs text-gray-400 font-semibold" >
67
+ MY GAMES
68
+ </ span >
69
+
70
+ { generateRouteList ( gameDevRoutes ) }
71
+
72
+ < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
73
+ INSPECT LIVE GAMES
74
+ </ span >
75
+
76
+ { generateRouteList ( inspectRoutes ) }
77
+ </ >
68
78
69
- < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
70
- GENERAL
71
- </ span >
79
+ ) }
80
+
81
+ { currentUser ?. capabilities . includes ( 'WEAPONS_READ' ) && (
82
+ < >
83
+ < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
84
+ GENERAL
85
+ </ span >
72
86
73
- { generateRouteList ( databaseRoutes ) }
87
+ { generateRouteList ( databaseRoutes ) }
88
+ </ >
89
+ ) }
74
90
75
91
< span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
76
92
THE TOWER
77
93
</ span >
78
94
79
95
{ generateRouteList ( towerRoutes ) }
80
- < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
81
- THE ARENA
82
- </ span >
83
96
84
- { generateRouteList ( arenaRoutes ) }
97
+ { currentUser ?. capabilities . includes ( 'THE_ARENA_READ' ) && (
98
+ < >
99
+ < span className = "uppercase py-1 text-xs text-gray-400 font-semibold mt-12" >
100
+ THE ARENA
101
+ </ span >
102
+
103
+ { generateRouteList ( arenaRoutes ) }
104
+ </ >
105
+ ) }
85
106
</ div >
86
107
</ nav >
87
108
< div className = "w-full min-w-0 px-16 py-8" > { children } </ div >
0 commit comments