File size: 3,736 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { plugins, currencyDollar, category, home, tag } from '@wordpress/icons';
import { useTranslate } from 'i18n-calypso';
import JetpackIcons from 'calypso/components/jetpack/jetpack-icons';
import GuidedTour from 'calypso/jetpack-cloud/components/guided-tour';
import NewSidebar from 'calypso/jetpack-cloud/components/sidebar';
import { itemLinkMatches } from 'calypso/my-sites/sidebar/utils';
import { isSectionNameEnabled } from 'calypso/sections-filter';
import {
	JETPACK_MANAGE_DASHBOARD_LINK,
	JETPACK_MANAGE_PLUGINS_LINK,
	JETPACK_MANAGE_LICENCES_LINK,
	JETPACK_MANAGE_BILLING_LINK,
	JETPACK_MANAGE_OVERVIEW_LINK,
	JETPACK_MANAGE_PRICING_LINK,
} from './lib/constants';
import type { MenuItemProps } from './types';

const BILLING_MENU_ITEM_ID = 'partner-portal-billing-menu-item';

const JetpackManageSidebar = ( { path }: { path: string } ) => {
	const translate = useTranslate();

	const createItem = ( props: MenuItemProps ) => ( {
		...props,
		trackEventName: 'calypso_jetpack_sidebar_menu_click',
		isSelected: itemLinkMatches( props.link, path ),
	} );

	// Overview menu items. Will be only visible if the jetpack-cloud-overview section is enabled.
	const overviewMenuItem = createItem( {
		icon: home,
		path: '/',
		link: JETPACK_MANAGE_OVERVIEW_LINK,
		title: translate( 'Overview' ),
		trackEventProps: {
			menu_item: 'Jetpack Cloud / Overview',
		},
	} );

	const dashboardMenuItem = createItem( {
		icon: category,
		path: '/',
		link: JETPACK_MANAGE_DASHBOARD_LINK,
		title: translate( 'Sites' ),
		trackEventProps: {
			menu_item: 'Jetpack Cloud / Dashboard',
		},
	} );

	const menuItems = [
		...( isSectionNameEnabled( 'jetpack-cloud-overview' ) ? [ overviewMenuItem ] : [] ),
		...[ dashboardMenuItem ],
		createItem( {
			icon: plugins,
			path: '/',
			link: JETPACK_MANAGE_PLUGINS_LINK,
			title: translate( 'Plugins' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Plugins',
			},
		} ),
		createItem( {
			icon: tag,
			path: '/',
			link: JETPACK_MANAGE_PRICING_LINK,
			title: translate( 'Pricing' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Pricing',
			},
		} ),
		createItem( {
			icon: <JetpackIcons icon="licenses_line" size={ 24 } />,
			path: '/',
			link: JETPACK_MANAGE_LICENCES_LINK,
			title: translate( 'Licenses' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Licenses',
			},
		} ),
		createItem( {
			id: BILLING_MENU_ITEM_ID,
			icon: currencyDollar,
			path: '/partner-portal/',
			link: JETPACK_MANAGE_BILLING_LINK,
			title: translate( 'Purchases' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal',
			},
			withChevron: true,
		} ),
	];
	return (
		<>
			<NewSidebar isJetpackManage path="/" menuItems={ menuItems } />

			<GuidedTour
				className="jetpack-cloud-sidebar__guided-tour"
				preferenceName="jetpack-manage-sidebar-v2-dashboard-tour"
				tours={ [
					{
						target: '.jetpack-cloud-sidebar__all-sites-icon',
						title: translate( 'Switch Sites Easily' ),
						description: translate(
							'You can navigate through your individual site views from here.'
						),
					},
					{
						target: '.jetpack-cloud-sidebar__profile-dropdown-button-icon',
						title: translate( 'Access Profile & Help Docs' ),
						description: translate(
							'Here you can log out from your account or view our help documentation.'
						),
					},
					{
						target: `#${ BILLING_MENU_ITEM_ID } svg`,
						popoverPosition: 'bottom left',
						title: translate( 'Manage Purchases' ),
						description: translate(
							'Here you can view your billing info, payment methods, invoices and more.'
						),
					},
				] }
			/>
		</>
	);
};

export default JetpackManageSidebar;