File size: 1,188 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
39
40
41
42
43
44
45
46
import page, { type Callback } from '@automattic/calypso-router';
import { addQueryArgs } from '@wordpress/url';
import { translate } from 'i18n-calypso';
import { isPlansPageUntangled } from 'calypso/lib/plans/untangling-plans-experiment';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import { getSelectedSite } from 'calypso/state/ui/selectors';
import AddOnsMain from './main';

export const addOnsSiteSelectionHeader: Callback = ( context, next ) => {
	context.getSiteSelectionHeaderText = () => {
		return translate( 'Select a site to open {{strong}}Add-Ons{{/strong}}', {
			components: {
				strong: <strong />,
			},
		} );
	};

	next();
};

export const addOnsManagement: Callback = ( context, next ) => {
	const state = context.store.getState();
	const selectedSite = getSelectedSite( state );

	if ( ! selectedSite ) {
		page.redirect( '/add-ons' );

		return null;
	}

	if ( isPlansPageUntangled( state ) ) {
		page.redirect(
			addQueryArgs( `/plans/${ context.params.site }`, {
				...getCurrentQueryArguments( state ),
				'add-ons-modal': true,
			} )
		);

		return null;
	}

	context.primary = <AddOnsMain />;

	next();
};