-
Notifications
You must be signed in to change notification settings - Fork 2k
/
confirm.jsx
112 lines (101 loc) · 3.06 KB
/
confirm.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
/**
* External dependencies
*/
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { find, flowRight, isArray } from 'lodash';
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
/**
* Internal dependencies
*/
import DisconnectJetpack from 'blocks/disconnect-jetpack';
import DocumentHead from 'components/data/document-head';
import enrichedSurveyData from 'components/marketing-survey/cancel-purchase-form/enriched-survey-data';
import FormattedHeader from 'components/formatted-header';
import Main from 'components/main';
import NavigationLink from 'components/wizard/navigation-link';
import redirectNonJetpack from 'my-sites/site-settings/redirect-non-jetpack';
import { getCurrentPlan } from 'state/sites/plans/selectors';
import { getSelectedSite, getSelectedSiteId, getSelectedSiteSlug } from 'state/ui/selectors';
import { submitSurvey } from 'lib/purchases/actions';
class ConfirmDisconnection extends PureComponent {
static propTypes = {
reason: PropTypes.string,
type: PropTypes.string,
text: PropTypes.oneOfType( [ PropTypes.string, PropTypes.arrayOf( PropTypes.string ) ] ),
// Provided by HOCs
purchase: PropTypes.object,
siteId: PropTypes.number,
siteSlug: PropTypes.string,
translate: PropTypes.func,
};
static allowedReasons = [
'troubleshooting',
'cannot-work',
'slow',
'buggy',
'no-clarity',
'delete',
'other',
];
submitSurvey = () => {
const { purchase, reason, siteId, text } = this.props;
const surveyData = {
'why-cancel': {
response: find( this.constructor.allowedReasons, ( r ) => r === reason ),
text: isArray( text ) ? text.join() : text,
},
source: {
from: 'Calypso',
},
};
submitSurvey(
'calypso-disconnect-jetpack-july2019',
siteId,
enrichedSurveyData( surveyData, purchase )
);
};
render() {
const { type, siteId, siteSlug, translate } = this.props;
const backHref =
`/settings/disconnect-site/${ siteSlug }` +
( type ? `?type=${ encodeURIComponent( type ) }` : '' );
return (
<Main className="disconnect-site__confirm">
<DocumentHead title={ translate( 'Site Settings' ) } />
<FormattedHeader
headerText={ translate( 'Confirm Disconnection' ) }
subHeaderText={ translate(
'Confirm that you want to disconnect your site from WordPress.com.'
) }
/>
<DisconnectJetpack
disconnectHref="/stats"
isBroken={ false }
onDisconnectClick={ this.submitSurvey }
showTitle={ false }
siteId={ siteId }
stayConnectedHref={ '/settings/manage-connection/' + siteSlug }
/>
<div className="disconnect-site__navigation-links">
<NavigationLink href={ backHref } direction="back" />
</div>
</Main>
);
}
}
const connectComponent = connect( ( state ) => {
const siteId = getSelectedSiteId( state );
return {
purchase: getCurrentPlan( state, siteId ),
site: getSelectedSite( state ),
siteId,
siteSlug: getSelectedSiteSlug( state ),
};
} );
export default flowRight(
connectComponent,
localize,
redirectNonJetpack()
)( ConfirmDisconnection );