File size: 1,383 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
import { Button } from '@automattic/components';
import { localize } from 'i18n-calypso';
import { Component } from 'react';
import { connect } from 'react-redux';
import accept from 'calypso/lib/accept';
import { recordTracksEvent } from 'calypso/state/analytics/actions';

class MigrateButton extends Component {
	state = {
		busy: false,
	};

	confirmCallback = ( accepted ) => {
		if ( accepted ) {
			this.props.recordTracksEvent( 'calypso_site_migration_start_confirm_clicked' );
			this.setState( { busy: true }, this.props.onClick );
		} else {
			return;
		}
	};

	handleClick = () => {
		const { translate } = this.props;

		if ( this.state.busy ) {
			return;
		}

		const message = (
			<>
				<h1>{ translate( 'Import and replace everything on this site?' ) }</h1>
				<div>
					{ translate( 'All posts, pages, comments and media will be lost on %(targetDomain)s.', {
						args: {
							targetDomain: this.props.targetSiteDomain,
						},
					} ) }
				</div>
			</>
		);

		this.props.recordTracksEvent( 'calypso_site_migration_start_clicked' );

		accept( message, this.confirmCallback, translate( 'Import and overwrite' ) );
	};

	render() {
		return (
			<Button primary busy={ this.state.busy } onClick={ this.handleClick }>
				{ this.props.children }
			</Button>
		);
	}
}

export default connect( null, { recordTracksEvent } )( localize( MigrateButton ) );