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

Fix where if a user isn't logged into wpcom, go to blank screen #8951

Merged
merged 3 commits into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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