@@ -38,6 +38,13 @@ class TabContainer extends Component {
3838 return ! ! resolvedToken && checkAdminOrTalentManager ( resolvedToken )
3939 }
4040
41+ getIsAdmin ( props = this . props ) {
42+ const { token : currentToken } = this . props
43+ const { token } = props
44+ const resolvedToken = token || currentToken
45+ return ! ! resolvedToken && checkAdmin ( resolvedToken )
46+ }
47+
4148 componentDidMount ( ) {
4249 const {
4350 projectId,
@@ -63,8 +70,9 @@ class TabContainer extends Component {
6370
6471 const canViewAssets = this . getCanViewAssets ( )
6572 const canViewEngagements = this . getCanViewEngagements ( )
73+ const isAdmin = this . getIsAdmin ( )
6674 this . setState ( {
67- currentTab : this . getTabFromPath ( history . location . pathname , projectId , canViewAssets , canViewEngagements )
75+ currentTab : this . getTabFromPath ( history . location . pathname , projectId , canViewAssets , canViewEngagements , isAdmin )
6876 } )
6977 }
7078
@@ -77,8 +85,9 @@ class TabContainer extends Component {
7785
7886 const canViewAssets = this . getCanViewAssets ( nextProps )
7987 const canViewEngagements = this . getCanViewEngagements ( nextProps )
88+ const isAdmin = this . getIsAdmin ( nextProps )
8089 this . setState ( {
81- currentTab : this . getTabFromPath ( nextProps . history . location . pathname , projectId , canViewAssets , canViewEngagements )
90+ currentTab : this . getTabFromPath ( nextProps . history . location . pathname , projectId , canViewAssets , canViewEngagements , isAdmin )
8291 } )
8392 if (
8493 isLoading ||
@@ -130,7 +139,7 @@ class TabContainer extends Component {
130139 return 0
131140 }
132141
133- getTabFromPath ( pathname , projectId , canViewAssets = true , canViewEngagements = false ) {
142+ getTabFromPath ( pathname , projectId , canViewAssets = true , canViewEngagements = false , isAdmin = false ) {
134143 if ( projectId ) {
135144 return this . getProjectTabFromPath ( pathname , projectId , canViewAssets , canViewEngagements )
136145 }
@@ -141,7 +150,7 @@ class TabContainer extends Component {
141150 return 2
142151 }
143152 if ( pathname === '/engagements' ) {
144- return canViewEngagements ? 3 : 0
153+ return isAdmin ? 3 : 0
145154 }
146155 if ( pathname === '/users' ) {
147156 return 4
@@ -178,7 +187,8 @@ class TabContainer extends Component {
178187 onTabChange ( tab ) {
179188 const { history, resetSidebarActiveParams, projectId } = this . props
180189 const canViewAssets = this . getCanViewAssets ( )
181- const canViewEngagements = this . getCanViewEngagements ( )
190+ const canViewEngagements = this . getCanViewEngagements ( ) // admin OR TM
191+ const isAdmin = this . getIsAdmin ( ) // admin
182192 if ( projectId ) {
183193 if ( ( tab === 2 && ! canViewEngagements ) || ( tab === 3 && ! canViewAssets ) ) {
184194 return
@@ -200,7 +210,7 @@ class TabContainer extends Component {
200210 history . push ( '/projects' )
201211 this . props . unloadProjects ( )
202212 this . setState ( { currentTab : 2 } )
203- } else if ( tab === 3 && canViewEngagements ) {
213+ } else if ( tab === 3 && isAdmin ) {
204214 history . push ( '/engagements' )
205215 this . setState ( { currentTab : 3 } )
206216 } else if ( tab === 4 ) {
@@ -225,6 +235,7 @@ class TabContainer extends Component {
225235 const { currentTab } = this . state
226236 const canViewAssets = this . getCanViewAssets ( )
227237 const canViewEngagements = this . getCanViewEngagements ( )
238+ const isAdmin = this . getIsAdmin ( )
228239
229240 return (
230241 < Tab
@@ -233,6 +244,7 @@ class TabContainer extends Component {
233244 projectId = { this . props . projectId }
234245 canViewAssets = { canViewAssets }
235246 canViewEngagements = { canViewEngagements }
247+ isAdmin = { isAdmin }
236248 onBack = { this . onBackToHome }
237249 />
238250 )
0 commit comments