File size: 3,929 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
import { Card } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { preventWidows } from 'calypso/lib/formatting';
import JetpackExampleActivate from './example-components/jetpack-activate';
import JetpackExampleConnect from './example-components/jetpack-connect';
import JetpackExampleInstall from './example-components/jetpack-install';

const noop = () => {};

class JetpackInstallStep extends Component {
	static propTypes = {
		confirmJetpackInstallStatus: PropTypes.func.isRequired,
		currentUrl: PropTypes.string,
		onClick: PropTypes.func,
	};

	static defaultProps = {
		currentUrl: '',
		onClick: noop,
	};

	confirmJetpackInstalled = ( event ) => {
		event.preventDefault();
		this.props.confirmJetpackInstallStatus( true );
	};

	confirmJetpackNotInstalled = ( event ) => {
		event.preventDefault();
		this.props.confirmJetpackInstallStatus( false );
	};

	renderAlreadyHaveJetpackButton() {
		return (
			// eslint-disable-next-line jsx-a11y/anchor-is-valid
			<a
				className="jetpack-connect__already-installed-jetpack-button"
				href="#"
				onClick={ this.confirmJetpackInstalled }
			>
				{ preventWidows( this.props.translate( 'Already have Jetpack installed?' ) ) }
			</a>
		);
	}

	renderNotJetpackButton() {
		return (
			// eslint-disable-next-line jsx-a11y/anchor-is-valid
			<a
				className="jetpack-connect__no-jetpack-button"
				href="#"
				onClick={ this.confirmJetpackNotInstalled }
			>
				{ preventWidows( this.props.translate( "Don't have Jetpack installed?" ) ) }
			</a>
		);
	}

	getStep( stepName ) {
		const { currentUrl, onClick, translate } = this.props;

		const jetpackConnectExample = <JetpackExampleConnect url={ currentUrl } onClick={ onClick } />;

		const steps = {
			installJetpack: {
				title: translate( '1. Install Jetpack' ),
				text: translate(
					"Click the green “Install Jetpack” button below. You'll be redirected to the " +
						"Jetpack plugin page on your site’s wp-admin dashboard, where you'll " +
						'then click the blue “Install Now” button.'
				),
				action: this.renderAlreadyHaveJetpackButton(),
				example: <JetpackExampleInstall url={ currentUrl } onClick={ onClick } />,
			},
			activateJetpackAfterInstall: {
				title: translate( '2. Activate Jetpack' ),
				text: translate( 'Next, click the blue “Activate Plugin” button to activate Jetpack.' ),
				action: null,
				example: <JetpackExampleActivate url={ currentUrl } isInstall onClick={ onClick } />,
			},
			connectJetpackAfterInstall: {
				title: translate( '3. Connect Jetpack' ),
				text: translate( 'Finally, click the “Set up Jetpack” button to finish the process.' ),
				action: null,
				example: jetpackConnectExample,
			},
			activateJetpack: {
				title: translate( '1. Activate Jetpack' ),
				text: translate(
					"You'll be redirected to the Plugins page on your site’s wp-admin " +
						"dashboard, where you'll then Click the blue “Activate” link. "
				),
				action: this.renderNotJetpackButton(),
				example: (
					<JetpackExampleActivate url={ currentUrl } isInstall={ false } onClick={ onClick } />
				),
			},
			connectJetpack: {
				title: translate( '2. Connect Jetpack' ),
				text: translate( 'Then click the “Set up Jetpack” button to finish the process.' ),
				action: null,
				example: jetpackConnectExample,
			},
		};
		return steps[ stepName ];
	}

	render() {
		const step = this.getStep( this.props.stepName );
		return (
			<Card className="jetpack-connect__install-step">
				<div className="jetpack-connect__install-step-title">{ step.title }</div>
				<div className="jetpack-connect__install-step-text">
					<span>
						{ preventWidows( step.text ) }
						&nbsp;
						{ step.action }
					</span>
				</div>
				{ step.example }
			</Card>
		);
	}
}

export default localize( JetpackInstallStep );