14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { Component } from 'react' ;
17
+ import React , { useEffect } from 'react' ;
18
18
import PropTypes from 'prop-types' ;
19
19
import { connect } from 'react-redux' ;
20
20
import { defineMessages , injectIntl } from 'react-intl' ;
21
+ import { useTracking } from 'react-tracking' ;
21
22
import { SERVER_SETTINGS_TAB_PAGE , settingsTabSelector } from 'controllers/pages' ;
22
23
import {
23
24
AUTHORIZATION_CONFIGURATION ,
24
25
ANALYTICS ,
25
26
LINKS_AND_BRANDING ,
26
27
} from 'common/constants/settingsTabs' ;
27
28
import { NavigationTabs } from 'components/main/navigationTabs' ;
28
- import { ADMIN_SERVER_SETTINGS_PAGE_EVENTS } from 'components/main/analytics/events' ;
29
+ import {
30
+ getServerSettingsPageViewEvent ,
31
+ ADMIN_SERVER_SETTINGS_PAGE_EVENTS ,
32
+ } from 'components/main/analytics/events/adminServerSettingsPageEvents' ;
29
33
import { AuthConfigurationTab } from './authConfigurationTab' ;
30
34
import { AnalyticsTab } from './analyticsTab' ;
31
35
import { LinksAndBrandingTab } from './linksAndBrandingTab' ;
@@ -45,61 +49,68 @@ const messages = defineMessages({
45
49
} ,
46
50
} ) ;
47
51
48
- @connect (
49
- ( state ) => ( {
50
- activeTab : settingsTabSelector ( state ) ,
51
- } ) ,
52
- {
53
- onChangeTab : ( linkAction ) => linkAction ,
54
- } ,
55
- )
56
- @injectIntl
57
- export class ServerSettingsTabs extends Component {
58
- static propTypes = {
59
- intl : PropTypes . object . isRequired ,
60
- activeTab : PropTypes . string ,
61
- onChangeTab : PropTypes . func ,
62
- } ;
63
- static defaultProps = {
64
- activeTab : AUTHORIZATION_CONFIGURATION ,
65
- onChangeTab : ( ) => { } ,
66
- } ;
52
+ const ServerSettingsTabs = ( { activeTab, onChangeTab, intl } ) => {
53
+ const { trackEvent } = useTracking ( ) ;
54
+
55
+ useEffect ( ( ) => {
56
+ if ( activeTab ) {
57
+ trackEvent ( getServerSettingsPageViewEvent ( activeTab ) ) ;
58
+ }
59
+ } , [ activeTab , trackEvent ] ) ;
67
60
68
- createTabLink = ( tabName ) => ( {
61
+ const createTabLink = ( tabName ) => ( {
69
62
type : SERVER_SETTINGS_TAB_PAGE ,
70
63
payload : { settingsTab : tabName } ,
71
64
} ) ;
72
65
73
- createTabsConfig = ( ) => ( {
66
+ const createTabsConfig = ( ) => ( {
74
67
[ AUTHORIZATION_CONFIGURATION ] : {
75
- name : this . props . intl . formatMessage ( messages . authConfiguration ) ,
76
- link : this . createTabLink ( AUTHORIZATION_CONFIGURATION ) ,
68
+ name : intl . formatMessage ( messages . authConfiguration ) ,
69
+ link : createTabLink ( AUTHORIZATION_CONFIGURATION ) ,
77
70
component : < AuthConfigurationTab /> ,
78
71
mobileDisabled : true ,
79
72
eventInfo : ADMIN_SERVER_SETTINGS_PAGE_EVENTS . AUTHORIZATION_CONFIGURATION_TAB ,
80
73
} ,
81
74
[ ANALYTICS ] : {
82
- name : this . props . intl . formatMessage ( messages . statistics ) ,
83
- link : this . createTabLink ( ANALYTICS ) ,
75
+ name : intl . formatMessage ( messages . statistics ) ,
76
+ link : createTabLink ( ANALYTICS ) ,
84
77
component : < AnalyticsTab /> ,
85
78
mobileDisabled : true ,
86
79
eventInfo : ADMIN_SERVER_SETTINGS_PAGE_EVENTS . ANALYTICS_TAB ,
87
80
} ,
88
81
[ LINKS_AND_BRANDING ] : {
89
- name : this . props . intl . formatMessage ( messages . linksAndBranding ) ,
90
- link : this . createTabLink ( LINKS_AND_BRANDING ) ,
82
+ name : intl . formatMessage ( messages . linksAndBranding ) ,
83
+ link : createTabLink ( LINKS_AND_BRANDING ) ,
91
84
component : < LinksAndBrandingTab /> ,
92
85
mobileDisabled : true ,
93
86
eventInfo : ADMIN_SERVER_SETTINGS_PAGE_EVENTS . LINKS_AND_BRANDING_TAB ,
94
87
} ,
95
88
} ) ;
96
89
97
- render = ( ) => (
90
+ return (
98
91
< NavigationTabs
99
- config = { this . createTabsConfig ( ) }
100
- activeTab = { this . props . activeTab }
101
- onChangeTab = { this . props . onChangeTab }
92
+ config = { createTabsConfig ( ) }
93
+ activeTab = { activeTab }
94
+ onChangeTab = { onChangeTab }
102
95
mobileDisabled
103
96
/>
104
97
) ;
105
- }
98
+ } ;
99
+ ServerSettingsTabs . propTypes = {
100
+ intl : PropTypes . object . isRequired ,
101
+ activeTab : PropTypes . string ,
102
+ onChangeTab : PropTypes . func ,
103
+ } ;
104
+ ServerSettingsTabs . defaultProps = {
105
+ activeTab : AUTHORIZATION_CONFIGURATION ,
106
+ onChangeTab : ( ) => { } ,
107
+ } ;
108
+
109
+ export const ServerSettingsTabsWrapper = connect (
110
+ ( state ) => ( {
111
+ activeTab : settingsTabSelector ( state ) ,
112
+ } ) ,
113
+ {
114
+ onChangeTab : ( linkAction ) => linkAction ,
115
+ } ,
116
+ ) ( injectIntl ( ServerSettingsTabs ) ) ;
0 commit comments