Skip to content

Commit

Permalink
Google Apps: Fill out the registration for G Suite in cart
Browse files Browse the repository at this point in the history
* Google Apps: Fill out the registration for G Suite in cart

This helps to preserve the data for when PayPal Express is used as
payment form and is more consistent with what G Suite uses.
  • Loading branch information
klimeryk authored and matthusby committed Mar 10, 2017
1 parent 2989829 commit 24d8ce7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion client/lib/cart-values/cart-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,18 @@ function googleAppsExtraLicenses( properties ) {
return assign( item, { extra: { google_apps_users: properties.users } } );
}

function fillGoogleAppsRegistrationData( cart, registrationData ) {
const googleAppsItems = filter( getAll( cart ), isGoogleApps );
return flow.apply( null, googleAppsItems.map( function( item ) {
item.extra = assign( item.extra, { google_apps_registration_data: registrationData } );
return add( item )
} ) );
}

function hasGoogleApps( cart ) {
return some( getAll( cart ), isGoogleApps );
}


function customDesignItem() {
return {
product_slug: 'custom-design'
Expand Down Expand Up @@ -769,6 +776,7 @@ module.exports = {
domainPrivacyProtection,
domainRedemption,
domainRegistration,
fillGoogleAppsRegistrationData,
findFreeTrial,
getAll,
getAllSorted,
Expand Down
4 changes: 4 additions & 0 deletions client/lib/cart/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ CartStore.dispatchToken = Dispatcher.register( ( payload ) => {
update( cartItems.removePrivacyFromAllDomains( CartStore.get() ) );
break;

case UpgradesActionTypes.GOOGLE_APPS_REGISTRATION_DATA_ADD:
update( cartItems.fillGoogleAppsRegistrationData( CartStore.get(), action.registrationData ) );
break;

case UpgradesActionTypes.CART_ITEMS_ADD:
update( flow( ...action.cartItems.map( cartItem => cartItems.add( cartItem ) ) ) );
break;
Expand Down
8 changes: 8 additions & 0 deletions client/lib/upgrades/actions/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function addDomainToCart( domainSuggestion ) {
} ) );
}

function addGoogleAppsRegistrationData( registrationData ) {
Dispatcher.handleViewAction( {
type: ActionTypes.GOOGLE_APPS_REGISTRATION_DATA_ADD,
registrationData: registrationData
} );
}

function removeDomainFromCart( domainSuggestion ) {
removeItem( cartItems.domainRegistration( {
domain: domainSuggestion.domain_name,
Expand All @@ -92,6 +99,7 @@ function applyCoupon( coupon ) {

export {
addDomainToCart,
addGoogleAppsRegistrationData,
addItem,
addItems,
addPrivacyToAllDomains,
Expand Down
1 change: 1 addition & 0 deletions client/lib/upgrades/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports.action = keyMirror( {
EMAIL_FORWARDING_FETCH_COMPLETED: null,
EMAIL_FORWARDING_FETCH_FAILED: null,
ICANN_VERIFICATION_RESEND_COMPLETED: null,
GOOGLE_APPS_REGISTRATION_DATA_ADD: null,
NAMESERVERS_FETCH: null,
NAMESERVERS_FETCH_COMPLETED: null,
NAMESERVERS_FETCH_FAILED: null,
Expand Down
3 changes: 2 additions & 1 deletion client/my-sites/upgrades/checkout/domain-details-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { cartItems } from 'lib/cart-values';
import { forDomainRegistrations as countriesListForDomainRegistrations } from 'lib/countries-list';
import analytics from 'lib/analytics';
import formState from 'lib/form-state';
import { addPrivacyToAllDomains, removePrivacyFromAllDomains, setDomainDetails } from 'lib/upgrades/actions';
import { addPrivacyToAllDomains, removePrivacyFromAllDomains, setDomainDetails, addGoogleAppsRegistrationData } from 'lib/upgrades/actions';
import FormButton from 'components/forms/form-button';
import { countries } from 'components/phone-input/data';
import { toIcannFormat } from 'components/phone-input/phone-number';
Expand Down Expand Up @@ -401,6 +401,7 @@ export default React.createClass( {
const allFieldValues = Object.assign( {}, formState.getAllFieldValues( this.state.form ) );
allFieldValues.phone = toIcannFormat( allFieldValues.phone, countries[ this.state.phoneCountryCode ] );
setDomainDetails( allFieldValues );
addGoogleAppsRegistrationData( allFieldValues );
},

setPrivacyProtectionSubscriptions( enable ) {
Expand Down

0 comments on commit 24d8ce7

Please sign in to comment.