| import { isEnabled } from '@automattic/calypso-config'; |
| import { PLAN_100_YEARS, isValidFeatureKey } from '@automattic/calypso-products'; |
| import page from '@automattic/calypso-router'; |
| import { isPlansPageUntangled } from 'calypso/lib/plans/untangling-plans-experiment'; |
| import { productSelect } from 'calypso/my-sites/plans/jetpack-plans/controller'; |
| import setJetpackPlansHeader from 'calypso/my-sites/plans/jetpack-plans/plans-header'; |
| import { PLAN } from 'calypso/sites/components/site-preview-pane/constants'; |
| import { siteDashboard } from 'calypso/sites/controller'; |
| import isSiteWpcom from 'calypso/state/selectors/is-site-wpcom'; |
| import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors'; |
| import Plans from './main'; |
|
|
| function showJetpackPlans( context ) { |
| const state = context.store.getState(); |
| const siteId = getSelectedSiteId( state ); |
| const isWpcom = isSiteWpcom( state, siteId ); |
| return ! isWpcom; |
| } |
|
|
| function is100YearPlanUser( context ) { |
| const state = context.store.getState(); |
| const selectedSite = getSelectedSite( state ); |
| return selectedSite?.plan?.product_slug === PLAN_100_YEARS; |
| } |
|
|
| export function plans( context, next ) { |
| |
| if ( is100YearPlanUser( context ) && ! isEnabled( 'untangling/plans' ) ) { |
| return page.redirect( `/plans/my-plan/${ context.params.site }` ); |
| } |
| if ( showJetpackPlans( context ) ) { |
| if ( context.params.intervalType ) { |
| return page.redirect( `/plans/${ context.params.site }` ); |
| } |
| setJetpackPlansHeader( context ); |
| return productSelect( '/plans' )( context, next ); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| const coupon = context.query.coupon || context.query.discount; |
|
|
| context.primary = ( |
| <Plans |
| context={ context } |
| intervalType={ context.params.intervalType } |
| customerType={ context.query.customerType } |
| selectedFeature={ context.query.feature } |
| selectedPlan={ context.query.plan } |
| coupon={ coupon } |
| discountEndDate={ context.query.ts } |
| redirectTo={ context.query.redirect_to } |
| redirectToAddDomainFlow={ |
| context.query.addDomainFlow !== undefined |
| ? context.query.addDomainFlow === 'true' |
| : undefined |
| } |
| domainAndPlanPackage={ context.query.domainAndPlanPackage === 'true' } |
| jetpackAppPlans={ context.query.jetpackAppPlans === 'true' } |
| /> |
| ); |
|
|
| if ( isPlansPageUntangled( context.store.getState() ) ) { |
| siteDashboard( PLAN )( context, next ); |
| } else { |
| next(); |
| } |
| } |
|
|
| export function features( context ) { |
| const { feature, domain } = context.params; |
| let comparePath = domain ? `/plans/${ domain }` : '/plans/'; |
|
|
| if ( isValidFeatureKey( feature ) ) { |
| comparePath += '?feature=' + feature; |
| } |
|
|
| |
| page.redirect( comparePath ); |
| } |
|
|
| export function redirectToCheckout( context ) { |
| |
| page.redirect( `/checkout/${ context.params.domain }/${ context.params.plan }` ); |
| } |
|
|
| export function redirectToPlans( context ) { |
| const siteDomain = context.params.domain; |
|
|
| if ( siteDomain ) { |
| return page.redirect( `/plans/${ siteDomain }` ); |
| } |
|
|
| return page.redirect( '/plans' ); |
| } |
|
|
| export function redirectToPlansIfNotJetpack( context, next ) { |
| if ( ! showJetpackPlans( context ) ) { |
| page.redirect( `/plans/${ context.params.site }` ); |
| } |
| next(); |
| } |
|
|
| export const redirectIfInvalidInterval = ( context, next ) => { |
| const { intervalType } = context.params; |
| const state = context.store.getState(); |
| const selectedSite = getSelectedSite( state ); |
|
|
| |
| if ( intervalType && ! [ 'monthly', 'yearly', '2yearly', '3yearly' ].includes( intervalType ) ) { |
| page.redirect( selectedSite ? `/plans/yearly/${ selectedSite.slug }` : '/plans' ); |
| return null; |
| } |
|
|
| next(); |
| }; |
|
|