@@ -15,7 +15,6 @@ import {
1515 MenuItem ,
1616 Select ,
1717 useTheme ,
18- Link ,
1918 Alert ,
2019 AlertTitle ,
2120} from '@mui/material' ;
@@ -43,11 +42,8 @@ import { defaultRemoteConfigValues } from '../interface/RemoteConfig';
4342import { animatedButtonStyling } from './Header.style' ;
4443import ThemeToggle from './ThemeToggle' ;
4544import { useTranslations , useLocale } from 'next-intl' ;
46- import { useSelector } from 'react-redux' ;
47- import {
48- selectIsAuthenticated ,
49- selectUserEmail ,
50- } from '../store/profile-selectors' ;
45+ import Link from 'next/link' ;
46+ import { app } from '../../firebase' ;
5147
5248// Lazy load components not needed for initial render
5349const LogoutConfirmModal = dynamic (
@@ -78,6 +74,9 @@ function useClientSearchParams(): URLSearchParams | null {
7874}
7975
8076export default function DrawerAppBar ( ) : React . ReactElement {
77+ const [ currentUser , setCurrentUser ] = React . useState <
78+ { email : string ; isAuthenticated : boolean } | undefined
79+ > ( undefined ) ;
8180 const clientSearchParams = useClientSearchParams ( ) ;
8281 const hasTransitFeedsRedirectParam =
8382 clientSearchParams ?. get ( 'utm_source' ) === 'transitfeeds' ;
@@ -96,6 +95,21 @@ export default function DrawerAppBar(): React.ReactElement {
9695 const { config } = useRemoteConfig ( ) ;
9796 const t = useTranslations ( 'common' ) ;
9897
98+ React . useEffect ( ( ) => {
99+ const auth = app . auth ( ) ;
100+ const unsubscribe = auth . onAuthStateChanged ( async ( user ) => {
101+ if ( user ) {
102+ setCurrentUser ( {
103+ email : user . email || '' ,
104+ isAuthenticated : ! user . isAnonymous ,
105+ } ) ;
106+ } else {
107+ setCurrentUser ( undefined ) ;
108+ }
109+ } ) ;
110+ return ( ) => unsubscribe ( ) ;
111+ } , [ ] ) ;
112+
99113 React . useEffect ( ( ) => {
100114 if ( hasTransitFeedsRedirectParam ) {
101115 setHasTransitFeedsRedirect ( true ) ;
@@ -111,8 +125,10 @@ export default function DrawerAppBar(): React.ReactElement {
111125 } , [ config ] ) ;
112126
113127 const router = useRouter ( ) ;
114- const isAuthenticated = useSelector ( selectIsAuthenticated ) ;
115- const userEmail = useSelector ( selectUserEmail ) ;
128+
129+ const isAuthenticated =
130+ currentUser != null && currentUser . isAuthenticated === true ;
131+ const userEmail = currentUser ?. email ;
116132
117133 const handleDrawerToggle = ( ) : void => {
118134 setMobileOpen ( ( prevState ) => ! prevState ) ;
@@ -184,7 +200,7 @@ export default function DrawerAppBar(): React.ReactElement {
184200 >
185201 < MenuIcon />
186202 </ IconButton >
187- < a
203+ < Link
188204 href = { '/' }
189205 style = { {
190206 textDecoration : 'none' ,
@@ -213,28 +229,34 @@ export default function DrawerAppBar(): React.ReactElement {
213229 >
214230 Mobility Database
215231 </ Typography >
216- </ a >
232+ </ Link >
217233 </ Box >
218234
219235 < Box sx = { { display : { xs : 'none' , md : 'block' } } } >
220236 { navigationItems . map ( ( item ) => (
221- < Button
222- sx = { ( theme ) => ( {
223- ...animatedButtonStyling ( theme ) ,
224- color : theme . palette . text . primary ,
225- } ) }
237+ < Link
238+ data-cy = {
239+ 'header-' + item . title . toLowerCase ( ) . replace ( / \s + / g, '-' )
240+ }
226241 href = { item . external === true ? item . target : '/' + item . target }
227242 key = { item . title }
228243 target = { item . external === true ? '_blank' : '_self' }
229244 rel = { item . external === true ? 'noopener noreferrer' : '' }
230- variant = { 'text' }
231- endIcon = { item . external === true ? < OpenInNew /> : null }
232- className = {
233- activeTab . includes ( '/' + item . target ) ? 'active' : ''
234- }
235245 >
236- { item . title }
237- </ Button >
246+ < Button
247+ sx = { ( theme ) => ( {
248+ ...animatedButtonStyling ( theme ) ,
249+ color : theme . palette . text . primary ,
250+ } ) }
251+ variant = { 'text' }
252+ endIcon = { item . external === true ? < OpenInNew /> : null }
253+ className = {
254+ activeTab . includes ( '/' + item . target ) ? 'active' : ''
255+ }
256+ >
257+ { item . title }
258+ </ Button >
259+ </ Link >
238260 ) ) }
239261 { config . gbfsValidator && (
240262 < >
@@ -383,6 +405,7 @@ export default function DrawerAppBar(): React.ReactElement {
383405 onClose = { handleMenuClose }
384406 >
385407 < MenuItem
408+ data-cy = 'accountDetailsHeader'
386409 onClick = { ( ) => {
387410 handleMenuItemClick ( navigationAccountItem ) ;
388411 } }
@@ -495,6 +518,7 @@ export default function DrawerAppBar(): React.ReactElement {
495518 } }
496519 >
497520 < DrawerContent
521+ isAuthenticated = { isAuthenticated }
498522 onLogoutClick = { handleLogoutClick }
499523 navigationItems = { navigationItems }
500524 metricsOptionsEnabled = { metricsOptionsEnabled }
0 commit comments