11require ( './ProjectsToolBar.scss' )
2- /* global tcUniNav */
32import React , { Component } from 'react'
43import PropTypes from 'prop-types'
54import querystring from 'query-string'
@@ -15,27 +14,16 @@ import { loadProjectsMetadata } from '../../actions/templates'
1514import { getNewProjectLink } from '../../helpers/projectHelper'
1615import { hasPermission } from '../../helpers/permissions'
1716import { PERMISSIONS } from '../../config/permissions'
18- import { HEADER_AUTH_URLS_HREF , HEADER_AUTH_URLS_LOCATION , DOMAIN } from '../../config/constants'
19- import { getInitials } from '../../helpers/format'
20-
21- const HEADER_AUTH_URLS = {
22- href : HEADER_AUTH_URLS_HREF ,
23- location : HEADER_AUTH_URLS_LOCATION
24- }
25- const BASE = `https://www.${ DOMAIN } `
26-
27- let uniqueId = 0
17+ import NavBar from './NavBar'
2818
2919class ProjectsToolBar extends Component {
3020
3121 constructor ( props ) {
3222 super ( props )
33- uniqueId += 1
3423 this . state = {
3524 errorCreatingProject : false ,
3625 isMobileMenuOpen : false ,
37- isMobileSearchVisible : false ,
38- headerId : uniqueId ,
26+ isMobileSearchVisible : false
3927 }
4028 this . applyFilters = this . applyFilters . bind ( this )
4129 this . handleTermChange = this . handleTermChange . bind ( this )
@@ -83,43 +71,6 @@ class ProjectsToolBar extends Component {
8371 window . addEventListener ( 'beforeunload' , this . onLeave )
8472 }
8573
86- componentDidUpdate ( ) {
87- if ( ! ! this . state . headerId && ! this . uniNavInitialized ) {
88- const user = this . props . user
89- const navigationUserInfo = {
90- ...user ,
91- initials : getInitials ( user . firstName , user . lastName )
92- }
93- const authToken = user ? user . token : null
94- this . uniNavInitialized = true
95- const headerId = this . state . headerId
96- const isAuthenticated = ! ! authToken
97- const authURLs = HEADER_AUTH_URLS
98-
99- const regSource = window . location . pathname . split ( '/' ) [ 1 ]
100- const retUrl = encodeURIComponent ( window . location . href )
101- tcUniNav ( 'init' , `headerNav-${ headerId } ` , {
102- type : 'tool' ,
103- toolName : 'Connect' ,
104- toolRoot : '/' ,
105- user : isAuthenticated ? navigationUserInfo : null ,
106- signOut : ( ) => {
107- window . location = `${ BASE } /logout?ref=nav`
108- } ,
109- signIn : ( ) => {
110- window . location = `${ authURLs . location
111- . replace ( '%S' , retUrl )
112- . replace ( 'member?' , '#!/member?' ) } ®Source=${ regSource } `
113- } ,
114- signUp : ( ) => {
115- window . location = `${ authURLs . location
116- . replace ( '%S' , retUrl )
117- . replace ( 'member?' , '#!/member?' ) } &mode=signUp®Source=${ regSource } `
118- }
119- } )
120- }
121- }
122-
12374 componentWillUnmount ( ) {
12475 window . removeEventListener ( 'beforeunload' , this . onLeave )
12576 const contentDiv = document . getElementById ( 'wrapper-main' )
@@ -196,7 +147,7 @@ class ProjectsToolBar extends Component {
196147
197148 render ( ) {
198149 const { userRoles, user, mobileMenu, orgConfig } = this . props
199- const { isMobileMenuOpen, isMobileSearchVisible, headerId } = this . state
150+ const { isMobileMenuOpen, isMobileSearchVisible } = this . state
200151 const isLoggedIn = ! ! ( userRoles && userRoles . length )
201152
202153 const onLeaveMessage = this . onLeave ( ) || ''
@@ -207,11 +158,11 @@ class ProjectsToolBar extends Component {
207158 when = { ! ! onLeaveMessage }
208159 message = { onLeaveMessage }
209160 />
210- < div id = { `headerNav- ${ headerId } ` } />
211- < div className = "primary-toolbar" >
212- { isLoggedIn && ! hasPermission ( PERMISSIONS . SEARCH_PROJECTS ) && < div className = "projects-title-mobile" > MY PROJECTS</ div > }
161+ < NavBar user = { user } />
162+ { isLoggedIn ? ( < div className = "primary-toolbar" >
163+ { ! hasPermission ( PERMISSIONS . SEARCH_PROJECTS ) && < div className = "projects-title-mobile" > MY PROJECTS</ div > }
213164 {
214- isLoggedIn && hasPermission ( PERMISSIONS . SEARCH_PROJECTS ) &&
165+ hasPermission ( PERMISSIONS . SEARCH_PROJECTS ) &&
215166 < div className = "search-widget" >
216167 < SearchBar
217168 hideSuggestionsWhenEmpty
@@ -224,10 +175,10 @@ class ProjectsToolBar extends Component {
224175 </ div >
225176 }
226177 < div className = "actions" >
227- { isLoggedIn && < NewProjectNavLink link = { getNewProjectLink ( orgConfig ) } /> }
228- { isLoggedIn && < MobileMenuToggle onToggle = { this . toggleMobileMenu } /> }
178+ < NewProjectNavLink link = { getNewProjectLink ( orgConfig ) } />
179+ < MobileMenuToggle onToggle = { this . toggleMobileMenu } />
229180 </ div >
230- </ div >
181+ </ div > ) : null }
231182 { isMobileSearchVisible && isLoggedIn &&
232183 < div className = "secondary-toolbar" >
233184 < SearchBar
@@ -248,6 +199,7 @@ class ProjectsToolBar extends Component {
248199
249200ProjectsToolBar . propTypes = {
250201 criteria : PropTypes . object . isRequired ,
202+ user : PropTypes . object ,
251203 /**
252204 * Function which render the logo section in the top bar
253205 */
0 commit comments