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

Free Trials: Fix display of stale data in PlanOverview #1987

Merged
merged 9 commits into from
Dec 30, 2015

Conversation

Tug
Copy link
Contributor

@Tug Tug commented Dec 29, 2015

Fixes #1465
where stale data is displayed when navigating to the plan page and the plan information is not yet available.

Before:
domain

After:
untitled

Review guide:

  • git fetch origin && git checkout fix/1465-stale-data-plan-overview
  • Run server with make run
  • Purchase a free plan. Once on the thank you page, go back to My Sites and then Plans.
  • Check that you either see your new plan with free trial or the placeholders for a moment.
  • Check that the plan name in the sidebar updates faster than in the gif.
  • Product Review
  • Code Review

cc: @spncrb @drewblaisdell

@Tug Tug added [Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans. [Status] In Progress Free Trials labels Dec 29, 2015
@Tug Tug added this to the No-cc Free Trials: v1 milestone Dec 29, 2015
Adding the `REMOVE_SITE_PLANS` action type which simply removes a site from the site.plans store.
The `updateSitePlans` actions dispatch a `REMOVE_SITE_PLANS` action add calls `fetchSitePlans`.
For this commit we call the `updateSitePlans` action when the thank you page is mounted,
so going back to the plan page won't display stale data.
@Tug Tug force-pushed the fix/1465-stale-data-plan-overview branch from ed75319 to 3805e23 Compare December 29, 2015 14:11
@Tug Tug force-pushed the fix/1465-stale-data-plan-overview branch from fc0652a to 4e8ee99 Compare December 29, 2015 16:35
@Tug Tug added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Dec 29, 2015
* @param {Object} siteId ID of the concerned site
* @return {Object} Action object
*/
export function updateSitePlans( siteId ) {
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 about naming this something like refreshSitePlans? updateSitePlans sounds to me like we're trying to change them on the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

@@ -632,4 +643,15 @@ PurchaseDetail = React.createClass( {
}
} );

module.exports = CheckoutThankYou;
module.exports = connect(
function mapStateToProps( state, props ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a linting rule against using defining variables that are never used. We should just skip argument this with an anonymous function () => {} or undefined. The later would be a better solution if it works (and I think it does, based on the docs).

@@ -63,6 +66,14 @@ var CheckoutThankYou = React.createClass( {
},

componentDidMount: function() {
var selectedSite = this.props.lastTransaction.selectedSite;
this.props.refreshSitePlans( selectedSite.ID );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to refresh these for all purchases, or just when the user checks out with a trial/plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, we should refresh only when the user purchased a plan. I tested with themes though and it never reaches the thank you page.
I haven't tested domain or other upgrades so I guess it's cleaner to check for the type of transaction explicitly.

siteId
} );

return fetchSitePlans( siteId );
Copy link
Contributor

Choose a reason for hiding this comment

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

In order for this function to fetch site plans, we need to pass the result of this call to dispatch like

dispatch( fetchSitePlans( siteId ) );

This is because refreshSitePlans and fetchSitePlans are 'thunk action creators' (docs) and return functions that take dispatch.

@Tug Tug force-pushed the fix/1465-stale-data-plan-overview branch from 229b141 to ec48c4c Compare December 29, 2015 18:42
@Tug
Copy link
Contributor Author

Tug commented Dec 29, 2015

@drewblaisdell Thank you for reviewing, I have fixed the problems you reported.
Can you give it another look when you have time?

var lastTransaction = this.props.lastTransaction,
selectedSite;

if ( lastTransaction ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to guard against a missing lastTransaction here? There are a couple other places in this file where we assume that it is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I added it because I encountered an undefined lastTransaction error here (when reloading or going back to this page), but I think it will still throw an error because of those couple of other places.

@drewblaisdell
Copy link
Contributor

I had one question about something small. Otherwise, this LGTM.

@ghost
Copy link

ghost commented Dec 30, 2015

Good stuff 👍

@ghost ghost added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 30, 2015
Tug added a commit that referenced this pull request Dec 30, 2015
…rview

Free Trials: Fix display of stale data in `PlanOverview`
@Tug Tug merged commit adacbb4 into master Dec 30, 2015
@Tug Tug deleted the fix/1465-stale-data-plan-overview branch December 30, 2015 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plans: Don't display stale data in PlanOverview
2 participants