File size: 9,609 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 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
import {
WPCOM_FEATURES_ANTISPAM,
WPCOM_FEATURES_BACKUPS,
WPCOM_FEATURES_PRIORITY_SUPPORT,
WPCOM_FEATURES_REAL_TIME_BACKUPS,
WPCOM_FEATURES_SCAN,
WPCOM_FEATURES_SEO_PREVIEW_TOOLS,
WPCOM_FEATURES_VIDEO_HOSTING,
WPCOM_FEATURES_VIDEOPRESS_UNLIMITED_STORAGE,
} from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { Button, Card, Gridicon } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { connect } from 'react-redux';
import QueryRewindState from 'calypso/components/data/query-rewind-state';
import { recordGoogleEvent, recordTracksEvent } from 'calypso/state/analytics/actions';
import { disconnect } from 'calypso/state/jetpack/connection/actions';
import {
successNotice,
errorNotice,
infoNotice,
removeNotice,
} from 'calypso/state/notices/actions';
import getRewindState from 'calypso/state/selectors/get-rewind-state';
import siteHasFeature from 'calypso/state/selectors/site-has-feature';
import { getSiteSlug, getSiteTitle } from 'calypso/state/sites/selectors';
import { setAllSitesSelected } from 'calypso/state/ui/actions';
import './style.scss';
const noop = () => {};
class DisconnectJetpack extends PureComponent {
static propTypes = {
disconnectHref: PropTypes.string,
isBroken: PropTypes.bool,
onDisconnectClick: PropTypes.func,
onStayConnectedClick: PropTypes.func,
showTitle: PropTypes.bool,
siteId: PropTypes.number,
stayConnectedHref: PropTypes.string,
// Connected props
hasAntiSpam: PropTypes.bool,
hasDailyBackups: PropTypes.bool,
hasPrioritySupport: PropTypes.bool,
hasRealTimeBackups: PropTypes.bool,
hasScan: PropTypes.bool,
hasSeoPreviewTools: PropTypes.bool,
hasVideoHosting: PropTypes.bool,
hasVideoPressUnlimitedStorage: PropTypes.bool,
siteSlug: PropTypes.string,
siteTitle: PropTypes.string,
setAllSitesSelected: PropTypes.func,
recordGoogleEvent: PropTypes.func,
recordTracksEvent: PropTypes.func,
disconnect: PropTypes.func,
successNotice: PropTypes.func,
errorNotice: PropTypes.func,
infoNotice: PropTypes.func,
removeNotice: PropTypes.func,
rewindState: PropTypes.string.isRequired,
};
static defaultProps = {
showTitle: true,
onDisconnectClick: noop,
onStayConnectedClick: noop,
};
trackReadMoreClick = () => {
this.props.recordGoogleEvent(
'Disconnect Jetpack Dialog',
'Clicked Read More about Jetpack benefits'
);
};
getIcon( icon ) {
return { components: { icon: <Gridicon icon={ icon } /> } };
}
planFeatures() {
const { translate } = this.props;
const features = [];
if ( this.props.hasRealTimeBackups ) {
features.push(
translate(
'{{icon/}} Real-time automated backups (unlimited storage)',
this.getIcon( 'history' )
)
);
} else if ( this.props.hasDailyBackups ) {
features.push(
translate(
'{{icon/}} Daily automated backups (unlimited storage)',
this.getIcon( 'history' )
)
);
}
if ( this.props.hasScan ) {
features.push(
translate( '{{icon/}} Real-time automated malware scanning', this.getIcon( 'spam' ) )
);
}
if ( this.props.hasPrioritySupport ) {
features.push(
translate( '{{icon/}} Priority WordPress and security support', this.getIcon( 'chat' ) )
);
}
if ( this.props.hasVideoPressUnlimitedStorage ) {
features.push(
translate( '{{icon/}} Unlimited high-speed video hosting', this.getIcon( 'video' ) )
);
} else if ( this.props.hasVideoHosting ) {
features.push( translate( '{{icon/}} High-speed video hosting', this.getIcon( 'video' ) ) );
}
if ( this.props.hasSeoPreviewTools ) {
features.push( translate( '{{icon/}} SEO preview tools', this.getIcon( 'globe' ) ) );
}
if ( this.props.hasAntiSpam ) {
features.push( translate( '{{icon/}} Spam filtering', this.getIcon( 'spam' ) ) );
}
features.push(
translate(
'{{icon/}} Jetpack Stats, related content, and sharing tools',
this.getIcon( 'stats-alt' )
)
);
features.push(
translate(
'{{icon/}} Brute force attack protection and downtime monitoring',
this.getIcon( 'lock' )
)
);
features.push(
translate( '{{icon/}} Unlimited, high-speed image hosting', this.getIcon( 'image' ) )
);
// Show the top 5 features they'll miss out on.
return features.slice( 0, 5 ).map( ( feature, index ) => {
return (
<div key={ 'disconnect-jetpack__feature-' + index } className="disconnect-jetpack__feature">
{ feature }
</div>
);
} );
}
disconnectJetpack = () => {
const {
onDisconnectClick,
siteId,
siteTitle,
translate,
successNotice: showSuccessNotice,
errorNotice: showErrorNotice,
infoNotice: showInfoNotice,
removeNotice: removeInfoNotice,
disconnect: disconnectSite,
} = this.props;
onDisconnectClick();
this.props.recordTracksEvent( 'calypso_jetpack_disconnect_confirm' );
this.props.recordGoogleEvent( 'Jetpack', 'Clicked To Confirm Disconnect Jetpack Dialog' );
const { notice } = showInfoNotice(
translate( 'Disconnecting %(siteName)s.', { args: { siteName: siteTitle } } ),
{
isPersistent: true,
showDismiss: false,
}
);
disconnectSite( siteId ).then(
() => {
this.props.setAllSitesSelected();
removeInfoNotice( notice.noticeId );
showSuccessNotice(
translate( 'Successfully disconnected %(siteName)s.', { args: { siteName: siteTitle } } )
);
this.props.recordGoogleEvent( 'Jetpack', 'Successfully Disconnected' );
},
( err ) => {
removeInfoNotice( notice.noticeId );
const errorMessage =
( err && err.message ) ||
translate( '%(siteName)s failed to disconnect', { args: { siteName: siteTitle } } );
showErrorNotice( errorMessage );
this.props.recordGoogleEvent( 'Jetpack', 'Failed Disconnected Site' );
}
);
};
handleTryRewind = () => {
this.props.recordTracksEvent( 'calypso_disconnect_jetpack_try_rewind' );
page( `/activity-log/${ this.props.siteSlug }` );
};
render() {
const {
disconnectHref,
isBroken,
onStayConnectedClick,
showTitle,
siteSlug,
stayConnectedHref,
translate,
siteId,
rewindState,
} = this.props;
if ( isBroken ) {
return (
<Card className="disconnect-jetpack">
{ showTitle && <h1>{ translate( 'Disconnect Jetpack' ) }</h1> }
<p className="disconnect-jetpack__highlight">
{ translate( 'WordPress.com has not been able to reach %(siteSlug)s for a while.', {
args: { siteSlug },
} ) }
</p>
<div className="disconnect-jetpack__button-wrap">
<Button primary scary onClick={ this.disconnectJetpack }>
{ translate( 'Remove Site' ) }
</Button>
</div>
</Card>
);
}
return [
<Card key="disconnect-jetpack" className="disconnect-jetpack__block">
{ siteId && <QueryRewindState siteId={ siteId } /> }
{ showTitle && (
<h1 className="disconnect-jetpack__header">
{ translate( 'Disconnect from WordPress.com?' ) }
</h1>
) }
<p className="disconnect-jetpack__highlight">
{ translate(
'By disconnecting %(siteSlug)s from WordPress.com you will no longer have access to the following:',
{ args: { siteSlug } }
) }
</p>
{ this.planFeatures() }
<div className="disconnect-jetpack__button-wrap">
<Button href={ stayConnectedHref } onClick={ onStayConnectedClick }>
{ translate( 'Stay connected' ) }
</Button>
<Button primary scary href={ disconnectHref } onClick={ this.disconnectJetpack }>
{ translate( 'Disconnect', {
context: 'Jetpack: Action user takes to disconnect Jetpack site from .com',
} ) }
</Button>
</div>
<a
onClick={ this.trackReadMoreClick }
className="disconnect-jetpack__more-info-link"
href="https://jetpack.com/features/"
>
{ translate( 'Read more about Jetpack benefits' ) }
</a>
</Card>,
'active' === rewindState && (
<Card
key="disconnect-jetpack__try-rewind"
className="disconnect-jetpack__try-rewind disconnect-jetpack__block"
>
<p className="disconnect-jetpack__highlight">
{ translate( 'Experiencing connection issues? Try to go back and restore your site.' ) }
</p>
<div className="disconnect-jetpack__try-rewind-button-wrap">
<Button onClick={ this.handleTryRewind }>{ translate( 'Restore site' ) }</Button>
</div>
</Card>
),
];
}
}
export default connect(
( state, { siteId } ) => {
const rewindState = getRewindState( state, siteId );
return {
hasAntiSpam: siteHasFeature( state, siteId, WPCOM_FEATURES_ANTISPAM ),
hasDailyBackups: siteHasFeature( state, siteId, WPCOM_FEATURES_BACKUPS ),
hasPrioritySupport: siteHasFeature( state, siteId, WPCOM_FEATURES_PRIORITY_SUPPORT ),
hasRealTimeBackups: siteHasFeature( state, siteId, WPCOM_FEATURES_REAL_TIME_BACKUPS ),
hasScan: siteHasFeature( state, siteId, WPCOM_FEATURES_SCAN ),
hasSeoPreviewTools: siteHasFeature( state, siteId, WPCOM_FEATURES_SEO_PREVIEW_TOOLS ),
hasVideoHosting: siteHasFeature( state, siteId, WPCOM_FEATURES_VIDEO_HOSTING ),
hasVideoPressUnlimitedStorage: siteHasFeature(
state,
siteId,
WPCOM_FEATURES_VIDEOPRESS_UNLIMITED_STORAGE
),
siteSlug: getSiteSlug( state, siteId ),
siteTitle: getSiteTitle( state, siteId ),
rewindState: rewindState.state,
};
},
{
setAllSitesSelected,
recordGoogleEvent,
recordTracksEvent,
disconnect,
successNotice,
errorNotice,
infoNotice,
removeNotice,
}
)( localize( DisconnectJetpack ) );
|