File size: 3,969 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
130
131
132
import { FEATURE_SFTP, PLAN_BUSINESS, WPCOM_PLANS, getPlan } from '@automattic/calypso-products';
import { addQueryArgs } from '@wordpress/url';
import { useTranslate } from 'i18n-calypso';
import UpsellNudge from 'calypso/blocks/upsell-nudge';
import { preventWidows } from 'calypso/lib/formatting';
import iconCloud from './icons/icon-cloud.svg';
import iconComments from './icons/icon-comments.svg';
import iconDatabase from './icons/icon-database.svg';
import iconServerRacks from './icons/icon-server-racks.svg';
import iconSSH from './icons/icon-ssh.svg';
import iconTerminal from './icons/icon-terminal.svg';
import type { TranslateResult } from 'i18n-calypso';
import './style.scss';

interface FeatureListItem {
	title: string;
	description: string;
	icon: string;
}

interface HostingUpsellNudgeTargetPlan {
	callToAction: TranslateResult;
	feature?: string;
	href: string;
	plan?: typeof WPCOM_PLANS;
	title: TranslateResult;
}

interface HostingUpsellNudgeProps {
	siteId: number | null;
	targetPlan?: HostingUpsellNudgeTargetPlan;
	secondaryCallToAction?: string;
	secondaryOnClick?: () => void;
}

export function HostingUpsellNudge( { siteId, targetPlan }: HostingUpsellNudgeProps ) {
	const translate = useTranslate();
	const features = useFeatureList();
	const callToActionText = translate( 'Upgrade to %(businessPlanName)s Plan', {
		args: { businessPlanName: getPlan( PLAN_BUSINESS )?.getTitle() ?? '' },
	} );
	const titleText = translate(
		'Upgrade to the %(businessPlanName)s plan to access all hosting features:',
		{
			args: { businessPlanName: getPlan( PLAN_BUSINESS )?.getTitle() ?? '' },
		}
	);
	const callToAction = targetPlan ? targetPlan.callToAction : callToActionText;
	const feature = targetPlan ? targetPlan.feature : FEATURE_SFTP;
	const href = targetPlan
		? targetPlan.href
		: addQueryArgs( `/checkout/${ siteId }/business`, {
				redirect_to: `/hosting-config/${ siteId }`,
		  } );
	const plan = targetPlan ? targetPlan.plan : PLAN_BUSINESS;
	const title = targetPlan ? targetPlan.title : titleText;

	return (
		<UpsellNudge
			className="hosting-upsell-nudge"
			compactButton={ false }
			title={ title }
			event="calypso_hosting_configuration_upgrade_click"
			href={ href }
			callToAction={ callToAction }
			plan={ plan as string }
			feature={ feature }
			showIcon
			list={ features }
			renderListItem={ ( { icon, title, description }: FeatureListItem ) => (
				<>
					<div className="hosting-upsell-nudge__feature-title">
						<img className="hosting-upsell-nudge__feature-icon" src={ icon } alt="" /> { title }
					</div>
					<div className="hosting-upsell-nudge__feature-description">
						{ preventWidows( description ) }
					</div>
				</>
			) }
		/>
	);
}

function useFeatureList(): FeatureListItem[] {
	const translate = useTranslate();

	return [
		{
			title: translate( 'SFTP' ),
			description: translate(
				'Streamline your workflow and edit your files with precision using an SFTP client.'
			),
			icon: iconCloud,
		},
		{
			title: translate( 'CLI Access' ),
			description: translate(
				'Use WP-CLI to manage plugins and users, or automate repetitive tasks from your terminal.'
			),
			icon: iconTerminal,
		},
		{
			title: translate( 'SSH' ),
			description: translate(
				'Take control of your website’s performance and security using SSH.'
			),
			icon: iconSSH,
		},
		{
			title: translate( 'Pick Your Data Center' ),
			description: translate(
				'Choose a primary data center for your site while still enjoying geo-redundant architecture.'
			),
			icon: iconServerRacks,
		},
		{
			title: translate( 'Database Access' ),
			description: translate(
				'Manage your website’s data easily, using phpMyAdmin to inspect tables and run queries.'
			),
			icon: iconDatabase,
		},
		{
			title: translate( 'Live Support' ),
			description: translate(
				'Whenever you’re stuck, our Happiness Engineers have the answers on hand.'
			),
			icon: iconComments,
		},
	];
}