import { getPlanClass, isWpcomEnterpriseGridPlan, isFreePlan, type FeatureGroupSlug, FEATURE_GROUP_STORAGE, } from '@automattic/calypso-products'; import { FoldableCard } from '@automattic/components'; import { AddOns } from '@automattic/data-stores'; import { useRef, useMemo } from '@wordpress/element'; import clsx from 'clsx'; import { useTranslate } from 'i18n-calypso'; import PlansGridContextProvider, { usePlansGridContext } from '../../grid-context'; import useGridSize from '../../hooks/use-grid-size'; import { PlanFeaturesItem } from '../item'; import { PlanStorage } from '../shared/storage'; import BillingTimeframes from './billing-timeframes'; import BottomPlanCard from './bottom-plan-card'; import EnterpriseFeatures from './enterprise-features'; import PlanFeaturesList from './plan-features-list'; import PlanHeaders from './plan-headers'; import PlanLogos from './plan-logos'; import PlanPrices from './plan-prices'; import PlanTagline from './plan-tagline'; import PreviousFeaturesIncludedTitle from './previous-features-included-title'; import SpotlightPlan from './spotlight-plan'; import Table from './table'; import TopButtons from './top-buttons'; import type { DataResponse, FeaturesGridExternalProps, FeaturesGridProps, GridPlan, GridSize, PlanActionOverrides, } from '../../types'; import type { JSX } from 'react'; import './style.scss'; type MobileViewProps = { currentSitePlanSlug?: string | null; generatedWPComSubdomain: DataResponse< { domain_name: string } >; gridPlanForSpotlight?: GridPlan; hideUnavailableFeatures?: boolean; isCustomDomainAllowedOnFreePlan: boolean; isInSignup: boolean; onStorageAddOnClick?: ( addOnSlug: AddOns.StorageAddOnSlug ) => void; paidDomainName?: string; planActionOverrides?: PlanActionOverrides; renderedGridPlans: GridPlan[]; selectedFeature?: string; showUpgradeableStorage: boolean; enableShowAllFeaturesButton?: boolean; }; const CardContainer = ( props: React.ComponentProps< typeof FoldableCard > & { planSlug: string } ) => { const { children, planSlug, ...otherProps } = props; return isWpcomEnterpriseGridPlan( planSlug ) ? (
{ children }
) : ( { children } ); }; const FeaturesContainer = ( props: { children: ( featureGroupSlug: FeatureGroupSlug ) => JSX.Element; featureGroups: FeatureGroupSlug[]; gridPlan: GridPlan; } ) => { const { children, gridPlan, featureGroups } = props; const { enableCategorisedFeatures, enableLogosOnlyForEnterprisePlan, enableReducedFeatureGroupSpacing, } = usePlansGridContext(); return ( <> { ! enableCategorisedFeatures && ( ) } { featureGroups.map( ( featureGroupSlug: FeatureGroupSlug ) => (
{ children( featureGroupSlug ) }
) ) } ); }; const MobileView = ( { currentSitePlanSlug, generatedWPComSubdomain, gridPlanForSpotlight, renderedGridPlans, hideUnavailableFeatures, isCustomDomainAllowedOnFreePlan, isInSignup, onStorageAddOnClick, paidDomainName, planActionOverrides, selectedFeature, showUpgradeableStorage, enableShowAllFeaturesButton, }: MobileViewProps ) => { const translate = useTranslate(); const { featureGroupMap, hideFeatureGroupTitles, intent } = usePlansGridContext(); const featureGroups = useMemo( () => Object.keys( featureGroupMap ).filter( ( key ) => FEATURE_GROUP_STORAGE !== key ) as FeatureGroupSlug[], [ featureGroupMap ] ); const storageFeatureGroup = featureGroupMap[ FEATURE_GROUP_STORAGE ]; return renderedGridPlans .reduce( ( acc, gridPlan ) => { // Bring the spotlight plan to the top if ( gridPlanForSpotlight?.planSlug === gridPlan.planSlug ) { return [ gridPlan ].concat( acc ); } return acc.concat( gridPlan ); }, [] as GridPlan[] ) .map( ( gridPlan, index ) => { const planCardClasses = clsx( 'plans-grid-next-features-grid__mobile-plan-card', getPlanClass( gridPlan.planSlug ) ); const isNotFreePlan = ! isFreePlan( gridPlan.planSlug ); const isEnterprisePlan = isWpcomEnterpriseGridPlan( gridPlan.planSlug ); const featuresEl = ( { ( featureGroupSlug: FeatureGroupSlug ) => ( ) } ); const planCardJsx = (
{ isInSignup && } { ( isNotFreePlan || isInSignup ) && ( ) } { ( isNotFreePlan || isInSignup ) && ( ) } { storageFeatureGroup && ! isEnterprisePlan && ( <> { ! hideFeatureGroupTitles && 'plans-wordpress-hosting' !== intent && (

{ storageFeatureGroup?.getTitle() }

) }
) } { enableShowAllFeaturesButton ? ( feature.getSlug() === selectedFeature ) } > { featuresEl } ) : (
{ featuresEl }
) }
); return planCardJsx; } ); }; type TabletViewProps = { currentSitePlanSlug?: string | null; generatedWPComSubdomain: DataResponse< { domain_name: string } >; gridPlanForSpotlight?: GridPlan; hideUnavailableFeatures?: boolean; isCustomDomainAllowedOnFreePlan: boolean; isInSignup: boolean; onStorageAddOnClick?: ( addOnSlug: AddOns.StorageAddOnSlug ) => void; paidDomainName?: string; planActionOverrides?: PlanActionOverrides; renderedGridPlans: GridPlan[]; selectedFeature?: string; showRefundPeriod?: boolean; showUpgradeableStorage: boolean; stickyRowOffset: number; }; const getTabletTopRowPlanCount = ( planCount: number ) => ( 4 === planCount ? 4 : 3 ); const TabletView = ( { currentSitePlanSlug, generatedWPComSubdomain, gridPlanForSpotlight, hideUnavailableFeatures, isCustomDomainAllowedOnFreePlan, isInSignup, onStorageAddOnClick, paidDomainName, planActionOverrides, renderedGridPlans, selectedFeature, showRefundPeriod, showUpgradeableStorage, stickyRowOffset, }: TabletViewProps ) => { const gridPlansWithoutSpotlight = ! gridPlanForSpotlight ? renderedGridPlans : renderedGridPlans.filter( ( { planSlug } ) => gridPlanForSpotlight.planSlug !== planSlug ); const numberOfPlansToShowOnTop = getTabletTopRowPlanCount( gridPlansWithoutSpotlight.length ); const plansForTopRow = gridPlansWithoutSpotlight.slice( 0, numberOfPlansToShowOnTop ); const plansForBottomRow = gridPlansWithoutSpotlight.slice( numberOfPlansToShowOnTop ); const tableProps = { currentSitePlanSlug, generatedWPComSubdomain, gridPlanForSpotlight, hideUnavailableFeatures, isCustomDomainAllowedOnFreePlan, isInSignup, onStorageAddOnClick, paidDomainName, planActionOverrides, selectedFeature, showRefundPeriod, showUpgradeableStorage, stickyRowOffset, }; return ( <>
{ plansForBottomRow.length > 0 && (
) } ); }; // TODO // Now that everything under is functional component, we can deprecate this wrapper and only keep ComparisonGrid instead. // More details can be found in https://github.com/Automattic/wp-calypso/issues/87047 const FeaturesGrid = ( { bottomGridPlan, currentSitePlanSlug, generatedWPComSubdomain, gridPlanForSpotlight, gridPlans, gridSize, hideUnavailableFeatures, isCustomDomainAllowedOnFreePlan, isInSignup, onStorageAddOnClick, paidDomainName, planActionOverrides, selectedFeature, showRefundPeriod, showUpgradeableStorage, stickyRowOffset, enableShowAllFeaturesButton, }: FeaturesGridProps ) => { const spotlightPlanProps = { currentSitePlanSlug, gridPlanForSpotlight, isInSignup, onStorageAddOnClick, planActionOverrides, selectedFeature, showUpgradeableStorage, }; const planFeaturesProps = { ...spotlightPlanProps, generatedWPComSubdomain, hideUnavailableFeatures, isCustomDomainAllowedOnFreePlan, paidDomainName, renderedGridPlans: gridPlans, showRefundPeriod, }; const gridPlansWithoutSpotlightCount = gridPlanForSpotlight ? gridPlans.filter( ( { planSlug } ) => gridPlanForSpotlight.planSlug !== planSlug ).length : gridPlans.length; const tabletTopRowPlanCount = getTabletTopRowPlanCount( gridPlansWithoutSpotlightCount ); const hasTabletSplitRow = 'medium' === gridSize && gridPlansWithoutSpotlightCount > tabletTopRowPlanCount; return (
{ 'small' !== gridSize && }
{ 'large' === gridSize && (
) } { 'medium' === gridSize && (
) } { 'small' === gridSize && (
) } { bottomGridPlan && ( ) } ); }; const WrappedFeaturesGrid = ( props: FeaturesGridExternalProps ) => { const { siteId, intent, bottomGridPlan, gridPlans, useCheckPlanAvailabilityForPurchase, useAction, recordTracksEvent, allFeaturesList, coupon, isInAdmin, isInSiteDashboard, className, enableFeatureTooltips, enableCategorisedFeatures, enableStorageAsBadge, enableReducedFeatureGroupSpacing, enableLogosOnlyForEnterprisePlan, featureGroupMap = {}, hideFeatureGroupTitles, enterpriseFeaturesList, isEnterpriseA4AIndia, enableTermSavingsPriceDisplay, showSimplifiedBillingDescription, showBillingDescriptionForIncreasedRenewalPrice, isExperimentVariant, showFeatureCheckmarks, } = props; const gridContainerRef = useRef< HTMLDivElement >( null ); const gridBreakpoints = useMemo( () => { // we want to fit up to the Commerce plan in this breakpoint let largeBreakpoint; if ( isInSiteDashboard ) { largeBreakpoint = 1042; } else if ( isInAdmin ) { largeBreakpoint = 1180; } else { largeBreakpoint = 1320; } // we want to fit 3 plans per row in this breakpoint const mediumBreakpoint = 669; return new Map< GridSize, number >( [ [ 'small', 0 ], [ 'medium', mediumBreakpoint ], [ 'large', largeBreakpoint ], ] ); }, [ isInAdmin, isInSiteDashboard ] ); // TODO: this will be deprecated along side removing the wrapper component const gridSize = useGridSize( { containerRef: gridContainerRef, containerBreakpoints: gridBreakpoints, } ); const classNames = clsx( 'plans-grid-next', className, { 'is-small': 'small' === gridSize, 'is-medium': 'medium' === gridSize, 'is-large': 'large' === gridSize, } ); const gridPlansForContext = useMemo( () => { if ( ! bottomGridPlan || gridPlans.some( ( gridPlan ) => gridPlan.planSlug === bottomGridPlan.planSlug ) ) { return gridPlans; } return [ ...gridPlans, bottomGridPlan ]; }, [ bottomGridPlan, gridPlans ] ); return (
); }; export default WrappedFeaturesGrid;