2019-05-22 16:19:56 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-08-23 12:56:57 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2019-10-10 14:05:13 +00:00
|
|
|
import { Button } from 'newspack-components';
|
2019-05-22 16:19:56 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-05-31 04:51:33 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2019-05-22 16:19:56 +00:00
|
|
|
import interpolateComponents from 'interpolate-components';
|
2019-05-31 04:51:33 +00:00
|
|
|
import { withDispatch } from '@wordpress/data';
|
2019-10-10 14:05:13 +00:00
|
|
|
import { filter, get } from 'lodash';
|
2019-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-23 12:56:57 +00:00
|
|
|
* WooCommerce depdencies
|
2019-05-22 16:19:56 +00:00
|
|
|
*/
|
|
|
|
import { Card, H, Link } from '@woocommerce/components';
|
2019-08-23 12:56:57 +00:00
|
|
|
import { updateQueryString } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal depdencies
|
|
|
|
*/
|
|
|
|
import CardIcon from './images/card';
|
2019-05-22 16:19:56 +00:00
|
|
|
import SecurityIcon from './images/security';
|
|
|
|
import SalesTaxIcon from './images/local_atm';
|
|
|
|
import SpeedIcon from './images/flash_on';
|
|
|
|
import MobileAppIcon from './images/phone_android';
|
2019-08-23 12:56:57 +00:00
|
|
|
import PrintIcon from './images/print';
|
2019-05-31 04:51:33 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-10-10 14:05:13 +00:00
|
|
|
import UsageModal from '../usage-modal';
|
2019-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-10-24 16:20:32 +00:00
|
|
|
import { pluginNames } from 'wc-api/onboarding/constants';
|
2019-05-22 16:19:56 +00:00
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
class Start extends Component {
|
2019-10-10 14:05:13 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
2019-05-22 16:19:56 +00:00
|
|
|
this.state = {
|
2019-10-10 14:05:13 +00:00
|
|
|
showUsageModal: false,
|
|
|
|
continueAction: '',
|
2019-05-22 16:19:56 +00:00
|
|
|
};
|
2019-05-28 03:09:48 +00:00
|
|
|
this.startWizard = this.startWizard.bind( this );
|
|
|
|
this.skipWizard = this.skipWizard.bind( this );
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 12:56:57 +00:00
|
|
|
componentDidMount() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const { updateProfileItems, profileItems, tosAccepted, isJetpackConnected } = this.props;
|
2019-08-23 12:56:57 +00:00
|
|
|
if (
|
2019-10-24 16:20:32 +00:00
|
|
|
isJetpackConnected &&
|
2019-10-22 23:55:57 +00:00
|
|
|
this.props.activePlugins.includes( 'woocommerce-services' ) &&
|
|
|
|
tosAccepted
|
2019-08-23 12:56:57 +00:00
|
|
|
) {
|
2019-10-17 14:57:29 +00:00
|
|
|
// Don't track event again if they revisit the start page.
|
|
|
|
if ( 'already-installed' !== profileItems.plugins ) {
|
|
|
|
recordEvent( 'wcadmin_storeprofiler_already_installed_plugins', {} );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateProfileItems( { plugins: 'already-installed' } );
|
2019-08-23 12:56:57 +00:00
|
|
|
return updateQueryString( { step: 'store-details' } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async skipWizard() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
isProfileItemsError,
|
|
|
|
updateProfileItems,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2019-10-24 16:20:32 +00:00
|
|
|
const plugins = isJetpackConnected ? 'skipped-wcs' : 'skipped';
|
2019-10-17 14:57:29 +00:00
|
|
|
await updateProfileItems( { plugins } );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-10-10 14:05:13 +00:00
|
|
|
if ( isProfileItemsError ) {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__( 'There was a problem updating your preferences.', 'woocommerce-admin' )
|
|
|
|
);
|
2019-10-10 14:05:13 +00:00
|
|
|
} else {
|
2019-10-17 14:57:29 +00:00
|
|
|
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true, plugins } );
|
|
|
|
return updateQueryString( { step: 'store-details' } );
|
2019-05-31 04:51:33 +00:00
|
|
|
}
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async startWizard() {
|
2019-10-17 14:57:29 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
isProfileItemsError,
|
|
|
|
updateProfileItems,
|
|
|
|
updateOptions,
|
|
|
|
goToNextStep,
|
2019-10-24 16:20:32 +00:00
|
|
|
isJetpackConnected,
|
2019-10-17 14:57:29 +00:00
|
|
|
} = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2019-10-03 16:03:29 +00:00
|
|
|
await updateOptions( {
|
|
|
|
woocommerce_setup_jetpack_opted_in: true,
|
|
|
|
} );
|
2019-10-17 14:57:29 +00:00
|
|
|
|
2019-10-24 16:20:32 +00:00
|
|
|
const plugins = isJetpackConnected ? 'installed-wcs' : 'installed';
|
2019-10-17 14:57:29 +00:00
|
|
|
await updateProfileItems( { plugins } );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-10-10 14:05:13 +00:00
|
|
|
if ( ! isProfileItemsError ) {
|
2019-10-17 14:57:29 +00:00
|
|
|
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true, plugins } );
|
|
|
|
goToNextStep();
|
2019-05-31 04:51:33 +00:00
|
|
|
} else {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__( 'There was a problem updating your preferences.', 'woocommerce-admin' )
|
|
|
|
);
|
2019-05-31 04:51:33 +00:00
|
|
|
}
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderBenefit( benefit ) {
|
|
|
|
const { description, icon, title } = benefit;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-profile-wizard__benefit" key={ title }>
|
|
|
|
{ icon }
|
|
|
|
<div className="woocommerce-profile-wizard__benefit-content">
|
|
|
|
<H className="woocommerce-profile-wizard__benefit-title">{ title }</H>
|
|
|
|
<p>{ description }</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-23 12:56:57 +00:00
|
|
|
getBenefits() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const { activePlugins, isJetpackConnected, tosAccepted } = this.props;
|
2019-08-23 12:56:57 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: __( 'Security', 'woocommerce-admin' ),
|
|
|
|
icon: <SecurityIcon />,
|
|
|
|
description: __(
|
|
|
|
'Jetpack automatically blocks brute force attacks to protect your store from unauthorized access.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: ! isJetpackConnected,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Sales Tax', 'woocommerce-admin' ),
|
|
|
|
icon: <SalesTaxIcon />,
|
|
|
|
description: __(
|
|
|
|
'With WooCommerce Services we ensure that the correct rate of tax is charged on all of your orders.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: ! activePlugins.includes( 'woocommerce-services' ) || ! tosAccepted,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Speed', 'woocommerce-admin' ),
|
|
|
|
icon: <SpeedIcon />,
|
|
|
|
description: __(
|
|
|
|
'Cache your images and static files on our own powerful global network of servers and speed up your site.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: ! isJetpackConnected,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Mobile App', 'woocommerce-admin' ),
|
|
|
|
icon: <MobileAppIcon />,
|
|
|
|
description: __(
|
|
|
|
'Your store in your pocket. Manage orders, receive sales notifications, and more. Only with a Jetpack connection.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: ! isJetpackConnected,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Print your own shipping labels', 'woocommerce-admin' ),
|
|
|
|
icon: <PrintIcon />,
|
|
|
|
description: __(
|
|
|
|
'Save time at the Post Office by printing USPS shipping labels at home.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: isJetpackConnected || ! tosAccepted,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Simple payment setup', 'woocommerce-admin' ),
|
|
|
|
icon: <CardIcon />,
|
|
|
|
description: __(
|
|
|
|
'WooCommerce Services enables us to provision Stripe and Paypal accounts quickly and easily for you.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
visible: isJetpackConnected || ! tosAccepted,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBenefits() {
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-profile-wizard__benefits">
|
|
|
|
{ filter( this.getBenefits(), benefit => benefit.visible ).map( benefit =>
|
|
|
|
this.renderBenefit( benefit )
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-22 16:19:56 +00:00
|
|
|
render() {
|
2019-10-10 14:05:13 +00:00
|
|
|
const { showUsageModal, continueAction } = this.state;
|
2019-10-24 16:20:32 +00:00
|
|
|
const { isJetpackConnected, activePlugins } = this.props;
|
2019-10-10 14:05:13 +00:00
|
|
|
|
2019-10-24 16:20:32 +00:00
|
|
|
const pluginsToInstall = [];
|
|
|
|
if ( ! isJetpackConnected ) {
|
|
|
|
pluginsToInstall.push( 'jetpack' );
|
|
|
|
}
|
|
|
|
if ( ! activePlugins.includes( 'woocommerce-services' ) ) {
|
|
|
|
pluginsToInstall.push( 'woocommerce-services' );
|
|
|
|
}
|
|
|
|
const pluginNamesString = pluginsToInstall
|
|
|
|
.map( pluginSlug => pluginNames[ pluginSlug ] )
|
|
|
|
.join( ' & ' );
|
2019-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-10-10 14:05:13 +00:00
|
|
|
{ showUsageModal && (
|
|
|
|
<UsageModal
|
|
|
|
onContinue={ () =>
|
|
|
|
'wizard' === continueAction ? this.startWizard() : this.skipWizard()
|
|
|
|
}
|
|
|
|
onClose={ () => this.setState( { showUsageModal: false, continueAction: '' } ) }
|
|
|
|
/>
|
|
|
|
) }
|
2019-05-27 16:37:02 +00:00
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
|
|
|
{ __( 'Start setting up your WooCommerce store', 'woocommerce-admin' ) }
|
|
|
|
</H>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
{ interpolateComponents( {
|
2019-08-23 12:56:57 +00:00
|
|
|
mixedString: sprintf(
|
|
|
|
__(
|
|
|
|
'Simplify and enhance the setup of your store with the free features and benefits offered by ' +
|
|
|
|
'{{strong}}%s{{/strong}}.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-10-24 16:20:32 +00:00
|
|
|
pluginNamesString
|
2019-05-27 16:37:02 +00:00
|
|
|
),
|
|
|
|
components: {
|
|
|
|
strong: <strong />,
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<Card>
|
2019-08-23 12:56:57 +00:00
|
|
|
{ this.renderBenefits() }
|
2019-05-22 16:19:56 +00:00
|
|
|
|
2019-10-03 16:03:29 +00:00
|
|
|
<p className="woocommerce-profile-wizard__tos">
|
|
|
|
{ interpolateComponents( {
|
|
|
|
mixedString: __(
|
|
|
|
'By connecting your site you agree to our fascinating {{tosLink}}Terms of Service{{/tosLink}} and to ' +
|
|
|
|
'{{detailsLink}}share details{{/detailsLink}} with WordPress.com. ',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
components: {
|
|
|
|
tosLink: <Link href="https://wordpress.com/tos" target="_blank" type="external" />,
|
|
|
|
detailsLink: (
|
|
|
|
<Link
|
|
|
|
href="https://jetpack.com/support/what-data-does-jetpack-sync"
|
|
|
|
target="_blank"
|
|
|
|
type="external"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
</p>
|
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
2019-10-10 14:05:13 +00:00
|
|
|
onClick={ () => this.setState( { showUsageModal: true, continueAction: 'wizard' } ) }
|
2019-05-30 06:31:07 +00:00
|
|
|
className="woocommerce-profile-wizard__continue"
|
2019-05-28 14:05:55 +00:00
|
|
|
>
|
2019-05-27 16:37:02 +00:00
|
|
|
{ __( 'Get started', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
<p>
|
2019-10-10 14:05:13 +00:00
|
|
|
<Button
|
|
|
|
isLink
|
|
|
|
className="woocommerce-profile-wizard__skip"
|
|
|
|
onClick={ () => this.setState( { showUsageModal: true, continueAction: 'skip' } ) }
|
|
|
|
>
|
2019-10-24 16:20:32 +00:00
|
|
|
{ sprintf( __( 'Proceed without %s', 'woocommerce-admin' ), pluginNamesString ) }
|
2019-08-02 13:22:11 +00:00
|
|
|
</Button>
|
2019-05-27 16:37:02 +00:00
|
|
|
</p>
|
2019-05-22 16:19:56 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
|
|
|
getProfileItemsError,
|
|
|
|
getActivePlugins,
|
|
|
|
getOptions,
|
|
|
|
getProfileItems,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = select( 'wc-api' );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
const isProfileItemsError = Boolean( getProfileItemsError() );
|
|
|
|
|
2019-10-22 23:55:57 +00:00
|
|
|
const options = getOptions( [ 'woocommerce_setup_jetpack_opted_in', 'wc_connect_options' ] );
|
|
|
|
const tosAccepted = get( options, [ 'wc_connect_options' ], {} ).tos_accepted;
|
2019-10-10 14:05:13 +00:00
|
|
|
|
2019-08-23 12:56:57 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
2019-10-17 14:57:29 +00:00
|
|
|
const profileItems = getProfileItems();
|
2019-08-23 12:56:57 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
isProfileItemsError,
|
|
|
|
activePlugins,
|
2019-10-22 23:55:57 +00:00
|
|
|
tosAccepted,
|
2019-10-17 14:57:29 +00:00
|
|
|
profileItems,
|
2019-10-24 16:20:32 +00:00
|
|
|
isJetpackConnected: isJetpackConnected(),
|
2019-08-23 12:56:57 +00:00
|
|
|
};
|
2019-05-31 04:51:33 +00:00
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-10-10 14:05:13 +00:00
|
|
|
const { updateProfileItems, updateOptions } = dispatch( 'wc-api' );
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-05-31 04:51:33 +00:00
|
|
|
updateProfileItems,
|
2019-10-03 16:03:29 +00:00
|
|
|
updateOptions,
|
2019-05-31 04:51:33 +00:00
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Start );
|