Skip to content

Commit

Permalink
Merge pull request #1987 from Automattic/fix/1465-stale-data-plan-ove…
Browse files Browse the repository at this point in the history
…rview

Free Trials: Fix display of stale data in `PlanOverview`
  • Loading branch information
Tug committed Dec 30, 2015
2 parents 34d1187 + 07e7b8d commit adacbb4
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 7 deletions.
1 change: 0 additions & 1 deletion client/lib/sites-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports = function() {
break;
case InvitesActionTypes.INVITE_ACCEPTED_SUCCESS:
case 'RECEIVE_DISCONNECTED_SITE':
case 'RECEIVE_DELETED_SITE':
case 'FETCH_SITES':
_sites.fetch(); // refetch the sites from .com
break;
Expand Down
32 changes: 31 additions & 1 deletion client/my-sites/upgrades/checkout/thank-you.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
* External dependencies
*/
var React = require( 'react' ),
connect = require( 'react-redux' ).connect,
store = require( 'store' );

/**
* Internal dependencies
*/
var config = require( 'config' ),
Dispatcher = require( 'dispatcher' ),
cartItems = require( 'lib/cart-values' ).cartItems,
Card = require( 'components/card' ),
Main = require( 'components/main' ),
analytics = require( 'analytics' ),
isPlan = require( 'lib/products-values' ).isPlan,
{ getPrimaryDomain, isSubdomain } = require( 'lib/domains' ),
refreshSitePlans = require( 'state/sites/plans/actions' ).refreshSitePlans,
i18n = require( 'lib/mixins/i18n' ),
paths = require( 'my-sites/upgrades/paths' );

Expand Down Expand Up @@ -63,6 +66,24 @@ var CheckoutThankYou = React.createClass( {
},

componentDidMount: function() {
var lastTransaction = this.props.lastTransaction,
selectedSite;

if ( lastTransaction ) {
selectedSite = lastTransaction.selectedSite;

// Refresh selected site plans if the user just purchased a plan
if ( cartItems.hasPlan( lastTransaction.cart ) ) {
this.props.refreshSitePlans( selectedSite.ID );
}

// Refresh the list of sites to update the `site.plan` property
// needed to display the plan name on the right of the `Plans` menu item
Dispatcher.handleViewAction( {
type: 'FETCH_SITES'
} );
}

analytics.tracks.recordEvent( 'calypso_checkout_thank_you_view' );
},

Expand Down Expand Up @@ -632,4 +653,13 @@ PurchaseDetail = React.createClass( {
}
} );

module.exports = CheckoutThankYou;
module.exports = connect(
undefined,
function mapDispatchToProps( dispatch ) {
return {
refreshSitePlans( siteId ) {
dispatch( refreshSitePlans( siteId ) );
}
};
}
)( CheckoutThankYou );
8 changes: 5 additions & 3 deletions client/my-sites/upgrades/controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var analytics = require( 'analytics' ),
upgradesActions = require( 'lib/upgrades/actions' ),
titleActions = require( 'lib/screen-title/actions' ),
setSection = require( 'state/ui/actions' ).setSection,
productsList = require( 'lib/products-list' )();
productsList = require( 'lib/products-list' )(),
renderWithReduxStore = require( 'lib/react-helpers' ).renderWithReduxStore;

module.exports = {

Expand Down Expand Up @@ -211,12 +212,13 @@ module.exports = {

titleActions.setTitle( i18n.translate( 'Thank You' ) );

ReactDom.render(
renderWithReduxStore(
React.createElement( CheckoutThankYouComponent, {
lastTransaction: lastTransaction,
productsList: productsList
} ),
document.getElementById( 'primary' )
document.getElementById( 'primary' ),
context.store
);

ReactDom.unmountComponentAtNode( document.getElementById( 'secondary' ) );
Expand Down
1 change: 1 addition & 0 deletions client/state/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const NEW_NOTICE = 'NEW_NOTICE';
export const RECEIVE_PUBLICIZE_CONNECTIONS = 'RECEIVE_PUBLICIZE_CONNECTIONS';
export const RECEIVE_SITE = 'RECEIVE_SITE';
export const REMOVE_NOTICE = 'REMOVE_NOTICE';
export const REMOVE_SITE_PLANS = 'REMOVE_SITE_PLANS';
export const SET_SECTION = 'SET_SECTION';
export const SET_SELECTED_SITE = 'SET_SELECTED_SITE';
export const TOGGLE_EXPORTER_ADVANCED_SETTINGS = 'TOGGLE_EXPORTER_ADVANCED_SETTINGS';
Expand Down
1 change: 1 addition & 0 deletions client/state/sites/plans/action-types.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const FETCH_SITE_PLANS = 'FETCH_SITE_PLANS';
export const FETCH_SITE_PLANS_COMPLETED = 'FETCH_SITE_PLANS_COMPLETED';
export const REMOVE_SITE_PLANS = 'REMOVE_SITE_PLANS';
19 changes: 19 additions & 0 deletions client/state/sites/plans/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import wpcom from 'lib/wp';
import {
FETCH_SITE_PLANS,
FETCH_SITE_PLANS_COMPLETED,
REMOVE_SITE_PLANS
} from './action-types';

/**
Expand Down Expand Up @@ -62,3 +63,21 @@ export function fetchSitePlansCompleted( siteId, plans ) {
plans: map( plans, createSitePlanObject )
};
}

/**
* Returns an action object to be used in updating an object containing
* the plans for the given site.
*
* @param {Object} siteId ID of the concerned site
* @return {Object} Action object
*/
export function refreshSitePlans( siteId ) {
return ( dispatch ) => {
dispatch( {
type: REMOVE_SITE_PLANS,
siteId
} );

dispatch( fetchSitePlans( siteId ) );
}
}
6 changes: 5 additions & 1 deletion client/state/sites/plans/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/
import {
FETCH_SITE_PLANS,
FETCH_SITE_PLANS_COMPLETED
FETCH_SITE_PLANS_COMPLETED,
REMOVE_SITE_PLANS
} from './action-types';
import omit from 'lodash/object/omit';

export const initialSiteState = {
error: null,
Expand All @@ -30,6 +32,8 @@ export function plans( state = {}, action ) {
data: action.plans
} )
} );
case REMOVE_SITE_PLANS:
return omit( state, action.siteId );
}

return state;
Expand Down
17 changes: 16 additions & 1 deletion client/state/sites/plans/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from 'chai';
/**
* Internal dependencies
*/
import { FETCH_SITE_PLANS } from 'state/action-types';
import { FETCH_SITE_PLANS, REMOVE_SITE_PLANS } from 'state/action-types';
import { initialSiteState, plans } from '../reducer';

describe( 'reducer', () => {
Expand Down Expand Up @@ -57,5 +57,20 @@ describe( 'reducer', () => {
11111111: Object.assign( {}, initialSiteState, { isFetching: true } )
} );
} );

it( 'should remove plans for a given site ID', () => {
const original = Object.freeze( {
11111111: initialSiteState,
22222222: initialSiteState
} ),
state = plans( original, {
type: REMOVE_SITE_PLANS,
siteId: 11111111
} );

expect( state ).to.eql( {
22222222: initialSiteState
} );
} );
} );
} );

0 comments on commit adacbb4

Please sign in to comment.