File size: 1,445 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
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import getUserSettings from 'calypso/state/selectors/get-user-settings';
import hasUserSettings from 'calypso/state/selectors/has-user-settings';
import { getOKIcon, getWarningIcon } from './icons.js';
import SecurityCheckupNavigationItem from './navigation-item';

class SecurityCheckupPassword extends Component {
	static propTypes = {
		translate: PropTypes.func.isRequired,
	};

	getDescriptionAndIcon() {
		const { translate, userSettings } = this.props;

		if ( userSettings.is_passwordless_user ) {
			return {
				description: translate( 'You don’t have a password set.' ),
				materialIcon: getWarningIcon(),
			};
		}

		return {
			description: translate( 'You have a password set, but you can change it at any time.' ),
			materialIcon: getOKIcon(),
		};
	}

	render() {
		const { translate, areUserSettingsLoaded } = this.props;

		if ( ! areUserSettingsLoaded ) {
			return <SecurityCheckupNavigationItem isPlaceholder />;
		}

		return (
			<SecurityCheckupNavigationItem
				{ ...this.getDescriptionAndIcon() }
				path="/me/security/password"
				text={ translate( 'Password' ) }
			/>
		);
	}
}

export default connect( ( state ) => ( {
	areUserSettingsLoaded: hasUserSettings( state ),
	userSettings: getUserSettings( state ),
} ) )( localize( SecurityCheckupPassword ) );