Skip to content

Commit

Permalink
Migration Trial: fix migrate and expired plan redirect conflicts (#81457
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ouikhuan authored and pull[bot] committed Apr 29, 2024
1 parent 5d761b9 commit 1934ce2
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions client/my-sites/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,37 +287,35 @@ function isPathAllowedForDIFMInProgressSite( path, slug, domains, contextParams
function onSelectedSiteAvailable( context ) {
const state = context.store.getState();
const selectedSite = getSelectedSite( state );

// If migration is in progress, only /migrate paths should be loaded for the site
const isMigrationInProgress = isSiteMigrationInProgress( state, selectedSite.ID );

if ( isMigrationInProgress && ! startsWith( context.pathname, '/migrate/' ) ) {
page.redirect( `/migrate/${ selectedSite.slug }` );
return false;
}
// Use getSitePlanSlug() as it ignores expired plans.
const currentPlanSlug = getSitePlanSlug( state, selectedSite.ID );

// If we had a trial plan, and the user doesn't have an active paid plan, redirect to fullpage trial expired page.
if ( wasTrialSite( state, selectedSite.ID ) ) {
// Use getSitePlanSlug() as it ignores expired plans.
const currentPlanSlug = getSitePlanSlug( state, selectedSite.ID );

if ( [ PLAN_FREE, PLAN_JETPACK_FREE ].includes( currentPlanSlug ) ) {
const permittedPathPrefixes = [
'/checkout/',
'/domains/',
'/email/',
'/export/',
'/plans/my-plan/trial-expired/',
'/purchases/',
'/settings/delete-site/',
];

if ( ! permittedPathPrefixes.some( ( prefix ) => context.pathname.startsWith( prefix ) ) ) {
page.redirect( `/plans/my-plan/trial-expired/${ selectedSite.slug }` );
return false;
}

context.hideLeftNavigation = true;
if (
wasTrialSite( state, selectedSite.ID ) &&
[ PLAN_FREE, PLAN_JETPACK_FREE ].includes( currentPlanSlug )
) {
const permittedPathPrefixes = [
'/checkout/',
'/domains/',
'/email/',
'/export/',
'/plans/my-plan/trial-expired/',
'/purchases/',
'/settings/delete-site/',
];

if ( ! permittedPathPrefixes.some( ( prefix ) => context.pathname.startsWith( prefix ) ) ) {
page.redirect( `/plans/my-plan/trial-expired/${ selectedSite.slug }` );
return false;
}
context.hideLeftNavigation = true;
} else {
// If migration is in progress, only /migrate paths should be loaded for the site
const isMigrationInProgress = isSiteMigrationInProgress( state, selectedSite.ID );
if ( isMigrationInProgress && ! startsWith( context.pathname, '/migrate/' ) ) {
page.redirect( `/migrate/${ selectedSite.slug }` );
return false;
}
}

Expand Down

0 comments on commit 1934ce2

Please sign in to comment.