/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; import { PLUGINS_STORE_NAME, useUserPreferences } from '@woocommerce/data'; import { H } from '@woocommerce/components'; /** * Internal dependencies */ import { recordEvent } from '../../lib/tracks'; import { createErrorNotice } from '../../../packages/data/src/plugins/actions'; const getJetpackInstallText = ( jetpackInstallState ) => { return ( { unavailable: __( 'Get Jetpack', 'woocommerce-admin' ), installed: __( 'Activate Jetpack', 'woocommerce-admin' ), activated: __( 'Connect Jetpack', 'woocommerce-admin' ), }[ jetpackInstallState ] || '' ); }; export const JetpackCTA = ( { onClickInstall, onClickDismiss, isBusy, jetpackInstallState, } ) => { return (
{ __( 'Get traffic stats with Jetpack', 'woocommerce-admin' ) }

{ __( 'Keep an eye on your views and visitors metrics with ' + 'Jetpack. Requires Jetpack plugin and a WordPress.com ' + 'account.', 'woocommerce-admin' ) }

); }; export const InstallJetpackCTA = () => { const { updateUserPreferences, ...userPrefs } = useUserPreferences(); const { jetpackInstallState, isBusy } = useSelect( ( select ) => { const { getPluginInstallState, isPluginsRequesting } = select( PLUGINS_STORE_NAME ); const installState = getPluginInstallState( 'jetpack' ); const busyState = isPluginsRequesting( 'getJetpackConnectUrl' ) || isPluginsRequesting( 'installPlugins' ) || isPluginsRequesting( 'activatePlugins' ); return { isBusy: busyState, jetpackInstallState: installState, }; } ); const { installJetpackAndConnect } = useDispatch( PLUGINS_STORE_NAME ); const onClickInstall = () => { installJetpackAndConnect( createErrorNotice ); }; return ( { const homepageStats = userPrefs.homepage_stats || {}; homepageStats.installJetpackDismissed = true; updateUserPreferences( { homepage_stats: homepageStats, } ); } } /> ); };