Skip to content

Commit 64725fb

Browse files
authored
Merge pull request #11601 from Automattic/fix/domain-first-with-site
Signup: Fix `site` path through `domain-first` flow
2 parents 4507e4b + 5a69d5f commit 64725fb

File tree

5 files changed

+15
-56
lines changed

5 files changed

+15
-56
lines changed

client/lib/cart/store/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ CartStore.dispatchToken = Dispatcher.register( ( payload ) => {
134134
} );
135135

136136
sites.on( 'change', setSelectedSite );
137-
setSelectedSite();
137+
138+
if ( sites.fetched ) {
139+
setSelectedSite();
140+
}
138141

139142
module.exports = CartStore;

client/lib/signup/flow-controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ assign( SignupFlowController.prototype, {
204204

205205
SignupActions.processSignupStep( step );
206206

207-
const apiFunction = steps[ step.stepName ].apiRequestFunction.bind( this );
207+
const apiFunction = steps[ step.stepName ].apiRequestFunction;
208208

209209
apiFunction( ( errors, providedDependencies ) => {
210210
this._processingSteps[ step.stepName ] = false;
211211
SignupActions.processedSignupStep( step, errors, providedDependencies );
212-
}, dependenciesFound, step );
212+
}, dependenciesFound, step, this._reduxStore );
213213
}
214214
},
215215

client/lib/signup/step-actions.js

+9-41
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ import { startsWith } from 'lodash';
1111
/**
1212
* Internal dependencies
1313
*/
14-
import { cartItems } from 'lib/cart-values';
1514
import wpcom from 'lib/wp' ;
1615
const sites = require( 'lib/sites-list' )();
1716
const user = require( 'lib/user' )();
1817
import { getSavedVariations } from 'lib/abtest';
1918
import SignupCart from 'lib/signup/cart';
20-
import { startFreeTrial } from 'lib/upgrades/actions';
21-
import { PLAN_PREMIUM } from 'lib/plans/constants';
2219
import analytics from 'lib/analytics';
2320

2421
import {
@@ -28,7 +25,7 @@ import {
2825
import { getSiteTitle } from 'state/signup/steps/site-title/selectors';
2926
import { getSurveyVertical, getSurveySiteType } from 'state/signup/steps/survey/selectors';
3027

31-
function createCart( callback, dependencies, data ) {
28+
function createCart( callback, dependencies, data, reduxStore ) {
3229
const { designType } = dependencies;
3330
const { domainItem, themeItem } = data;
3431

@@ -43,7 +40,7 @@ function createCart( callback, dependencies, data ) {
4340

4441
SignupCart.addToCart( cartKey, [ domainItem ], error => callback( error, providedDependencies ) );
4542
} else {
46-
createSiteWithCart( callback, dependencies, data );
43+
createSiteWithCart( callback, dependencies, data, reduxStore );
4744
}
4845
}
4946

@@ -55,9 +52,9 @@ function createSiteWithCart( callback, dependencies, {
5552
siteUrl,
5653
themeSlugWithRepo,
5754
themeItem
58-
} ) {
59-
const siteTitle = getSiteTitle( this._reduxStore.getState() ).trim();
60-
const surveyVertical = getSurveyVertical( this._reduxStore.getState() ).trim();
55+
}, reduxStore ) {
56+
const siteTitle = getSiteTitle( reduxStore.getState() ).trim();
57+
const surveyVertical = getSurveyVertical( reduxStore.getState() ).trim();
6158

6259
wpcom.undocumented().sitesNew( {
6360
blog_name: siteUrl,
@@ -109,7 +106,7 @@ function createSiteWithCart( callback, dependencies, {
109106
if ( ! user.get() && isFreeThemePreselected ) {
110107
setThemeOnSite( addToCartAndProceed, { siteSlug, themeSlugWithRepo } );
111108
} else if ( user.get() && isFreeThemePreselected ) {
112-
fetchSitesAndUser( siteSlug, setThemeOnSite.bind( this, addToCartAndProceed, { siteSlug, themeSlugWithRepo } ) );
109+
fetchSitesAndUser( siteSlug, setThemeOnSite.bind( null, addToCartAndProceed, { siteSlug, themeSlugWithRepo } ) );
113110
} else if ( user.get() ) {
114111
fetchSitesAndUser( siteSlug, addToCartAndProceed );
115112
} else {
@@ -118,25 +115,6 @@ function createSiteWithCart( callback, dependencies, {
118115
} );
119116
}
120117

121-
/**
122-
* Adds a Premium with free trial to the shopping cart.
123-
*
124-
* @param {function} callback - function to execute when action completes
125-
* @param {object} dependencies - data provided to the current step
126-
* @param {object} data - additional data provided by the current step
127-
*/
128-
function startFreePremiumTrial( callback, dependencies, data ) {
129-
const { siteId } = dependencies;
130-
131-
startFreeTrial( siteId, cartItems.planItem( PLAN_PREMIUM ), ( error ) => {
132-
if ( error ) {
133-
callback( error, dependencies );
134-
} else {
135-
callback( error, dependencies, data );
136-
}
137-
} );
138-
}
139-
140118
function fetchSitesUntilSiteAppears( siteSlug, callback ) {
141119
if ( sites.select( siteSlug ) ) {
142120
callback();
@@ -243,16 +221,6 @@ module.exports = {
243221

244222
createSiteWithCart,
245223

246-
createSiteWithCartAndStartFreeTrial( callback, dependencies, data ) {
247-
createSiteWithCart( ( error, providedDependencies ) => {
248-
if ( error ) {
249-
callback( error, providedDependencies );
250-
} else {
251-
startFreePremiumTrial( callback, providedDependencies, data );
252-
}
253-
}, dependencies, data );
254-
},
255-
256224
addPlanToCart( callback, { siteId }, { cartItem, privacyItem } ) {
257225
if ( isEmpty( cartItem ) ) {
258226
// the user selected the free plan
@@ -266,9 +234,9 @@ module.exports = {
266234
SignupCart.addToCart( siteId, newCartItems, callback );
267235
},
268236

269-
createAccount( callback, dependencies, { userData, flowName, queryArgs } ) {
270-
const surveyVertical = getSurveyVertical( this._reduxStore.getState() ).trim();
271-
const surveySiteType = getSurveySiteType( this._reduxStore.getState() ).trim();
237+
createAccount( callback, dependencies, { userData, flowName, queryArgs }, reduxStore ) {
238+
const surveyVertical = getSurveyVertical( reduxStore.getState() ).trim();
239+
const surveySiteType = getSurveySiteType( reduxStore.getState() ).trim();
272240

273241
wpcom.undocumented().usersNew( assign(
274242
{}, userData, {

client/signup/config/step-components.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
'design-type': DesignTypeComponent,
2121
'design-type-with-store': DesignTypeWithStoreComponent,
2222
domains: DomainsStepComponent,
23-
'domains-with-plan': DomainsStepComponent,
2423
'domain-only': DomainsStepComponent,
2524
'domains-theme-preselected': DomainsStepComponent,
2625
'jetpack-user': UserSignupComponent,

client/signup/config/steps.js

-11
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ module.exports = {
9191
delayApiRequestUntilComplete: true
9292
},
9393

94-
'domains-with-plan': {
95-
stepName: 'domains-with-plan',
96-
apiRequestFunction: stepActions.createSiteWithCartAndStartFreeTrial,
97-
providesDependencies: [ 'siteId', 'siteSlug', 'domainItem', 'themeItem' ],
98-
dependencies: [ 'themeSlugWithRepo' ],
99-
props: {
100-
isDomainOnly: false
101-
},
102-
delayApiRequestUntilComplete: true
103-
},
104-
10594
'domains-theme-preselected': {
10695
stepName: 'domains-theme-preselected',
10796
apiRequestFunction: stepActions.createSiteWithCart,

0 commit comments

Comments
 (0)