Skip to content

Commit

Permalink
Connect button: Carry the "from" param when redirecting. (#17350)
Browse files Browse the repository at this point in the history
* Connect button: Carry the  param when redirecting.

* Only append parameter if it's already set. Don't need an empty one :)
  • Loading branch information
dereksmart authored Oct 2, 2020
1 parent 85aedcb commit 664e642
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions _inc/connect-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ jQuery( document ).ready( function ( $ ) {
handleConnectInPlaceFlow: function () {
// Alternative connection buttons should redirect to the main one for the "connect in place" flow.
if ( connectButton.hasClass( 'jp-banner__alt-connect-button' ) ) {
window.location = jpConnect.connectInPlaceUrl;
// Make sure we don't lose the `from` parameter, if set.
var fromParam = ( connectButtonFrom && '&from=' + connectButtonFrom ) || '';
window.location = jpConnect.connectInPlaceUrl + fromParam;
return;
}

Expand Down Expand Up @@ -146,24 +148,24 @@ jQuery( document ).ready( function ( $ ) {

// Fetch plan type late to make sure any stored license keys have been
// attached to the site during the connection.
jetpackConnectButton.fetchPlanType()
.always( function () {
if ( ! jetpackConnectButton.isPaidPlan ) {
window.location.assign( jpConnect.plansPromptUrl );
return;
}

var parser = document.createElement('a');
parser.href = jpConnect.dashboardUrl;
var reload = window.location.pathname === parser.pathname && window.location.hash !== parser.hash;

window.location.assign( jpConnect.dashboardUrl );

if ( reload ) {
// The Jetpack admin page has hashes in the URLs, so we need to reload the page after .assign()
window.location.reload( true );
}
} );
jetpackConnectButton.fetchPlanType().always( function () {
if ( ! jetpackConnectButton.isPaidPlan ) {
window.location.assign( jpConnect.plansPromptUrl );
return;
}

var parser = document.createElement( 'a' );
parser.href = jpConnect.dashboardUrl;
var reload =
window.location.pathname === parser.pathname && window.location.hash !== parser.hash;

window.location.assign( jpConnect.dashboardUrl );

if ( reload ) {
// The Jetpack admin page has hashes in the URLs, so we need to reload the page after .assign()
window.location.reload( true );
}
} );
},
handleConnectionError: function ( error ) {
jetpackConnectButton.isRegistering = false;
Expand All @@ -172,7 +174,11 @@ jQuery( document ).ready( function ( $ ) {
};

// When we visit /wp-admin/admin.php?page=jetpack#/setup, immediately start the connection flow.
var hash = location.hash.replace( /#\//, '' );
var hash = location.hash.replace( /(#\/setup).*/, 'setup' );

// In case the parameter has been manually set in the URL after redirect.
connectButtonFrom = location.hash.split( '&from=' )[ 1 ];

if ( 'setup' === hash ) {
if ( connectionHelpSections.length ) {
connectionHelpSections.hide();
Expand Down

0 comments on commit 664e642

Please sign in to comment.