@@ -5,46 +5,40 @@ import PropTypes from 'prop-types';
5
5
import { useTranslation } from 'react-i18next' ;
6
6
import { Link , useLocation } from 'react-router-dom' ;
7
7
8
- /**
9
- * @description Secondary navigation component for the CleanAir site
10
- * @param {Array } disabledTabs
11
- * @returns {JSX.Element }
12
- */
13
8
const SecondaryNavComponent = ( { disabledTabs } ) => {
14
9
const { t } = useTranslation ( ) ;
15
10
const activeTab = useSelector ( ( state ) => state . cleanAirData . activeTab ) ;
16
11
const tabs = [
17
- t ( 'cleanAirSite.subNav.about' ) ,
18
- t ( 'cleanAirSite.subNav.membership' ) ,
19
- t ( 'cleanAirSite.subNav.events' ) ,
20
- t ( 'cleanAirSite.subNav.resources' )
12
+ { label : t ( 'cleanAirSite.subNav.about' ) , linkName : 'about' } ,
13
+ { label : t ( 'cleanAirSite.subNav.membership' ) , linkName : 'membership' } ,
14
+ { label : t ( 'cleanAirSite.subNav.events' ) , linkName : 'events' } ,
15
+ { label : t ( 'cleanAirSite.subNav.resources' ) , linkName : 'resources' }
21
16
] ;
17
+
22
18
const dispatch = useDispatch ( ) ;
23
19
const location = useLocation ( ) ;
24
-
25
20
useEffect ( ( ) => {
26
- dispatch ( setActiveTab ( tabs [ 0 ] ) ) ;
27
- const currentTab = tabs . findIndex ( ( tab ) => location . pathname . includes ( tab . toLowerCase ( ) ) ) ;
21
+ const currentTab = tabs . findIndex ( ( tab ) => location . pathname . includes ( tab . linkName ) ) ;
28
22
if ( currentTab !== - 1 && ! disabledTabs . includes ( currentTab ) ) {
29
23
dispatch ( setActiveTab ( tabs [ currentTab ] ) ) ;
30
24
}
31
- } , [ location , dispatch , tabs , disabledTabs ] ) ;
25
+ } , [ location ] ) ;
32
26
33
27
return (
34
28
< div className = "header-subnav" >
35
29
< ul className = "tabs" >
36
30
{ tabs . map ( ( tab , index ) => (
37
- < Link to = { `/clean-air/${ tab . toLowerCase ( ) } ` } key = { index } >
31
+ < Link to = { `/clean-air/${ tab . linkName } ` } key = { index } >
38
32
< li
39
33
className = { `${
40
- location . pathname . includes ( tab . toLowerCase ( ) ) || activeTab === tab ? 'active' : ''
34
+ location . pathname . includes ( tab . linkName ) || activeTab === index ? 'active' : ''
41
35
} ${ disabledTabs . includes ( index ) ? 'disabled' : '' } `}
42
36
onClick = { ( ) => {
43
37
if ( ! disabledTabs . includes ( index ) ) {
44
38
dispatch ( setActiveTab ( tab ) ) ;
45
39
}
46
40
} } >
47
- < span > { tab } </ span >
41
+ < span > { tab . label } </ span >
48
42
</ li >
49
43
</ Link >
50
44
) ) }
0 commit comments