File size: 1,160 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { PLAN_ECOMMERCE_TRIAL_MONTHLY, isFreePlanProduct } from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { getSelectedSite, getSelectedPurchase } from 'calypso/state/ui/selectors';
import CurrentPlan from './';

export function currentPlan( context, next ) {
	const state = context.store.getState();

	const selectedSite = getSelectedSite( state );
	const purchase = getSelectedPurchase( state );

	if ( ! selectedSite ) {
		page.redirect( '/plans/' );

		return null;
	}

	const isFreePlan = isFreePlanProduct( selectedSite.plan );
	const currentPlanSlug = selectedSite?.plan?.product_slug ?? '';
	const isEcommerceTrial = currentPlanSlug === PLAN_ECOMMERCE_TRIAL_MONTHLY;
	const isEntrepreneurTrial = isEcommerceTrial && ! purchase?.isWooExpressTrial;

	if ( isFreePlan || isEntrepreneurTrial ) {
		page.redirect( `/plans/${ selectedSite.slug }` );

		return null;
	}

	const product = context.query.product;
	const requestThankYou = context.query.hasOwnProperty( 'thank-you' );

	context.primary = (
		<CurrentPlan path={ context.path } product={ product } requestThankYou={ requestThankYou } />
	);

	next();
}