Skip to content

Commit

Permalink
Fix where if a user isn't logged into wpcom, go to blank screen (#8951)
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom authored and oskosk committed Mar 3, 2018
1 parent ea3403d commit 4e272a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions _inc/client/plans/plan-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import includes from 'lodash/includes';
* Internal dependencies
*/
import Button from 'components/button';
import { getSiteRawUrl } from 'state/initial-state';
import { getSiteRawUrl, getUserId } from 'state/initial-state';
import { getSitePlan, getAvailablePlans } from 'state/site/reducer';
import analytics from 'lib/analytics';
import { getPlanClass } from 'lib/plans/constants';
Expand Down Expand Up @@ -192,7 +192,7 @@ class PlanGrid extends React.Component {
const isActivePlan = this.isCurrentPlanType( planType );
const url = isActivePlan
? `https://wordpress.com/plans/my-plan/${ this.props.siteRawUrl }`
: `https://wordpress.com/checkout/${ this.props.siteRawUrl }/${ planType === 'personal' ? 'jetpack-personal' : planType }`;
: `https://jetpack.com/redirect/?source=plans-${ planType }&site=${ this.props.siteRawUrl }&u=${ this.props.userId }`;
const isPrimary = this.isPrimary( planType, plan );
const className = classNames(
'plan-features__table-item',
Expand Down Expand Up @@ -253,7 +253,7 @@ class PlanGrid extends React.Component {
*/
renderBottomButtons() {
return map( this.getPlans(), ( plan, planType ) => {
const url = `https://jetpack.com/features/comparison/?site=${ this.props.siteRawUrl }`;
const url = `https://jetpack.com/redirect/?source=plans-learn-more&site=${ this.props.siteRawUrl }&u=${ this.props.userId }`;
return (
<td key={ 'bottom-' + planType } className="plan-features__table-item is-bottom-buttons has-border-bottom">
<Button href={ url }>{ plan.strings.see_all }</Button>
Expand Down Expand Up @@ -331,7 +331,7 @@ class PlanGrid extends React.Component {
} );
};
return (
<a onClick={ clickHandler } href={ 'https://jetpack.com/features/' + feature.info }>{ feature.name }</a>
<a onClick={ clickHandler } href={ `https://jetpack.com/features/${ feature.info }?site=${ this.props.siteRawUrl }&u=${ this.props.userId }` }>{ feature.name }</a>
);
}

Expand All @@ -341,6 +341,7 @@ export default connect( ( state ) => {
return {
plans: getAvailablePlans( state ),
siteRawUrl: getSiteRawUrl( state ),
sitePlan: getSitePlan( state )
sitePlan: getSitePlan( state ),
userId: getUserId( state ),
};
}, null, )( PlanGrid );
9 changes: 9 additions & 0 deletions _inc/client/state/initial-state/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export function getUsername( state ) {
return get( state.jetpack.initialState.userData.currentUser, [ 'username' ] );
}

/**
* Gets the current wp-admin user id
* @param {Object} state Global state tree
* @returns {int} The user id in wp-admin
*/
export function getUserId( state ) {
return get( state.jetpack.initialState.userData.currentUser, 'id' );
}

export function userCanViewStats( state ) {
return get( state.jetpack.initialState.userData.currentUser.permissions, 'view_stats', false );
}
Expand Down
1 change: 1 addition & 0 deletions _inc/lib/admin-pages/class.jetpack-react-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ function jetpack_current_user_data() {
'isConnected' => Jetpack::is_user_connected( $current_user->ID ),
'isMaster' => $is_master_user,
'username' => $current_user->user_login,
'id' => $current_user->ID,
'wpcomUser' => $dotcom_data,
'gravatar' => get_avatar( $current_user->ID, 40, 'mm', '', array( 'force_display' => true ) ),
'permissions' => array(
Expand Down

0 comments on commit 4e272a1

Please sign in to comment.