1
1
/* global tcUniNav */
2
- import React , { useEffect , useRef , useState } from 'react' ;
2
+ import React , { useEffect , useRef } from 'react' ;
3
3
import PT from 'prop-types' ;
4
4
import { connect } from 'react-redux' ;
5
5
import { config } from 'topcoder-react-utils' ;
6
6
import _ from 'lodash' ;
7
7
import { getInitials , getSubPageConfiguration } from '../utils/url' ;
8
8
9
- let uniqueId = 0 ;
9
+ const headerElId = 'uninav-headerNav' ;
10
10
11
11
const TopcoderHeader = ( { auth } ) => {
12
12
const uniNavInitialized = useRef ( false ) ;
@@ -15,20 +15,14 @@ const TopcoderHeader = ({ auth }) => {
15
15
const isAuthenticated = ! ! authToken ;
16
16
const authURLs = config . HEADER_AUTH_URLS ;
17
17
const headerRef = useRef ( ) ;
18
- const [ headerId , setHeaderId ] = useState ( 0 ) ;
19
18
20
19
const navigationUserInfo = {
21
20
...user ,
22
21
initials : getInitials ( user . firstName , user . lastName ) ,
23
22
} ;
24
23
25
24
useEffect ( ( ) => {
26
- uniqueId += 1 ;
27
- setHeaderId ( uniqueId ) ;
28
- } , [ ] ) ;
29
-
30
- useEffect ( ( ) => {
31
- if ( uniNavInitialized . current || ! headerId ) {
25
+ if ( uniNavInitialized . current ) {
32
26
return ;
33
27
}
34
28
@@ -46,11 +40,10 @@ const TopcoderHeader = ({ auth }) => {
46
40
type = urlParams . get ( 'navTool' ) ;
47
41
}
48
42
49
- tcUniNav ( 'init' , `headerNav- ${ headerId } ` , {
43
+ tcUniNav ( 'init' , headerElId , {
50
44
type,
51
45
toolName : getSubPageConfiguration ( ) . toolName ,
52
46
toolRoot : getSubPageConfiguration ( ) . toolRoot ,
53
- user : isAuthenticated ? navigationUserInfo : null ,
54
47
signOut : ( ) => {
55
48
window . location = `${ config . URL . BASE } /logout?ref=nav` ;
56
49
} ,
@@ -61,9 +54,15 @@ const TopcoderHeader = ({ auth }) => {
61
54
window . location = `${ authURLs . location . replace ( '%S' , retUrl ) . replace ( 'member?' , '#!/member?' ) } &mode=signUp®Source=${ regSource } ` ;
62
55
} ,
63
56
} ) ;
64
- } , [ headerId ] ) ;
57
+ } , [ ] ) ;
58
+
59
+ useEffect ( ( ) => {
60
+ tcUniNav ( 'update' , headerElId , {
61
+ user : isAuthenticated ? navigationUserInfo : null ,
62
+ } ) ;
63
+ } , [ isAuthenticated , navigationUserInfo ] ) ;
65
64
66
- return < div id = { `headerNav- ${ headerId } ` } ref = { headerRef } /> ;
65
+ return < div id = { headerElId } ref = { headerRef } /> ;
67
66
} ;
68
67
69
68
TopcoderHeader . defaultProps = {
0 commit comments