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

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

); }; export const InstallJetpackCTA = () => { const { currentUserCan } = useUser(); const { updateUserPreferences, ...userPrefs } = useUserPreferences(); const { canUserInstallPlugins, 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, canUserInstallPlugins: currentUserCan( 'install_plugins' ), }; } ); const { installJetpackAndConnect } = useDispatch( PLUGINS_STORE_NAME ); if ( ! canUserInstallPlugins ) { return null; } const onClickInstall = () => { installJetpackAndConnect( createErrorNotice, getAdminLink ); }; return ( { const homepageStats = userPrefs.homepage_stats || {}; homepageStats.installJetpackDismissed = true; updateUserPreferences( { homepage_stats: homepageStats, } ); } } /> ); };