File size: 1,642 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
import config from '@automattic/calypso-config';
import { isFreePlan } from '@automattic/calypso-products';
import { Component } from 'react';
import { connect } from 'react-redux';
import { submitSignupStep } from 'calypso/state/signup/progress/actions';
import { getSite } from 'calypso/state/sites/selectors';

/**
 * @param {null|undefined|{plan?: {product_slug: string}}} selectedSite
 * @returns {boolean}
 */
export const siteHasPaidPlan = ( selectedSite ) =>
	Boolean( selectedSite && selectedSite.plan && ! isFreePlan( selectedSite.plan.product_slug ) );

export class SitePickerSubmit extends Component {
	// @TODO: Please update https://github.com/Automattic/wp-calypso/issues/58453 if you are refactoring away from UNSAFE_* lifecycle methods!
	UNSAFE_componentWillMount() {
		const { stepSectionName, stepName, goToStep, selectedSite } = this.props;
		const hasPaidPlan = siteHasPaidPlan( selectedSite );
		const { ID: siteId, slug: siteSlug } = selectedSite;

		this.props.submitSignupStep(
			{
				stepName,
				stepSectionName,
				siteId,
				siteSlug,
			},
			{ themeSlugWithRepo: 'pub/twentysixteen' }
		);

		if ( hasPaidPlan ) {
			this.props.submitSignupStep(
				{ stepName: 'plans-site-selected', wasSkipped: true },
				{ cartItems: null, themeSlugWithRepo: 'pub/twentysixteen' }
			);

			goToStep( config.isEnabled( 'signup/social-first' ) ? 'user-social' : 'user' );
		} else {
			goToStep( 'plans-site-selected' );
		}
	}

	render() {
		return null;
	}
}

export default connect(
	( state, ownProps ) => ( {
		selectedSite: getSite( state, ownProps.siteSlug ),
	} ),
	{ submitSignupStep }
)( SitePickerSubmit );