-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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.
ed75319
to
3805e23
Compare
fc0652a
to
4e8ee99
Compare
* @param {Object} siteId ID of the concerned site | ||
* @return {Object} Action object | ||
*/ | ||
export function updateSitePlans( siteId ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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).
….handleServerAction' because this action is triggered by the client
@@ -63,6 +66,14 @@ var CheckoutThankYou = React.createClass( { | |||
}, | |||
|
|||
componentDidMount: function() { | |||
var selectedSite = this.props.lastTransaction.selectedSite; | |||
this.props.refreshSitePlans( selectedSite.ID ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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
.
229b141
to
ec48c4c
Compare
@drewblaisdell Thank you for reviewing, I have fixed the problems you reported. |
var lastTransaction = this.props.lastTransaction, | ||
selectedSite; | ||
|
||
if ( lastTransaction ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I had one question about something small. Otherwise, this LGTM. |
Good stuff 👍 |
…rview Free Trials: Fix display of stale data in `PlanOverview`
Fixes #1465
where stale data is displayed when navigating to the plan page and the plan information is not yet available.
Before:

After:

Review guide:
git fetch origin && git checkout fix/1465-stale-data-plan-overview
make run
My Sites
and thenPlans
.cc: @spncrb @drewblaisdell