File size: 2,540 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
import page from '@automattic/calypso-router';
import { chevronLeft, formatListBulletsRTL, payment, receipt, store } from '@wordpress/icons';
import { useTranslate } from 'i18n-calypso';
import NewSidebar from 'calypso/jetpack-cloud/components/sidebar';
import { itemLinkMatches } from 'calypso/my-sites/sidebar/utils';
import { useDispatch } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import {
	JETPACK_MANAGE_BILLING_LINK,
	JETPACK_MANAGE_COMPANY_DETAILS_LINK,
	JETPACK_MANAGE_DASHBOARD_LINK,
	JETPACK_MANAGE_INVOICES_LINK,
	JETPACK_MANAGE_PARTNER_PORTAL_LINK,
	JETPACK_MANAGE_PAYMENT_METHODS_LINK,
} from './lib/constants';
import { MenuItemProps } from './types';

const PurchasesSidebar = ( { path }: { path: string } ) => {
	const translate = useTranslate();
	const dispatch = useDispatch();

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

	const menuItems = [
		createItem( {
			icon: store,
			link: JETPACK_MANAGE_BILLING_LINK,
			title: translate( 'Billing' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Billing',
			},
		} ),
		createItem( {
			icon: payment,
			link: JETPACK_MANAGE_PAYMENT_METHODS_LINK,
			title: translate( 'Payment Methods' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Payment Methods',
			},
		} ),
		createItem( {
			icon: receipt,
			link: JETPACK_MANAGE_INVOICES_LINK,
			title: translate( 'Invoices' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Invoices',
			},
		} ),
		createItem( {
			icon: formatListBulletsRTL,
			link: JETPACK_MANAGE_COMPANY_DETAILS_LINK,
			title: translate( 'Company Details' ),
			trackEventProps: {
				menu_item: 'Jetpack Cloud / Partner Portal / Company Details',
			},
		} ),
	];

	return (
		<NewSidebar
			isJetpackManage
			path={ JETPACK_MANAGE_PARTNER_PORTAL_LINK }
			menuItems={ menuItems }
			title={ translate( 'Purchases' ) }
			description={ translate( 'Manage all your billing related settings from one place.' ) }
			backButtonProps={ {
				label: translate( 'Back to Sites' ),
				icon: chevronLeft,
				onClick: () => {
					dispatch(
						recordTracksEvent( 'calypso_jetpack_sidebar_new_purchases_back_button_click' )
					);

					page( JETPACK_MANAGE_DASHBOARD_LINK );
				},
			} }
		/>
	);
};

export default PurchasesSidebar;