File size: 1,875 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import i18n from 'i18n-calypso';
import { find } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import SectionNav from 'calypso/components/section-nav';
import NavItem from 'calypso/components/section-nav/item';
import NavTabs from 'calypso/components/section-nav/tabs';

export default class SecuritySectionNav extends Component {
	static propTypes = {
		path: PropTypes.string.isRequired,
	};

	getNavtabs = () => {
		return [
			{
				title: i18n.translate( 'Password' ),
				path: '/me/security',
			},
			{
				title: i18n.translate( 'Social Login' ),
				path: '/me/security/social-login',
			},
			{
				title: i18n.translate( 'Two-Step Authentication' ),
				path: '/me/security/two-step',
			},
			{
				title: i18n.translate( 'Connected Apps' ),
				path: '/me/security/connected-applications',
			},
			{
				title: i18n.translate( 'Account Recovery' ),
				path: '/me/security/account-recovery',
			},
		];
	};

	getFilteredPath = () => {
		const paramIndex = this.props.path.indexOf( '?' );
		return paramIndex < 0 ? this.props.path : this.props.path.substring( 0, paramIndex );
	};

	getSelectedText = () => {
		let text = '';
		const filteredPath = this.getFilteredPath();
		const found = find( this.getNavtabs(), { path: filteredPath } );

		if ( 'undefined' !== typeof found ) {
			text = String( found.title );
		}

		return text;
	};

	onClick = () => {
		window.scrollTo( 0, 0 );
	};

	render() {
		return (
			<SectionNav selectedText={ this.getSelectedText() }>
				<NavTabs>
					{ this.getNavtabs().map( function ( tab ) {
						return (
							<NavItem
								key={ tab.path }
								onClick={ this.onClick }
								path={ tab.path }
								selected={ tab.path === this.getFilteredPath() }
							>
								{ tab.title }
							</NavItem>
						);
					}, this ) }
				</NavTabs>
			</SectionNav>
		);
	}
}