File size: 19,960 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 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 | import { isEnabled } from '@automattic/calypso-config';
import {
FEATURE_LEGACY_STORAGE_200GB,
getIntervalTypeForTerm,
getPlan,
is100Year,
isFreePlanProduct,
PLAN_ECOMMERCE,
PLAN_ECOMMERCE_TRIAL_MONTHLY,
PLAN_HOSTING_TRIAL_MONTHLY,
PLAN_MIGRATION_TRIAL_MONTHLY,
PLAN_WOOEXPRESS_MEDIUM,
PLAN_WOOEXPRESS_MEDIUM_MONTHLY,
PLAN_WOOEXPRESS_SMALL,
PLAN_WOOEXPRESS_SMALL_MONTHLY,
} from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { WpcomPlansUI, Plans } from '@automattic/data-stores';
import { withShoppingCart } from '@automattic/shopping-cart';
import { useDispatch } from '@wordpress/data';
import { addQueryArgs, getQueryArg } from '@wordpress/url';
import { localize, useTranslate } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import Banner from 'calypso/components/banner';
import DocumentHead from 'calypso/components/data/document-head';
import QueryProducts from 'calypso/components/data/query-products-list';
import QuerySitePurchases from 'calypso/components/data/query-site-purchases';
import EmptyContent from 'calypso/components/empty-content';
import FormattedHeader from 'calypso/components/formatted-header';
import Main from 'calypso/components/main';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import TrackComponentView from 'calypso/lib/analytics/track-component-view';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { getDomainRegistrations } from 'calypso/lib/cart-values/cart-items';
import { PerformanceTrackerStop } from 'calypso/lib/performance-tracking';
import { isPlansPageUntangled } from 'calypso/lib/plans/untangling-plans-experiment';
import { isPartnerPurchase } from 'calypso/lib/purchases';
import { isExternal } from 'calypso/lib/url';
import PlansNavigation from 'calypso/my-sites/plans/navigation';
import P2PlansMain from 'calypso/my-sites/plans/p2-plans-main';
import PlansFeaturesMain from 'calypso/my-sites/plans-features-main';
import { FeatureBreadcrumb } from 'calypso/sites/hooks/breadcrumbs/use-set-feature-breadcrumb';
import CurrentPlanPanel from 'calypso/sites/plan/components/current-plan-panel';
import { useSelector } from 'calypso/state';
import { getByPurchaseId } from 'calypso/state/purchases/selectors';
import { canCurrentUser } from 'calypso/state/selectors/can-current-user';
import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slug';
import getCurrentPlanTerm from 'calypso/state/selectors/get-current-plan-term';
import getCurrentQueryArguments from 'calypso/state/selectors/get-current-query-arguments';
import getDomainFromHomeUpsellInQuery from 'calypso/state/selectors/get-domain-from-home-upsell-in-query';
import isEligibleForWpComMonthlyPlan from 'calypso/state/selectors/is-eligible-for-wpcom-monthly-plan';
import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams';
import siteHasFeature from 'calypso/state/selectors/site-has-feature';
import { useSiteGlobalStylesOnPersonal } from 'calypso/state/sites/hooks/use-site-global-styles-on-personal';
import { fetchSitePlans } from 'calypso/state/sites/plans/actions';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors';
import CalypsoShoppingCartProvider from '../checkout/calypso-shopping-cart-provider';
import withCartKey from '../checkout/with-cart-key';
import DomainAndPlanPackageNavigation from '../domains/components/domain-and-plan-package/navigation';
import DomainUpsellDialog from './components/domain-upsell-dialog';
import PlansHeader from './components/plans-header';
import ECommerceTrialPlansPage from './ecommerce-trial';
import ModernizedLayout from './modernized-layout';
import BusinessTrialPlansPage from './trials/business-trial-plans-page';
import WooExpressPlansPage from './woo-express-plans-page';
import './style.scss';
function DomainAndPlanUpsellNotice() {
const translate = useTranslate();
const noticeTitle = translate( 'Almost done' );
const noticeDescription = translate( 'Upgrade today to claim your free domain name!' );
return (
<Banner
title={ noticeTitle }
description={ noticeDescription }
icon="star"
showIcon
disableHref
/>
);
}
function DescriptionMessage( { isDomainUpsell, isFreePlan, yourDomainName, siteSlug } ) {
const translate = useTranslate();
const dispatch = useDispatch();
if ( ! isDomainUpsell ) {
return (
<>
<p>
{ translate(
'With your annual plan, you’ll get %(domainName)s {{strong}}free for the first year{{/strong}}.',
{
args: {
domainName: yourDomainName,
},
components: {
strong: <strong />,
},
}
) }
</p>
<p>
{ translate(
'You’ll also unlock advanced features that make it easy to build and grow your site.'
) }
</p>
</>
);
}
const skipPlan = () => {
recordTracksEvent( 'calypso_plans_page_domain_upsell_skip_click' );
// show Warning only on free plans.
isFreePlan
? dispatch( WpcomPlansUI.store ).setShowDomainUpsellDialog( true )
: page( `/checkout/${ siteSlug }` );
};
const subtitle = isFreePlan
? translate( 'See and compare the features available on each WordPress.com plan' )
: translate( 'All of our annual plans include a free domain name for one year.' );
const subtitle2 = isFreePlan
? ''
: translate(
'Upgrade to a yearly plan and claim {{strong}}%(domainName)s for free{{/strong}}.',
{
args: {
domainName: yourDomainName,
},
components: {
strong: <strong />,
br: <br />,
},
}
);
const skipText = isFreePlan
? translate( 'Or continue with the free plan.' )
: translate( 'Or continue with your monthly plan.' );
return (
<>
<p>{ subtitle }</p>
{ subtitle2 && <p>{ subtitle2 }</p> }
<p>
<button onClick={ skipPlan }>{ skipText }</button>
</p>
</>
);
}
class PlansComponent extends Component {
static propTypes = {
context: PropTypes.object.isRequired,
coupon: PropTypes.string,
redirectToAddDomainFlow: PropTypes.bool,
domainAndPlanPackage: PropTypes.bool,
intervalType: PropTypes.string,
customerType: PropTypes.string,
selectedFeature: PropTypes.string,
redirectTo: PropTypes.string,
selectedSite: PropTypes.object,
isDomainAndPlanPackageFlow: PropTypes.bool,
isDomainUpsell: PropTypes.bool,
isDomainUpsellSuggested: PropTypes.bool,
};
static defaultProps = {
intervalType: 'yearly',
};
componentDidMount() {
const { currentPlan, selectedSite } = this.props;
this.redirectIfInvalidPlanInterval();
if ( ! currentPlan && selectedSite ) {
this.props.fetchSitePlans( selectedSite.ID );
}
if ( this.props.isDomainAndPlanPackageFlow ) {
document.body.classList.add( 'is-domain-plan-package-flow' );
}
// Scroll to the top
if ( typeof window !== 'undefined' ) {
window.scrollTo( 0, 0 );
}
}
componentWillUnmount() {
if ( document.body.classList.contains( 'is-domain-plan-package-flow' ) ) {
document.body.classList.remove( 'is-domain-plan-package-flow' );
}
}
componentDidUpdate() {
this.redirectIfInvalidPlanInterval();
}
isInvalidPlanInterval() {
const { isSiteEligibleForMonthlyPlan, intervalType, selectedSite } = this.props;
if ( 'monthly' === intervalType && selectedSite ) {
// This is the reason isInvalidPlanInterval even exists and the redirection isn't handled at controller level
return ! isSiteEligibleForMonthlyPlan;
}
}
redirectIfInvalidPlanInterval() {
const { selectedSite } = this.props;
if ( this.isInvalidPlanInterval() ) {
page.redirect( '/plans/yearly/' + selectedSite.slug );
}
}
onSelectPlan = ( item ) => {
const {
selectedSite,
context: {
query: { discount },
},
} = this.props;
const checkoutPath = `/checkout/${ selectedSite.slug }/${ item.product_slug }/`;
page(
discount
? addQueryArgs( checkoutPath, {
coupon: discount,
} )
: checkoutPath
);
};
renderPlaceholder = () => {
return (
<div>
<Main wideLayout>
<div id="plans" className="plans plans__has-sidebar" />
</Main>
</div>
);
};
renderPlansMain() {
const { selectedSite, isUntangled, isWPForTeamsSite, currentPlanIntervalType } = this.props;
if ( isEnabled( 'p2/p2-plus' ) && isWPForTeamsSite ) {
return (
<P2PlansMain
// None of these props appear to be used by the P2PlansMain component.
// We should consider removing them.
selectedPlan={ this.props.selectedPlan }
redirectTo={ this.props.redirectTo }
site={ selectedSite }
coupon={ this.props.coupon }
discountEndDate={ this.props.discountEndDate }
/>
);
}
const hideFreePlan = this.props.isDomainAndPlanPackageFlow;
// The Jetpack mobile app wants to display a specific selection of plans
const plansIntent = this.props.jetpackAppPlans ? 'plans-jetpack-app' : null;
const hidePlanTypeSelector =
this.props.domainAndPlanPackage &&
( ! this.props.isDomainUpsell ||
( this.props.isDomainUpsell && currentPlanIntervalType === 'monthly' ) );
return (
<PlansFeaturesMain
isInSiteDashboard={ isUntangled }
redirectToAddDomainFlow={ this.props.redirectToAddDomainFlow }
hidePlanTypeSelector={ hidePlanTypeSelector }
hideFreePlan={ hideFreePlan }
customerType={ this.props.customerType }
intervalType={ this.props.intervalType }
selectedFeature={ this.props.selectedFeature }
selectedPlan={ this.props.selectedPlan }
redirectTo={ this.props.redirectTo }
coupon={ this.props.coupon }
discountEndDate={ this.props.discountEndDate }
siteId={ selectedSite?.ID }
plansWithScroll={ false }
hidePlansFeatureComparison={ this.props.isDomainAndPlanPackageFlow }
showLegacyStorageFeature={ this.props.siteHasLegacyStorage }
intent={ plansIntent }
isSpotlightOnCurrentPlan={ ! isUntangled && ! this.props.isDomainAndPlanPackageFlow }
showPlanTypeSelectorDropdown={ isEnabled( 'onboarding/interval-dropdown' ) }
/>
);
}
getIntervalForWooExpressPlans() {
const { intervalType } = this.props;
// Only accept monthly or yearly for the interval; otherwise let the component provide a default.
const interval =
intervalType === 'monthly' || intervalType === 'yearly' ? intervalType : undefined;
return interval;
}
renderEcommerceTrialPage() {
const { selectedSite, purchase } = this.props;
if ( ! selectedSite || ! purchase ) {
return this.renderPlaceholder();
}
const interval = this.getIntervalForWooExpressPlans();
return (
<ECommerceTrialPlansPage
isWooExpressTrial={ !! purchase?.isWooExpressTrial }
interval={ interval }
site={ selectedSite }
/>
);
}
renderBusinessTrialPage() {
const { selectedSite } = this.props;
if ( ! selectedSite ) {
return this.renderPlaceholder();
}
return <BusinessTrialPlansPage selectedSite={ selectedSite } />;
}
renderWooExpressPlansPage() {
const { currentPlan, selectedSite, isSiteEligibleForMonthlyPlan } = this.props;
if ( ! selectedSite ) {
return this.renderPlaceholder();
}
const interval = this.getIntervalForWooExpressPlans();
return (
<WooExpressPlansPage
currentPlan={ currentPlan }
interval={ interval }
selectedSite={ selectedSite }
showIntervalToggle={ isSiteEligibleForMonthlyPlan }
/>
);
}
renderMainContent( {
isEcommerceTrial,
isBusinessTrial,
isWooExpressPlan,
isA4APlan,
is100YearPlan,
} ) {
if ( isEcommerceTrial ) {
return this.renderEcommerceTrialPage();
}
if ( isWooExpressPlan ) {
return this.renderWooExpressPlansPage();
}
if ( isBusinessTrial ) {
return this.renderBusinessTrialPage();
}
if ( isA4APlan || is100YearPlan ) {
return null;
}
return this.renderPlansMain();
}
render() {
const { isUntangled, selectedSite, translate } = this.props;
return (
<>
<DocumentHead title={ translate( 'Plans', { textOnly: true } ) } />
{ isUntangled && (
<FeatureBreadcrumb siteId={ selectedSite.ID } title={ translate( 'Plan' ) } />
) }
{ this.renderContent() }
</>
);
}
getBackLink() {
const backTo = getQueryArg( window.location.href, 'back_to' ) ?? '';
if ( ! isExternal( backTo ) ) {
return backTo;
}
const { selectedSite, isDomainUpsell, isDomainUpsellSuggested } = this.props;
return isDomainUpsell && isDomainUpsellSuggested
? addQueryArgs( `/home/${ selectedSite.slug }` )
: addQueryArgs( `/domains/add/${ selectedSite.slug }`, {
domainAndPlanPackage: true,
} );
}
renderContent() {
const {
selectedSite,
translate,
canAccessPlans,
isUntangled,
currentPlan,
domainAndPlanPackage,
isDomainAndPlanPackageFlow,
isJetpackNotAtomic,
isDomainUpsell,
isFreePlan,
currentPlanIntervalType,
domainFromHomeUpsellFlow,
jetpackAppPlans,
purchase,
} = this.props;
if ( ! selectedSite || this.isInvalidPlanInterval() || ! currentPlan ) {
return this.renderPlaceholder();
}
const currentPlanSlug = selectedSite?.plan?.product_slug;
const isEcommerceTrial = currentPlanSlug === PLAN_ECOMMERCE_TRIAL_MONTHLY;
const isBusinessTrial =
currentPlanSlug === PLAN_MIGRATION_TRIAL_MONTHLY ||
currentPlanSlug === PLAN_HOSTING_TRIAL_MONTHLY;
const isWooExpressPlan = [
PLAN_WOOEXPRESS_MEDIUM,
PLAN_WOOEXPRESS_MEDIUM_MONTHLY,
PLAN_WOOEXPRESS_SMALL,
PLAN_WOOEXPRESS_SMALL_MONTHLY,
].includes( currentPlanSlug );
const wooExpressSubHeaderText = translate(
"Discover what's available in your Woo Express plan."
);
const entrepreneurTrialSubHeaderText =
// translators: %(planName)s is a plan name. E.g. Commerce plan.
translate( "Discover what's available in your %(planName)s plan.", {
args: {
planName: getPlan( PLAN_ECOMMERCE )?.getTitle() ?? '',
},
} );
const isWooExpressTrial = purchase?.isWooExpressTrial;
const isA4APlan = purchase && isPartnerPurchase( purchase );
const is100YearPlan = purchase && is100Year( purchase );
// Use the Woo Express subheader text if the current plan has the Performance or trial plans or fallback to the default subheader text.
let subHeaderText = null;
if ( isWooExpressPlan || isEcommerceTrial ) {
subHeaderText = isWooExpressTrial ? wooExpressSubHeaderText : entrepreneurTrialSubHeaderText;
}
const allDomains = isDomainAndPlanPackageFlow ? getDomainRegistrations( this.props.cart ) : [];
const yourDomainName = allDomains.length
? allDomains.slice( -1 )[ 0 ]?.meta
: translate( 'your domain name' );
const headline =
currentPlanIntervalType === 'monthly'
? translate( 'Get your domain’s first year for free' )
: translate( 'Choose the perfect plan' );
// Hide for WooExpress plans and Entrepreneur trials that are not WooExpress trials
const isEntrepreneurTrial = isEcommerceTrial && ! purchase?.isWooExpressTrial;
const showPlansNavigation = ! isUntangled && ! ( isWooExpressPlan || isEntrepreneurTrial );
return (
<div>
{ ! isUntangled && ! isJetpackNotAtomic && <ModernizedLayout /> }
{ selectedSite.ID && <QuerySitePurchases siteId={ selectedSite.ID } /> }
<PageViewTracker path="/plans/:site" title="Plans" />
{ /** QueryProducts added to ensure currency-code state gets populated for usages of getCurrentUserCurrencyCode */ }
<QueryProducts />
<TrackComponentView
eventName="calypso_plans_view"
eventProperties={ {
current_plan_slug: currentPlanSlug || null,
is_site_on_paid_plan: !! ( currentPlanSlug && ! isFreePlan ),
} }
/>
{ ( isDomainUpsell || domainFromHomeUpsellFlow ) && (
<DomainUpsellDialog domain={ selectedSite.slug } />
) }
{ canAccessPlans && (
<div>
{ isUntangled && <CurrentPlanPanel /> }
{ ! isUntangled && ! isDomainAndPlanPackageFlow && (
<PlansHeader
domainFromHomeUpsellFlow={ domainFromHomeUpsellFlow }
subHeaderText={ subHeaderText }
/>
) }
{ isDomainAndPlanPackageFlow && (
<>
<div className="plans__header">
{ ! jetpackAppPlans && (
<DomainAndPlanPackageNavigation goBackLink={ this.getBackLink() } step={ 2 } />
) }
<FormattedHeader brandFont headerText={ headline } align="center" />
<DescriptionMessage
isFreePlan={ isFreePlan }
yourDomainName={ yourDomainName }
siteSlug={ selectedSite.slug }
isDomainUpsell={ isDomainUpsell }
/>
</div>
</>
) }
<div id={ isUntangled ? 'site-plans' : 'plans' } className="plans plans__has-sidebar">
{ showPlansNavigation && <PlansNavigation path={ this.props.context.path } /> }
<Main fullWidthLayout={ ! isWooExpressTrial } wideLayout={ isWooExpressTrial }>
{ ! isDomainAndPlanPackageFlow && domainAndPlanPackage && (
<DomainAndPlanUpsellNotice />
) }
{ this.renderMainContent( {
isEcommerceTrial,
isBusinessTrial,
isWooExpressPlan,
isA4APlan,
is100YearPlan,
} ) }
<PerformanceTrackerStop />
</Main>
</div>
</div>
) }
{ ! canAccessPlans && (
<EmptyContent title={ translate( 'You are not authorized to view this page' ) } />
) }
</div>
);
}
}
const ConnectedPlans = connect(
( state, props ) => {
const { currentPlan, selectedSiteId } = props;
const currentPlanIntervalType = getIntervalTypeForTerm(
getPlan( currentPlan?.productSlug )?.term
);
return {
currentPlan,
currentPlanIntervalType,
purchase: currentPlan ? getByPurchaseId( state, currentPlan.purchaseId ) : null,
selectedSite: getSelectedSite( state ),
canAccessPlans: canCurrentUser( state, getSelectedSiteId( state ), 'manage_options' ),
isUntangled: isPlansPageUntangled( state ),
isWPForTeamsSite: isSiteWPForTeams( state, selectedSiteId ),
isSiteEligibleForMonthlyPlan: isEligibleForWpComMonthlyPlan( state, selectedSiteId ),
isDomainAndPlanPackageFlow: !! getCurrentQueryArguments( state )?.domainAndPlanPackage,
isJetpackNotAtomic: isJetpackSite( state, selectedSiteId, {
treatAtomicAsJetpackSite: false,
} ),
isDomainUpsell:
!! getCurrentQueryArguments( state )?.domainAndPlanPackage &&
!! getCurrentQueryArguments( state )?.domain,
isDomainUpsellSuggested: getCurrentQueryArguments( state )?.domain === 'true',
isFreePlan: isFreePlanProduct( currentPlan ),
domainFromHomeUpsellFlow: getDomainFromHomeUpsellInQuery( state ),
siteHasLegacyStorage: siteHasFeature( state, selectedSiteId, FEATURE_LEGACY_STORAGE_200GB ),
locale: getCurrentLocaleSlug( state ),
};
},
( dispatch ) => ( {
fetchSitePlans: ( siteId ) => dispatch( fetchSitePlans( siteId ) ),
} )
)( withCartKey( withShoppingCart( localize( PlansComponent ) ) ) );
export default function PlansWrapper( props ) {
const { intervalType: intervalTypeFromProps } = props;
const selectedSiteId = useSelector( getSelectedSiteId );
const currentPlan = Plans.useCurrentPlan( { siteId: selectedSiteId } );
// Initialize Global Styles.
useSiteGlobalStylesOnPersonal();
/**
* For WP.com plans page, if intervalType is not explicitly specified in the URL,
* we want to show plans of the same term as plan that is currently active
* We want to show the highest term between the current plan and the longer plan term default experiment
*/
const intervalTypeForCurrentPlanTerm = useSelector( ( state ) =>
getIntervalTypeForTerm( getCurrentPlanTerm( state, selectedSiteId ) )
);
return (
<CalypsoShoppingCartProvider>
<ConnectedPlans
{ ...props }
currentPlan={ currentPlan }
selectedSiteId={ selectedSiteId }
intervalType={ intervalTypeFromProps ?? intervalTypeForCurrentPlanTerm }
/>
</CalypsoShoppingCartProvider>
);
}
|