-
Notifications
You must be signed in to change notification settings - Fork 792
/
protect.jsx
103 lines (94 loc) · 2.76 KB
/
protect.jsx
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import DashItem from 'components/dash-item';
import { numberFormat, translate as __ } from 'i18n-calypso';
/**
* Internal dependencies
*/
import QueryProtectCount from 'components/data/query-dash-protect';
import { isModuleAvailable } from 'state/modules';
import { getProtectCount } from 'state/at-a-glance';
import { isDevMode } from 'state/connection';
class DashProtect extends Component {
static propTypes = {
isDevMode: PropTypes.bool.isRequired,
protectCount: PropTypes.any.isRequired,
isModuleAvailable: PropTypes.bool.isRequired,
};
activateProtect() {
this.props.updateOptions( { protect: true } );
}
getContent() {
const support = {
text: __( 'Protects your site from traditional and distributed brute force login attacks.' ),
link: 'https://jetpack.com/support/protect/',
};
if ( this.props.getOptionValue( 'protect' ) ) {
const protectCount = this.props.protectCount;
if ( false === protectCount || '0' === protectCount || 'N/A' === protectCount ) {
return (
<DashItem
label="Protect"
module="protect"
support={ support }
status="is-working"
className="jp-dash-item__recently-activated"
>
<div className="jp-dash-item__recently-activated-lower">
<QueryProtectCount />
<p className="jp-dash-item__description">{ __( 'Jetpack is actively blocking malicious login attempts. Data will display here soon!' ) }</p>
</div>
</DashItem>
);
}
return (
<DashItem
label="Protect"
module="protect"
support={ support }
status="is-working"
>
<h2 className="jp-dash-item__count">{ numberFormat( protectCount ) }</h2>
<p className="jp-dash-item__description">{ __( 'Total malicious attacks blocked on your site.' ) }</p>
</DashItem>
);
}
return (
<DashItem
label="Protect"
module="protect"
support={ support }
className="jp-dash-item__is-inactive"
>
<p className="jp-dash-item__description">{
this.props.isDevMode ? __( 'Unavailable in Dev Mode' )
: __( '{{a}}Activate Protect{{/a}} to keep your site protected from malicious sign in attempts.', {
components: {
a: <a href="javascript:void(0)" onClick={ this.activateProtect } />
}
}
)
}</p>
</DashItem>
);
}
render() {
return this.props.isModuleAvailable && (
<div className="jp-dash-item__interior">
<QueryProtectCount />
{ this.getContent() }
</div>
);
}
}
export default connect(
state => ( {
protectCount: getProtectCount( state ),
isDevMode: isDevMode( state ),
isModuleAvailable: isModuleAvailable( state, 'protect' ),
} )
)( DashProtect );