Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup: Fix site path through domain-first flow #11601

Merged
merged 3 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/lib/cart/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ CartStore.dispatchToken = Dispatcher.register( ( payload ) => {
} );

sites.on( 'change', setSelectedSite );
setSelectedSite();

if ( sites.fetched ) {
setSelectedSite();
}

module.exports = CartStore;
4 changes: 2 additions & 2 deletions client/lib/signup/flow-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ assign( SignupFlowController.prototype, {

SignupActions.processSignupStep( step );

const apiFunction = steps[ step.stepName ].apiRequestFunction.bind( this );
const apiFunction = steps[ step.stepName ].apiRequestFunction;

apiFunction( ( errors, providedDependencies ) => {
this._processingSteps[ step.stepName ] = false;
SignupActions.processedSignupStep( step, errors, providedDependencies );
}, dependenciesFound, step );
}, dependenciesFound, step, this._reduxStore );
}
},

Expand Down
50 changes: 9 additions & 41 deletions client/lib/signup/step-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import { startsWith } from 'lodash';
/**
* Internal dependencies
*/
import { cartItems } from 'lib/cart-values';
import wpcom from 'lib/wp' ;
const sites = require( 'lib/sites-list' )();
const user = require( 'lib/user' )();
import { getSavedVariations } from 'lib/abtest';
import SignupCart from 'lib/signup/cart';
import { startFreeTrial } from 'lib/upgrades/actions';
import { PLAN_PREMIUM } from 'lib/plans/constants';
import analytics from 'lib/analytics';

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

function createCart( callback, dependencies, data ) {
function createCart( callback, dependencies, data, reduxStore ) {
const { designType } = dependencies;
const { domainItem, themeItem } = data;

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

SignupCart.addToCart( cartKey, [ domainItem ], error => callback( error, providedDependencies ) );
} else {
createSiteWithCart( callback, dependencies, data );
createSiteWithCart( callback, dependencies, data, reduxStore );
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that we also have createSiteWithCartAndStartFreeTrial function that calls createSiteWithCart but reduxStore param is not passed. I have no idea if that is required, but we should double check if it doesn't break anything.

Expand All @@ -55,9 +52,9 @@ function createSiteWithCart( callback, dependencies, {
siteUrl,
themeSlugWithRepo,
themeItem
} ) {
const siteTitle = getSiteTitle( this._reduxStore.getState() ).trim();
const surveyVertical = getSurveyVertical( this._reduxStore.getState() ).trim();
}, reduxStore ) {
const siteTitle = getSiteTitle( reduxStore.getState() ).trim();
const surveyVertical = getSurveyVertical( reduxStore.getState() ).trim();

wpcom.undocumented().sitesNew( {
blog_name: siteUrl,
Expand Down Expand Up @@ -109,7 +106,7 @@ function createSiteWithCart( callback, dependencies, {
if ( ! user.get() && isFreeThemePreselected ) {
setThemeOnSite( addToCartAndProceed, { siteSlug, themeSlugWithRepo } );
} else if ( user.get() && isFreeThemePreselected ) {
fetchSitesAndUser( siteSlug, setThemeOnSite.bind( this, addToCartAndProceed, { siteSlug, themeSlugWithRepo } ) );
fetchSitesAndUser( siteSlug, setThemeOnSite.bind( null, addToCartAndProceed, { siteSlug, themeSlugWithRepo } ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of using an arrow function here?

fetchSitesAndUser( siteSlug, () => {
	setThemeOnSite( addToCartAndProceed, { siteSlug, themeSlugWithRepo } );
} );

This may be just me but I find it more readable :).

} else if ( user.get() ) {
fetchSitesAndUser( siteSlug, addToCartAndProceed );
} else {
Expand All @@ -118,25 +115,6 @@ function createSiteWithCart( callback, dependencies, {
} );
}

/**
* Adds a Premium with free trial to the shopping cart.
*
* @param {function} callback - function to execute when action completes
* @param {object} dependencies - data provided to the current step
* @param {object} data - additional data provided by the current step
*/
function startFreePremiumTrial( callback, dependencies, data ) {
const { siteId } = dependencies;

startFreeTrial( siteId, cartItems.planItem( PLAN_PREMIUM ), ( error ) => {
if ( error ) {
callback( error, dependencies );
} else {
callback( error, dependencies, data );
}
} );
}

function fetchSitesUntilSiteAppears( siteSlug, callback ) {
if ( sites.select( siteSlug ) ) {
callback();
Expand Down Expand Up @@ -243,16 +221,6 @@ module.exports = {

createSiteWithCart,

createSiteWithCartAndStartFreeTrial( callback, dependencies, data ) {
createSiteWithCart( ( error, providedDependencies ) => {
if ( error ) {
callback( error, providedDependencies );
} else {
startFreePremiumTrial( callback, providedDependencies, data );
}
}, dependencies, data );
},

addPlanToCart( callback, { siteId }, { cartItem, privacyItem } ) {
if ( isEmpty( cartItem ) ) {
// the user selected the free plan
Expand All @@ -266,9 +234,9 @@ module.exports = {
SignupCart.addToCart( siteId, newCartItems, callback );
},

createAccount( callback, dependencies, { userData, flowName, queryArgs } ) {
const surveyVertical = getSurveyVertical( this._reduxStore.getState() ).trim();
const surveySiteType = getSurveySiteType( this._reduxStore.getState() ).trim();
createAccount( callback, dependencies, { userData, flowName, queryArgs }, reduxStore ) {
const surveyVertical = getSurveyVertical( reduxStore.getState() ).trim();
const surveySiteType = getSurveySiteType( reduxStore.getState() ).trim();

wpcom.undocumented().usersNew( assign(
{}, userData, {
Expand Down
1 change: 0 additions & 1 deletion client/signup/config/step-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
'design-type': DesignTypeComponent,
'design-type-with-store': DesignTypeWithStoreComponent,
domains: DomainsStepComponent,
'domains-with-plan': DomainsStepComponent,
'domain-only': DomainsStepComponent,
'domains-theme-preselected': DomainsStepComponent,
'jetpack-user': UserSignupComponent,
Expand Down
11 changes: 0 additions & 11 deletions client/signup/config/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ module.exports = {
delayApiRequestUntilComplete: true
},

'domains-with-plan': {
stepName: 'domains-with-plan',
apiRequestFunction: stepActions.createSiteWithCartAndStartFreeTrial,
providesDependencies: [ 'siteId', 'siteSlug', 'domainItem', 'themeItem' ],
dependencies: [ 'themeSlugWithRepo' ],
props: {
isDomainOnly: false
},
delayApiRequestUntilComplete: true
},

'domains-theme-preselected': {
stepName: 'domains-theme-preselected',
apiRequestFunction: stepActions.createSiteWithCart,
Expand Down