-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathindex.tsx
721 lines (667 loc) · 24.6 KB
/
index.tsx
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
import config from '@automattic/calypso-config';
import {
chooseDefaultCustomerType,
getPlan,
getPlanClass,
getPlanPath,
isFreePlan,
isPersonalPlan,
PlanSlug,
PLAN_PERSONAL,
PRODUCT_1GB_SPACE,
} from '@automattic/calypso-products';
import { Button, Spinner } from '@automattic/components';
import { WpcomPlansUI } from '@automattic/data-stores';
import styled from '@emotion/styled';
import { useDispatch } from '@wordpress/data';
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from '@wordpress/element';
import classNames from 'classnames';
import { localize, useTranslate } from 'i18n-calypso';
import page from 'page';
import { useSelector } from 'react-redux';
import QueryPlans from 'calypso/components/data/query-plans';
import QuerySitePlans from 'calypso/components/data/query-site-plans';
import QuerySites from 'calypso/components/data/query-sites';
import FormattedHeader from 'calypso/components/formatted-header';
import { retargetViewPlans } from 'calypso/lib/analytics/ad-tracking';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import {
planItem as getCartItemForPlan,
getPlanCartItem,
} from 'calypso/lib/cart-values/cart-items';
import { loadExperimentAssignment } from 'calypso/lib/explat';
import { isValidFeatureKey, FEATURES_LIST } from 'calypso/lib/plans/features-list';
import scrollIntoViewport from 'calypso/lib/scroll-into-viewport';
import PlanFeatures2023Grid from 'calypso/my-sites/plan-features-2023-grid';
import useGridPlans from 'calypso/my-sites/plan-features-2023-grid/hooks/npm-ready/data-store/use-grid-plans';
import usePlanFeaturesForGridPlans from 'calypso/my-sites/plan-features-2023-grid/hooks/npm-ready/data-store/use-plan-features-for-grid-plans';
import useRestructuredPlanFeaturesForComparisonGrid from 'calypso/my-sites/plan-features-2023-grid/hooks/npm-ready/data-store/use-restructured-plan-features-for-comparison-grid';
import PlanNotice from 'calypso/my-sites/plans-features-main/components/plan-notice';
import PlanTypeSelector from 'calypso/my-sites/plans-features-main/components/plan-type-selector';
import { getCurrentUserName } from 'calypso/state/current-user/selectors';
import canUpgradeToPlan from 'calypso/state/selectors/can-upgrade-to-plan';
import getDomainFromHomeUpsellInQuery from 'calypso/state/selectors/get-domain-from-home-upsell-in-query';
import getPreviousRoute from 'calypso/state/selectors/get-previous-route';
import isEligibleForWpComMonthlyPlan from 'calypso/state/selectors/is-eligible-for-wpcom-monthly-plan';
import { getCurrentPlan } from 'calypso/state/sites/plans/selectors';
import { getSitePlanSlug, getSiteSlug } from 'calypso/state/sites/selectors';
import useAddOns from '../add-ons/hooks/use-add-ons';
import { FreePlanFreeDomainDialog } from './components/free-plan-free-domain-dialog';
import { FreePlanPaidDomainDialog } from './components/free-plan-paid-domain-dialog';
import { LoadingPlaceHolder } from './components/loading-placeholder';
import usePricedAPIPlans from './hooks/data-store/use-priced-api-plans';
import usePricingMetaForGridPlans from './hooks/data-store/use-pricing-meta-for-grid-plans';
import useFilterPlansForPlanFeatures from './hooks/use-filter-plans-for-plan-features';
import useIsCustomDomainAllowedOnFreePlan from './hooks/use-is-custom-domain-allowed-on-free-plan';
import useIsPlanUpsellEnabledOnFreeDomain from './hooks/use-is-plan-upsell-enabled-on-free-domain';
import useObservableForOdie from './hooks/use-observable-for-odie';
import usePlanBillingPeriod from './hooks/use-plan-billing-period';
import usePlanFromUpsells from './hooks/use-plan-from-upsells';
import usePlanIntentFromSiteMeta from './hooks/use-plan-intent-from-site-meta';
import usePlanUpgradeabilityCheck from './hooks/use-plan-upgradeability-check';
import useGetFreeSubdomainSuggestion from './hooks/use-suggested-free-domain-from-paid-domain';
import type { IntervalType } from './types';
import type { DomainSuggestion } from '@automattic/data-stores';
import type { MinimalRequestCartProduct } from '@automattic/shopping-cart';
import type {
GridPlan,
PlansIntent,
} from 'calypso/my-sites/plan-features-2023-grid/hooks/npm-ready/data-store/use-grid-plans';
import type {
DataResponse,
PlanActionOverrides,
} from 'calypso/my-sites/plan-features-2023-grid/types';
import type { IAppState } from 'calypso/state/types';
import './style.scss';
const SPOTLIGHT_ENABLED_INTENTS = [ 'plans-default-wpcom' ];
const FreePlanSubHeader = styled.p`
margin: -32px 0 40px 0;
color: var( --studio-gray-60 );
font-size: 1rem;
text-align: center;
button.is-borderless {
font-weight: 500;
color: var( --studio-gray-90 );
text-decoration: underline;
font-size: 16px;
padding: 0;
}
@media ( max-width: 960px ) {
margin-top: -16px;
}
`;
export interface PlansFeaturesMainProps {
siteId?: number | null;
intent?: PlansIntent | null;
isInSignup?: boolean;
plansWithScroll?: boolean;
customerType?: string;
basePlansPath?: string;
selectedPlan?: PlanSlug;
selectedFeature?: string;
onUpgradeClick?: ( cartItems?: MinimalRequestCartProduct[] | null ) => void;
redirectToAddDomainFlow?: boolean;
hidePlanTypeSelector?: boolean;
paidDomainName?: string;
freeSubdomain?: string;
siteTitle?: string;
signupFlowUserName?: string;
flowName?: string | null;
removePaidDomain?: () => void;
setSiteUrlAsFreeDomainSuggestion?: ( freeDomainSuggestion: DomainSuggestion ) => void;
intervalType?: IntervalType;
planTypeSelector?: 'customer' | 'interval';
withDiscount?: string;
discountEndDate?: Date;
hidePlansFeatureComparison?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hideFreePlan?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hidePersonalPlan?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hidePremiumPlan?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hideBusinessPlan?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hideEcommercePlan?: boolean;
/**
* @deprecated use intent mechanism instead
*/
hideEnterprisePlan?: boolean;
isStepperUpgradeFlow?: boolean;
isLaunchPage?: boolean | null;
isReskinned?: boolean;
isPlansInsideStepper?: boolean;
showBiennialToggle?: boolean;
hideUnavailableFeatures?: boolean; // used to hide features that are not available, instead of strike-through as explained in #76206
showLegacyStorageFeature?: boolean;
isSpotlightOnCurrentPlan?: boolean;
}
const SecondaryFormattedHeader = ( { siteSlug }: { siteSlug?: string | null } ) => {
const translate = useTranslate();
const headerText = translate( 'Upgrade your plan to access this feature and more' );
const subHeaderText = (
<Button className="plans-features-main__view-all-plans is-link" href={ `/plans/${ siteSlug }` }>
{ translate( 'View all plans' ) }
</Button>
);
return (
<FormattedHeader
headerText={ headerText }
subHeaderText={ subHeaderText }
compactOnMobile
isSecondary
/>
);
};
const PlansFeaturesMain = ( {
paidDomainName,
freeSubdomain: signupFlowSubdomain,
siteTitle,
signupFlowUserName,
flowName,
removePaidDomain,
setSiteUrlAsFreeDomainSuggestion,
onUpgradeClick,
hidePlanTypeSelector,
redirectToAddDomainFlow,
siteId,
selectedPlan,
basePlansPath,
selectedFeature,
plansWithScroll,
withDiscount,
discountEndDate,
hideFreePlan,
hidePersonalPlan,
hidePremiumPlan,
hideBusinessPlan,
hideEcommercePlan,
hideEnterprisePlan,
intent: intentFromProps, // do not set a default value for this prop here
isReskinned,
showBiennialToggle,
customerType = 'personal',
planTypeSelector = 'interval',
intervalType = 'yearly',
hidePlansFeatureComparison = false,
hideUnavailableFeatures = false,
isInSignup = false,
isPlansInsideStepper = false,
isStepperUpgradeFlow = false,
isLaunchPage = false,
showLegacyStorageFeature = false,
isSpotlightOnCurrentPlan,
}: PlansFeaturesMainProps ) => {
const [ isFreePlanPaidDomainDialogOpen, setIsFreePlanPaidDomainDialogOpen ] = useState( false );
const [ isFreePlanFreeDomainDialogOpen, setIsFreePlanFreeDomainDialogOpen ] = useState( false );
const [ showPlansComparisonGrid, setShowPlansComparisonGrid ] = useState( false );
const [ masterbarHeight, setMasterbarHeight ] = useState( 0 );
const translate = useTranslate();
const plansComparisonGridRef = useRef< HTMLDivElement >( null );
const storageAddOns = useAddOns( siteId ?? undefined, isInSignup ).filter(
( addOn ) => addOn?.productSlug === PRODUCT_1GB_SPACE
);
const currentPlan = useSelector( ( state: IAppState ) => getCurrentPlan( state, siteId ) );
const eligibleForWpcomMonthlyPlans = useSelector( ( state: IAppState ) =>
isEligibleForWpComMonthlyPlan( state, siteId )
);
const siteSlug = useSelector( ( state: IAppState ) => getSiteSlug( state, siteId ) );
const sitePlanSlug = useSelector( ( state: IAppState ) =>
siteId ? getSitePlanSlug( state, siteId ) : null
);
const userCanUpgradeToPersonalPlan = useSelector(
( state: IAppState ) => siteId && canUpgradeToPlan( state, siteId, PLAN_PERSONAL )
);
const previousRoute = useSelector( ( state: IAppState ) => getPreviousRoute( state ) );
const isCustomDomainAllowedOnFreePlan = useIsCustomDomainAllowedOnFreePlan(
flowName,
!! paidDomainName
);
const isPlanUpsellEnabledOnFreeDomain = useIsPlanUpsellEnabledOnFreeDomain(
flowName,
!! paidDomainName
);
const { setShowDomainUpsellDialog } = useDispatch( WpcomPlansUI.store );
const domainFromHomeUpsellFlow = useSelector( getDomainFromHomeUpsellInQuery );
const showUpgradeableStorage = config.isEnabled( 'plans/upgradeable-storage' );
const observableForOdieRef = useObservableForOdie();
const toggleShowPlansComparisonGrid = () => {
setShowPlansComparisonGrid( ! showPlansComparisonGrid );
};
const showDomainUpsellDialog = useCallback( () => {
setShowDomainUpsellDialog( true );
}, [ setShowDomainUpsellDialog ] );
const currentUserName = useSelector( getCurrentUserName );
const { wpcomFreeDomainSuggestion, invalidateDomainSuggestionCache } =
useGetFreeSubdomainSuggestion(
paidDomainName || siteTitle || signupFlowUserName || currentUserName
);
// the A/A tests for identifying SRM issue. See peP6yB-11Y-p2
// We can use `useExperiment()` and its `isEligible` check to avoid the condition, but it's intentional to use loadExperimentAssignment() here
// to be consistent with the other A/A tests.
useEffect( () => {
if ( flowName === 'onboarding' ) {
loadExperimentAssignment( 'calypso_srm_test_plans_page_view_free_plan_modal_view' );
loadExperimentAssignment( 'calypso_srm_test_plans_page_view_free_plan_button_click' );
}
}, [] );
const resolvedSubdomainName: DataResponse< string > = {
isLoading: signupFlowSubdomain ? false : wpcomFreeDomainSuggestion.isLoading,
result: signupFlowSubdomain
? signupFlowSubdomain
: wpcomFreeDomainSuggestion.result?.domain_name,
};
const isDisplayingPlansNeededForFeature = () => {
if (
selectedFeature &&
isValidFeatureKey( selectedFeature ) &&
selectedPlan &&
getPlan( selectedPlan ) &&
! isPersonalPlan( selectedPlan ) &&
( 'interval' === planTypeSelector || ! previousRoute.startsWith( '/plans/' ) )
) {
return true;
}
return false;
};
const toggleIsFreePlanPaidDomainDialogOpen = () => {
setIsFreePlanPaidDomainDialogOpen( ! isFreePlanPaidDomainDialogOpen );
};
const handleUpgradeClick = ( cartItems?: MinimalRequestCartProduct[] | null ) => {
const cartItemForPlan = getPlanCartItem( cartItems );
// `cartItemForPlan` is empty if Free plan is selected. Show `FreePlanPaidDomainDialog`
// in that case and exit. `FreePlanPaidDomainDialog` takes over from there.
// It only applies to main onboarding flow and the paid media flow at the moment.
// Standardizing it or not is TBD; see Automattic/growth-foundations#63 and pdgrnI-2nV-p2#comment-4110 for relevant discussion.
if ( ! cartItemForPlan ) {
recordTracksEvent( 'calypso_signup_free_plan_click' );
if ( paidDomainName ) {
toggleIsFreePlanPaidDomainDialogOpen();
return;
}
if ( isPlanUpsellEnabledOnFreeDomain.result ) {
setIsFreePlanFreeDomainDialogOpen( true );
return;
}
}
if ( onUpgradeClick ) {
onUpgradeClick( cartItems );
return;
}
const planPath = cartItemForPlan?.product_slug
? getPlanPath( cartItemForPlan.product_slug )
: '';
const checkoutUrlWithArgs = `/checkout/${ siteSlug }/${ planPath }`;
page( checkoutUrlWithArgs );
};
const term = usePlanBillingPeriod( {
intervalType,
...( selectedPlan ? { defaultValue: getPlan( selectedPlan )?.term } : {} ),
} );
// TODO: plans from upsell takes precedence for setting intent right now
// - this is currently set to the default wpcom set until we have updated tailored features for all plans
// - at which point, we'll inject the upsell plan to the tailored plans mix instead
const intentFromSiteMeta = usePlanIntentFromSiteMeta();
const planFromUpsells = usePlanFromUpsells();
const intent = planFromUpsells
? 'plans-default-wpcom'
: intentFromProps || intentFromSiteMeta.intent || 'plans-default-wpcom';
const gridPlans = useGridPlans( {
allFeaturesList: FEATURES_LIST,
usePricedAPIPlans,
usePricingMetaForGridPlans,
selectedFeature,
term,
intent,
selectedPlan,
sitePlanSlug,
hideEnterprisePlan,
usePlanUpgradeabilityCheck,
showLegacyStorageFeature,
isSubdomainNotGenerated: ! resolvedSubdomainName.result,
storageAddOns,
} );
const planFeaturesForFeaturesGrid = usePlanFeaturesForGridPlans( {
planSlugs: gridPlans?.map( ( gridPlan ) => gridPlan.planSlug ) || [],
allFeaturesList: FEATURES_LIST,
intent,
selectedFeature,
showLegacyStorageFeature,
isInSignup,
} );
const planFeaturesForComparisonGrid = useRestructuredPlanFeaturesForComparisonGrid( {
planSlugs: gridPlans?.map( ( gridPlan ) => gridPlan.planSlug ) || [],
allFeaturesList: FEATURES_LIST,
intent,
selectedFeature,
showLegacyStorageFeature,
} );
// TODO: `useFilterPlansForPlanFeatures` should gradually deprecate and whatever remains to fall into the `useGridPlans` hook
const filteredPlansForPlanFeatures = useFilterPlansForPlanFeatures( {
plans: gridPlans || [],
isDisplayingPlansNeededForFeature: isDisplayingPlansNeededForFeature(),
selectedPlan,
hideFreePlan,
hidePersonalPlan,
hidePremiumPlan,
hideBusinessPlan,
hideEcommercePlan,
} );
// we neeed only the visible ones for comparison grid (these should extend into plans-ui data store selectors)
const gridPlansForComparisonGrid = filteredPlansForPlanFeatures.reduce( ( acc, gridPlan ) => {
if ( gridPlan.isVisible ) {
return [
...acc,
{
...gridPlan,
features: planFeaturesForComparisonGrid[ gridPlan.planSlug ],
},
];
}
return acc;
}, [] as GridPlan[] );
// we neeed only the visible ones for features grid (these should extend into plans-ui data store selectors)
const gridPlansForFeaturesGrid = filteredPlansForPlanFeatures.reduce( ( acc, gridPlan ) => {
if ( gridPlan.isVisible ) {
return [
...acc,
{
...gridPlan,
features: planFeaturesForFeaturesGrid[ gridPlan.planSlug ],
},
];
}
return acc;
}, [] as GridPlan[] );
// If advertising plans for a certain feature, ensure user has pressed "View all plans" before they can see others
let hidePlanSelector = 'customer' === planTypeSelector && isDisplayingPlansNeededForFeature();
// In the "purchase a plan and free domain" flow we do not want to show
// monthly plans because monthly plans do not come with a free domain.
if ( redirectToAddDomainFlow !== undefined || hidePlanTypeSelector ) {
hidePlanSelector = true;
}
let _customerType = chooseDefaultCustomerType( {
currentCustomerType: customerType,
selectedPlan,
currentPlan: { productSlug: currentPlan?.productSlug },
} );
// Make sure the plans for the default customer type can be purchased.
if ( _customerType === 'personal' && userCanUpgradeToPersonalPlan ) {
_customerType = 'business';
}
const planTypeSelectorProps = {
basePlansPath,
isStepperUpgradeFlow,
isInSignup,
eligibleForWpcomMonthlyPlans,
isPlansInsideStepper,
intervalType,
customerType: _customerType,
siteSlug,
selectedPlan,
selectedFeature,
showBiennialToggle,
kind: planTypeSelector,
plans: gridPlansForFeaturesGrid.map( ( gridPlan ) => gridPlan.planSlug ),
};
/**
* The effects on /plans page need to be checked if this variable is initialized
*/
let planActionOverrides: PlanActionOverrides | undefined;
if ( isInSignup ) {
planActionOverrides = {
loggedInFreePlan: {
status:
isPlanUpsellEnabledOnFreeDomain.isLoading || wpcomFreeDomainSuggestion.isLoading
? 'blocked'
: 'enabled',
},
};
}
if ( sitePlanSlug && isFreePlan( sitePlanSlug ) ) {
planActionOverrides = {
loggedInFreePlan: {
status:
isPlanUpsellEnabledOnFreeDomain.isLoading || wpcomFreeDomainSuggestion.isLoading
? 'blocked'
: 'enabled',
callback: () => {
page.redirect( `/add-ons/${ siteSlug }` );
},
text: translate( 'Manage add-ons', { context: 'verb' } ),
},
};
if ( domainFromHomeUpsellFlow ) {
planActionOverrides.loggedInFreePlan = {
...planActionOverrides.loggedInFreePlan,
callback: showDomainUpsellDialog,
text: translate( 'Keep my plan', { context: 'verb' } ),
};
}
}
/**
* The spotlight in smaller grids looks broken.
* So for now we only allow the spotlight in the default grid plans grid where we display all 6 plans.
* In order to accommodate this for other variations with lesser number of plans the design needs to be reworked.
* Or else the intent needs to be explicitly allow the spotlight to be shown in this relevant intent.
* Eventually once the spotlight card is made responsive this flag can be removed.
* Check : https://github.com/Automattic/wp-calypso/pull/80232 for more details.
*/
const gridPlanForSpotlight =
sitePlanSlug && isSpotlightOnCurrentPlan && SPOTLIGHT_ENABLED_INTENTS.includes( intent )
? gridPlansForFeaturesGrid.find(
( { planSlug } ) => getPlanClass( planSlug ) === getPlanClass( sitePlanSlug )
)
: undefined;
/**
* Calculates the height of the masterbar if it exists, and passes it to the component as an offset
* for the sticky CTA bar.
*/
useLayoutEffect( () => {
const masterbarElement = document.querySelector< HTMLDivElement >( 'header.masterbar' );
if ( ! masterbarElement ) {
return;
}
if ( ! window.ResizeObserver ) {
setMasterbarHeight( masterbarElement.offsetHeight );
return;
}
let lastHeight = masterbarElement.offsetHeight;
const observer = new ResizeObserver(
( [ masterbar ]: Parameters< ResizeObserverCallback >[ 0 ] ) => {
const currentHeight = masterbar.contentRect.height;
if ( currentHeight !== lastHeight ) {
setMasterbarHeight( currentHeight );
lastHeight = currentHeight;
}
}
);
observer.observe( masterbarElement );
return () => {
observer.disconnect();
};
}, [] );
useLayoutEffect( () => {
if ( showPlansComparisonGrid ) {
setTimeout( () => {
if ( plansComparisonGridRef.current ) {
scrollIntoViewport( plansComparisonGridRef.current, {
behavior: 'smooth',
scrollMode: 'if-needed',
block: 'nearest',
inline: 'nearest',
} );
}
} );
}
}, [ showPlansComparisonGrid ] );
useEffect( () => {
recordTracksEvent( 'calypso_wp_plans_test_view' );
retargetViewPlans();
}, [] );
const isLoadingGridPlans = Boolean( intentFromSiteMeta.processing || ! gridPlans );
return (
<div
className={ classNames( 'plans-features-main', 'is-pricing-grid-2023-plans-features-main' ) }
>
<QueryPlans />
<QuerySites siteId={ siteId } />
<QuerySitePlans siteId={ siteId } />
{ paidDomainName && isFreePlanPaidDomainDialogOpen && (
<FreePlanPaidDomainDialog
paidDomainName={ paidDomainName }
wpcomFreeDomainSuggestion={ wpcomFreeDomainSuggestion }
suggestedPlanSlug={ PLAN_PERSONAL }
isCustomDomainAllowedOnFreePlan={ isCustomDomainAllowedOnFreePlan }
onClose={ toggleIsFreePlanPaidDomainDialogOpen }
onFreePlanSelected={ () => {
if ( isCustomDomainAllowedOnFreePlan.isLoading ) {
return;
}
if ( ! isCustomDomainAllowedOnFreePlan.result ) {
removePaidDomain?.();
}
// Since this domain will not be available after it is selected, invalidate the cache.
invalidateDomainSuggestionCache();
wpcomFreeDomainSuggestion.result &&
setSiteUrlAsFreeDomainSuggestion?.( wpcomFreeDomainSuggestion.result );
onUpgradeClick?.( null );
} }
onPlanSelected={ () => {
const cartItemForPlan = getCartItemForPlan( PLAN_PERSONAL );
const cartItems = cartItemForPlan ? [ cartItemForPlan ] : null;
onUpgradeClick?.( cartItems );
} }
/>
) }
{ isFreePlanFreeDomainDialogOpen && (
<FreePlanFreeDomainDialog
suggestedPlanSlug={ PLAN_PERSONAL }
freeSubdomain={ resolvedSubdomainName }
onClose={ () => setIsFreePlanFreeDomainDialogOpen( false ) }
onFreePlanSelected={ () => {
if ( ! signupFlowSubdomain && wpcomFreeDomainSuggestion.result ) {
setSiteUrlAsFreeDomainSuggestion?.( wpcomFreeDomainSuggestion.result );
}
invalidateDomainSuggestionCache();
onUpgradeClick?.( null );
} }
onPlanSelected={ () => {
if ( ! signupFlowSubdomain && wpcomFreeDomainSuggestion.result ) {
setSiteUrlAsFreeDomainSuggestion?.( wpcomFreeDomainSuggestion.result );
}
invalidateDomainSuggestionCache();
const cartItemForPlan = getCartItemForPlan( PLAN_PERSONAL );
const cartItems = cartItemForPlan ? [ cartItemForPlan ] : null;
onUpgradeClick?.( cartItems );
} }
/>
) }
{ siteId && (
<PlanNotice
visiblePlans={ gridPlansForFeaturesGrid.map( ( gridPlan ) => gridPlan.planSlug ) }
siteId={ siteId }
isInSignup={ isInSignup }
{ ...( withDiscount &&
discountEndDate && {
discountInformation: {
withDiscount,
discountEndDate,
},
} ) }
/>
) }
{ intent === 'plans-paid-media' &&
( isPlanUpsellEnabledOnFreeDomain.isLoading ? (
<FreePlanSubHeader>
{ translate( `Unlock a powerful bundle of features. Or {{loader}}{{/loader}}`, {
components: {
loader: (
<LoadingPlaceHolder
display="inline-block"
width="155px"
height="15px"
borderRadius="2px"
/>
),
},
} ) }
</FreePlanSubHeader>
) : (
<FreePlanSubHeader>
{ translate(
`Unlock a powerful bundle of features. Or {{link}}start with a free plan{{/link}}.`,
{
components: {
link: <Button onClick={ () => handleUpgradeClick() } borderless />,
},
}
) }
</FreePlanSubHeader>
) ) }
{ isDisplayingPlansNeededForFeature() && <SecondaryFormattedHeader siteSlug={ siteSlug } /> }
{ ( isLoadingGridPlans || resolvedSubdomainName.isLoading ) && <Spinner size={ 30 } /> }
{ ! isLoadingGridPlans && ! resolvedSubdomainName.isLoading && (
<>
{ ! hidePlanSelector && <PlanTypeSelector { ...planTypeSelectorProps } /> }
<div
className={ classNames(
'plans-features-main__group',
'is-wpcom',
'is-2023-pricing-grid',
{
'is-scrollable': plansWithScroll,
}
) }
data-e2e-plans="wpcom"
>
<PlanFeatures2023Grid
gridPlansForFeaturesGrid={ gridPlansForFeaturesGrid }
gridPlansForComparisonGrid={ gridPlansForComparisonGrid }
gridPlanForSpotlight={ gridPlanForSpotlight }
paidDomainName={ paidDomainName }
wpcomFreeDomainSuggestion={ wpcomFreeDomainSuggestion }
isCustomDomainAllowedOnFreePlan={ isCustomDomainAllowedOnFreePlan }
isInSignup={ isInSignup }
isLaunchPage={ isLaunchPage }
onUpgradeClick={ handleUpgradeClick }
flowName={ flowName }
selectedFeature={ selectedFeature }
selectedPlan={ selectedPlan }
siteId={ siteId }
isReskinned={ isReskinned }
intervalType={ intervalType }
hidePlansFeatureComparison={ hidePlansFeatureComparison }
hideUnavailableFeatures={ hideUnavailableFeatures }
currentSitePlanSlug={ sitePlanSlug }
planActionOverrides={ planActionOverrides }
intent={ intent }
showLegacyStorageFeature={ showLegacyStorageFeature }
showUpgradeableStorage={ showUpgradeableStorage }
stickyRowOffset={ masterbarHeight }
usePricingMetaForGridPlans={ usePricingMetaForGridPlans }
allFeaturesList={ FEATURES_LIST }
showPlansComparisonGrid={ showPlansComparisonGrid }
toggleShowPlansComparisonGrid={ toggleShowPlansComparisonGrid }
planTypeSelectorProps={ planTypeSelectorProps }
ref={ plansComparisonGridRef }
observableForOdieRef={ observableForOdieRef }
/>
</div>
</>
) }
</div>
);
};
export default localize( PlansFeaturesMain );