2020-05-27 02:38:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Button } from '@wordpress/components';
|
2020-08-20 04:02:01 +00:00
|
|
|
import { useSelect, useDispatch } from '@wordpress/data';
|
2021-02-03 17:19:15 +00:00
|
|
|
import {
|
|
|
|
PLUGINS_STORE_NAME,
|
2021-02-19 13:57:17 +00:00
|
|
|
useUser,
|
2021-02-03 17:19:15 +00:00
|
|
|
useUserPreferences,
|
|
|
|
} from '@woocommerce/data';
|
2020-06-12 06:38:33 +00:00
|
|
|
import { H } from '@woocommerce/components';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2022-03-01 04:19:07 +00:00
|
|
|
import { createErrorNotice } from '@woocommerce/data/src/plugins/actions';
|
2020-05-27 02:38:57 +00:00
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
const getJetpackInstallText = ( jetpackInstallState ) => {
|
|
|
|
return (
|
|
|
|
{
|
|
|
|
unavailable: __( 'Get Jetpack', 'woocommerce-admin' ),
|
|
|
|
installed: __( 'Activate Jetpack', 'woocommerce-admin' ),
|
|
|
|
activated: __( 'Connect Jetpack', 'woocommerce-admin' ),
|
|
|
|
}[ jetpackInstallState ] || ''
|
2020-05-27 02:38:57 +00:00
|
|
|
);
|
2020-08-20 04:02:01 +00:00
|
|
|
};
|
2020-05-27 02:38:57 +00:00
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
export const JetpackCTA = ( {
|
|
|
|
onClickInstall,
|
|
|
|
onClickDismiss,
|
|
|
|
isBusy,
|
|
|
|
jetpackInstallState,
|
|
|
|
} ) => {
|
2020-05-27 02:38:57 +00:00
|
|
|
return (
|
|
|
|
<article className="woocommerce-stats-overview__install-jetpack-promo">
|
2020-06-18 23:44:00 +00:00
|
|
|
<div className="woocommerce-stats-overview__install-jetpack-promo__content">
|
|
|
|
<H>
|
|
|
|
{ __(
|
|
|
|
'Get traffic stats with Jetpack',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</H>
|
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
'Keep an eye on your views and visitors metrics with ' +
|
|
|
|
'Jetpack. Requires Jetpack plugin and a WordPress.com ' +
|
|
|
|
'account.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</div>
|
2020-05-27 02:38:57 +00:00
|
|
|
<footer>
|
2020-08-20 04:02:01 +00:00
|
|
|
<Button
|
|
|
|
isSecondary
|
|
|
|
onClick={ () => {
|
|
|
|
recordEvent( 'statsoverview_install_jetpack' );
|
|
|
|
onClickInstall();
|
|
|
|
} }
|
|
|
|
disabled={ isBusy }
|
|
|
|
isBusy={ isBusy }
|
|
|
|
>
|
|
|
|
{ getJetpackInstallText( jetpackInstallState ) }
|
2020-05-27 02:38:57 +00:00
|
|
|
</Button>
|
2020-08-20 04:02:01 +00:00
|
|
|
<Button
|
|
|
|
isTertiary
|
|
|
|
onClick={ () => {
|
|
|
|
recordEvent( 'statsoverview_dismiss_install_jetpack' );
|
|
|
|
onClickDismiss();
|
|
|
|
} }
|
|
|
|
disabled={ isBusy }
|
|
|
|
isBusy={ isBusy }
|
|
|
|
>
|
2020-05-27 02:38:57 +00:00
|
|
|
{ __( 'No thanks', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</footer>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
export const InstallJetpackCTA = () => {
|
2021-02-19 13:57:17 +00:00
|
|
|
const { currentUserCan } = useUser();
|
2020-08-20 04:02:01 +00:00
|
|
|
const { updateUserPreferences, ...userPrefs } = useUserPreferences();
|
2021-02-03 17:19:15 +00:00
|
|
|
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' );
|
2020-05-27 02:38:57 +00:00
|
|
|
|
2021-02-03 17:19:15 +00:00
|
|
|
return {
|
|
|
|
isBusy: busyState,
|
|
|
|
jetpackInstallState: installState,
|
2021-02-19 13:57:17 +00:00
|
|
|
canUserInstallPlugins: currentUserCan( 'install_plugins' ),
|
2021-02-03 17:19:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2020-06-12 06:38:33 +00:00
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
const { installJetpackAndConnect } = useDispatch( PLUGINS_STORE_NAME );
|
|
|
|
|
2021-02-03 17:19:15 +00:00
|
|
|
if ( ! canUserInstallPlugins ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
const onClickInstall = () => {
|
2020-09-18 02:22:52 +00:00
|
|
|
installJetpackAndConnect( createErrorNotice, getAdminLink );
|
2020-08-20 04:02:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<JetpackCTA
|
|
|
|
jetpackInstallState={ jetpackInstallState }
|
|
|
|
isBusy={ isBusy }
|
|
|
|
onClickInstall={ onClickInstall }
|
|
|
|
onClickDismiss={ () => {
|
|
|
|
const homepageStats = userPrefs.homepage_stats || {};
|
|
|
|
homepageStats.installJetpackDismissed = true;
|
|
|
|
updateUserPreferences( {
|
|
|
|
homepage_stats: homepageStats,
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|