File size: 2,515 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
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { addQueryArgs } from 'calypso/lib/route';
import { urlToSlug } from 'calypso/lib/url';

import './style.scss';

class JetpackConnectSiteOnly extends Component {
	static propTypes = {
		homeUrl: PropTypes.string.isRequired,
		redirectAfterAuth: PropTypes.string.isRequired,
		source: PropTypes.string,
	};

	getPlansURL() {
		const { homeUrl, redirectAfterAuth } = this.props;
		const slug = urlToSlug( homeUrl );

		// Pull the purchase nonce out of the redirect uri
		const urlParams = new URLSearchParams( window.location.search );
		const calypsoEnv = urlParams.get( 'calypso_env' );
		const redirectParams = new URLSearchParams( urlParams.get( 'redirect_to' ) );
		const purchaseNonce = redirectParams.get( 'purchase_nonce' );

		const url =
			'development' === calypsoEnv
				? `http://jetpack.cloud.localhost:3001/pricing/${ slug }`
				: `https://cloud.jetpack.com/pricing/${ slug }`;

		return addQueryArgs(
			{
				redirect: redirectAfterAuth,
				site: slug,
				unlinked: '1',
				purchaseNonce,
			},
			url
		);
	}

	getTracksProps() {
		const { source } = this.props;
		return { source };
	}

	onSkip() {
		recordTracksEvent( 'calypso_jpc_iframe_skip_user_connection', this.getTracksProps() );
	}

	onFeatures() {
		recordTracksEvent( 'calypso_jpc_iframe_view_all_features', this.getTracksProps() );
	}

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

		return (
			<div className="jetpack-connect-site-only__form">
				<h2>{ translate( 'Or start using Jetpack now' ) }</h2>

				<p>{ translate( 'Jump in and start using Jetpack right away.' ) }</p>
				<p>
					{ translate(
						"{{link}}Some features{{/link}} will not be available, but you'll be able to connect your user account at any point to unlock them.",
						{
							components: {
								link: (
									<a
										target="_blank"
										href="https://jetpack.com/support/why-the-wordpress-com-connection-is-important-for-jetpack/"
										rel="noreferrer"
										onClick={ () => this.onFeatures() }
									/>
								),
							},
						}
					) }
				</p>

				<a
					className="jetpack-connect-site-only__continue-link"
					href={ this.getPlansURL() }
					onClick={ () => this.onSkip() }
				>
					{ translate( 'Continue without user account' ) }
				</a>
			</div>
		);
	}
}

export default localize( JetpackConnectSiteOnly );