import { TERM_ANNUALLY, PLAN_JETPACK_FREE } from '@automattic/calypso-products'; import { Button } from '@automattic/components'; import { useTranslate } from 'i18n-calypso'; import { Fragment, useCallback, useMemo } from 'react'; import { usePresalesChat } from 'calypso/lib/presales-chat'; import CalypsoShoppingCartProvider from 'calypso/my-sites/checkout/calypso-shopping-cart-provider'; import ProductLightbox from 'calypso/my-sites/plans/jetpack-plans/product-lightbox'; import StoreItemInfoContext, { useStoreItemInfoContext, } from 'calypso/my-sites/plans/jetpack-plans/product-store/context/store-item-info-context'; import { useProductLightbox } from 'calypso/my-sites/plans/jetpack-plans/product-store/hooks/use-product-lightbox'; import { useStoreItemInfo } from 'calypso/my-sites/plans/jetpack-plans/product-store/hooks/use-store-item-info'; import { ItemPrice } from 'calypso/my-sites/plans/jetpack-plans/product-store/item-price'; import { MoreInfoLink } from 'calypso/my-sites/plans/jetpack-plans/product-store/more-info-link'; import slugToSelectorProduct from 'calypso/my-sites/plans/jetpack-plans/slug-to-selector-product'; import { useDispatch } from 'calypso/state'; import { recordTracksEvent } from 'calypso/state/analytics/actions/record'; import { getPurchaseURLCallback } from '../../../../my-sites/plans/jetpack-plans/get-purchase-url-callback'; import { TableWithStoreContextProps } from '../types'; import { links } from './links'; import { useComparisonData } from './useComparisonData'; import { useProductsToCompare } from './useProductsToCompare'; import type { SelectorProduct, PurchaseCallback } from 'calypso/my-sites/plans/jetpack-plans/types'; import './style.scss'; export const Table: React.FC = () => { const translate = useTranslate(); const productsToCompare = useProductsToCompare(); const data = useComparisonData(); const { currentProduct, setCurrentProduct, onClickMoreInfoFactory } = useProductLightbox(); const { getCheckoutURL, getCtaLabel, getIsExternal, getOnClickPurchase } = useStoreItemInfoContext(); usePresalesChat( 'jpGeneral' ); const sectionHeadingColSpan = productsToCompare.length + 1; const headerRow = ( { productsToCompare.map( ( { id, name, productSlug } ) => { const isFree = 'FREE' === id; const item = ( isFree ? { productSlug: PLAN_JETPACK_FREE } : slugToSelectorProduct( productSlug ) ) as SelectorProduct; return (
{ name } { ! isFree && } { isFree ? ( { translate( 'Basic Jetpack features' ) } ) : ( /* removing until the PR to add the lightbox for Growth is merged */ ) }
); } ) } ); return (
{ currentProduct && ( setCurrentProduct( null ) } onChangeProduct={ setCurrentProduct } /> ) } { productsToCompare.map( ( { id } ) => ( ) ) } { headerRow } { data.map( ( { sectionId, sectionName, icon, features } ) => { return ( { features.map( ( { id, name, icon, info, url } ) => { return ( { productsToCompare.map( ( { id, name: productName } ) => ( ) ) } ); } ) } ); } ) } { headerRow }
{ sectionName }
{ icon ? (
) : (
) } { name }
{ info[ id ]?.content }

{ translate( 'Looking for more? Check out {{link}}an exhaustive list of Jetpack features{{/link}}.', { components: { link: , }, } ) }

); }; const TableWithStoreContext: React.FC< TableWithStoreContextProps > = ( { locale, rootUrl, urlQueryArgs, } ) => { const createCheckoutURL = useMemo( () => getPurchaseURLCallback( '', urlQueryArgs, locale ), [ locale, urlQueryArgs ] ); const dispatch = useDispatch(); const onClickPurchase = useCallback< PurchaseCallback >( ( product ) => { dispatch( recordTracksEvent( 'calypso_jetpack_comparison_page_product_click', { product_slug: product.productSlug, duration: TERM_ANNUALLY, path: rootUrl, } ) ); }, [ dispatch, rootUrl ] ); const storeItemInfo = useStoreItemInfo( { duration: TERM_ANNUALLY, siteId: null, createCheckoutURL, onClickPurchase, } ); return ( ); }; export const TableWithStoreAccess: React.FC< TableWithStoreContextProps > = ( { locale, rootUrl, urlQueryArgs, } ) => { return ( ); };