-
Notifications
You must be signed in to change notification settings - Fork 2k
/
disconnect-jetpack-dialog.jsx
123 lines (106 loc) · 2.86 KB
/
disconnect-jetpack-dialog.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* External dependencies
*/
import page from 'page';
import React, { Component } from 'react';
import { translate } from 'i18n-calypso';
import { connect } from 'react-redux';
/**
* Internal dependencies
*/
import Dialog from 'components/dialog';
import SitesListActions from 'lib/sites-list/actions';
import { getSelectedSite } from 'state/ui/selectors';
import { recordGoogleEvent } from 'state/analytics/actions';
class DisconnectJetpackDialog extends Component {
constructor( props ) {
super( props );
this.state = {
showJetpackDisconnectDialog: false
};
this.open = this.open.bind( this );
this.close = this.close.bind( this );
this.disconnectJetpack = this.disconnectJetpack.bind( this );
}
open() {
this.setState( {
showJetpackDisconnectDialog: true
} );
}
close( action ) {
this.setState( {
showJetpackDisconnectDialog: false
} );
if ( action === 'continue' ) {
this.disconnectJetpack();
this.props.recordGoogleEvent( 'Jetpack', 'Clicked To Confirm Disconnect Jetpack Dialog' );
} else {
this.props.recordGoogleEvent( 'Jetpack', 'Clicked To Cancel Disconnect Jetpack Dialog' );
}
}
disconnectJetpack() {
const { site, selectedSite } = this.props;
// remove any error and completed notices
SitesListActions.removeSitesNotices( [ { status: 'error' }, { status: 'completed' } ] );
if ( site ) {
SitesListActions.disconnect( site );
if ( selectedSite.ID === site.ID && this.props.redirect ) {
page.redirect( this.props.redirect );
return;
}
} else if ( this.props.sites ) {
this.props.sites.getSelectedOrAllWithPlugins().forEach( siteItem => SitesListActions.disconnect( siteItem ) );
}
if ( selectedSite.ID === site.ID ) {
page.redirect( '/sites' );
}
}
renderInfo() {
const { site } = this.props;
if ( ! site ) {
return translate( 'Disconnecting Jetpack will remove access to WordPress.com features.', {
context: 'Jetpack: Warning message displayed prior to disconnecting multiple Jetpack Sites.'
} );
}
return translate( 'Disconnecting Jetpack will remove access to WordPress.com features for %(siteName)s.', {
args: {
siteName: site.name || site.title
},
context: 'Jetpack: Warning message displayed prior to disconnecting a Jetpack Site.'
} );
}
render() {
const deactivationButtons = [
{
action: 'cancel',
label: translate( 'Cancel' )
},
{
action: 'continue',
label: translate( 'Disconnect' ),
isPrimary: true
}
];
return (
<Dialog
isVisible={ this.state.showJetpackDisconnectDialog }
buttons={ deactivationButtons }
onClose={ this.close }>
<h1>{ translate( 'Disconnect Jetpack' ) }</h1>
<p>{ this.renderInfo() }</p>
</Dialog>
);
}
}
export default connect(
state => ( {
selectedSite: getSelectedSite( state )
} ),
{
recordGoogleEvent
},
null,
{
withRef: true
}
)( DisconnectJetpackDialog );