11/* global tcUniNav */
2- import React , { useEffect , useRef , useState } from 'react' ;
2+ import React , { useEffect , useRef } from 'react' ;
33import PT from 'prop-types' ;
44import { connect } from 'react-redux' ;
55import { config } from 'topcoder-react-utils' ;
66import _ from 'lodash' ;
77import { getInitials , getSubPageConfiguration } from '../utils/url' ;
88
9- let uniqueId = 0 ;
9+ const headerElId = 'uninav-headerNav' ;
1010
1111const TopcoderHeader = ( { auth } ) => {
1212 const uniNavInitialized = useRef ( false ) ;
@@ -15,20 +15,14 @@ const TopcoderHeader = ({ auth }) => {
1515 const isAuthenticated = ! ! authToken ;
1616 const authURLs = config . HEADER_AUTH_URLS ;
1717 const headerRef = useRef ( ) ;
18- const [ headerId , setHeaderId ] = useState ( 0 ) ;
1918
2019 const navigationUserInfo = {
2120 ...user ,
2221 initials : getInitials ( user . firstName , user . lastName ) ,
2322 } ;
2423
2524 useEffect ( ( ) => {
26- uniqueId += 1 ;
27- setHeaderId ( uniqueId ) ;
28- } , [ ] ) ;
29-
30- useEffect ( ( ) => {
31- if ( uniNavInitialized . current || ! headerId ) {
25+ if ( uniNavInitialized . current ) {
3226 return ;
3327 }
3428
@@ -46,11 +40,10 @@ const TopcoderHeader = ({ auth }) => {
4640 type = urlParams . get ( 'navTool' ) ;
4741 }
4842
49- tcUniNav ( 'init' , `headerNav- ${ headerId } ` , {
43+ tcUniNav ( 'init' , headerElId , {
5044 type,
5145 toolName : getSubPageConfiguration ( ) . toolName ,
5246 toolRoot : getSubPageConfiguration ( ) . toolRoot ,
53- user : isAuthenticated ? navigationUserInfo : null ,
5447 signOut : ( ) => {
5548 window . location = `${ config . URL . BASE } /logout?ref=nav` ;
5649 } ,
@@ -61,9 +54,15 @@ const TopcoderHeader = ({ auth }) => {
6154 window . location = `${ authURLs . location . replace ( '%S' , retUrl ) . replace ( 'member?' , '#!/member?' ) } &mode=signUp®Source=${ regSource } ` ;
6255 } ,
6356 } ) ;
64- } , [ headerId ] ) ;
57+ } , [ ] ) ;
58+
59+ useEffect ( ( ) => {
60+ tcUniNav ( 'update' , headerElId , {
61+ user : isAuthenticated ? navigationUserInfo : null ,
62+ } ) ;
63+ } , [ isAuthenticated , navigationUserInfo ] ) ;
6564
66- return < div id = { `headerNav- ${ headerId } ` } ref = { headerRef } /> ;
65+ return < div id = { headerElId } ref = { headerRef } /> ;
6766} ;
6867
6968TopcoderHeader . defaultProps = {
0 commit comments