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-05-28 14:05:55 +00:00
|
|
|
import { FormToggle } from '@wordpress/components';
|
|
|
|
import { Button, CheckboxControl } 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-08-23 12:56:57 +00:00
|
|
|
import { filter } 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-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-05-22 16:19:56 +00:00
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
class Start extends Component {
|
2019-05-22 16:19:56 +00:00
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
|
|
|
|
this.state = {
|
2019-05-31 04:51:33 +00:00
|
|
|
allowTracking: true,
|
2019-05-22 16:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onTrackingChange = this.onTrackingChange.bind( this );
|
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() {
|
|
|
|
if (
|
|
|
|
this.props.activePlugins.includes( 'jetpack' ) &&
|
|
|
|
this.props.activePlugins.includes( 'woocommerce-services' )
|
|
|
|
) {
|
|
|
|
return updateQueryString( { step: 'store-details' } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 16:51:56 +00:00
|
|
|
async updateTracking() {
|
|
|
|
const { updateSettings } = this.props;
|
|
|
|
const allowTracking = this.state.allowTracking ? 'yes' : 'no';
|
|
|
|
await updateSettings( { advanced: { woocommerce_allow_tracking: allowTracking } } );
|
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async skipWizard() {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice, isProfileItemsError, updateProfileItems, isSettingsError } = this.props;
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-07-01 18:13:29 +00:00
|
|
|
recordEvent( 'storeprofiler_welcome_clicked', { proceed_without_install: true } );
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
await updateProfileItems( { skipped: true } );
|
2019-06-21 16:51:56 +00:00
|
|
|
await this.updateTracking();
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-06-21 16:51:56 +00:00
|
|
|
if ( isProfileItemsError || isSettingsError ) {
|
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
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async startWizard() {
|
2019-10-03 16:03:29 +00:00
|
|
|
const { updateOptions, createNotice, isSettingsError } = this.props;
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-07-01 18:13:29 +00:00
|
|
|
recordEvent( 'storeprofiler_welcome_clicked', { get_started: true } );
|
|
|
|
|
2019-10-03 16:03:29 +00:00
|
|
|
await updateOptions( {
|
|
|
|
woocommerce_setup_jetpack_opted_in: true,
|
|
|
|
} );
|
2019-06-21 16:51:56 +00:00
|
|
|
await this.updateTracking();
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
if ( ! isSettingsError ) {
|
|
|
|
this.props.goToNextStep();
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
onTrackingChange() {
|
|
|
|
this.setState( {
|
2019-05-31 04:51:33 +00:00
|
|
|
allowTracking: ! this.state.allowTracking,
|
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() {
|
|
|
|
const { activePlugins } = this.props;
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: __( 'Security', 'woocommerce-admin' ),
|
|
|
|
icon: <SecurityIcon />,
|
|
|
|
description: __(
|
|
|
|
'Jetpack automatically blocks brute force attacks to protect your store from unauthorized access.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
visible: ! activePlugins.includes( 'jetpack' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
visible: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
visible: ! activePlugins.includes( 'jetpack' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
visible: ! activePlugins.includes( 'jetpack' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
visible:
|
|
|
|
activePlugins.includes( 'jetpack' ) && ! activePlugins.includes( 'woocommerce-services' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
visible:
|
|
|
|
activePlugins.includes( 'jetpack' ) && ! activePlugins.includes( 'woocommerce-services' ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-31 04:51:33 +00:00
|
|
|
const { allowTracking } = this.state;
|
2019-08-23 12:56:57 +00:00
|
|
|
const { activePlugins } = this.props;
|
|
|
|
const pluginNames = activePlugins.includes( 'jetpack' )
|
|
|
|
? __( 'WooCommerce Services', 'woocommerce-admin' )
|
|
|
|
: __( 'Jetpack & WooCommerce Services', 'woocommerce-admin' );
|
2019-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
const trackingLabel = interpolateComponents( {
|
|
|
|
mixedString: __(
|
2019-05-28 14:05:55 +00:00
|
|
|
'Help improve WooCommerce with {{link}}usage tracking{{/link}}',
|
2019-05-22 16:19:56 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
components: {
|
|
|
|
link: (
|
|
|
|
<Link href="https://woocommerce.com/usage-tracking" target="_blank" type="external" />
|
|
|
|
),
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
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'
|
|
|
|
),
|
|
|
|
pluginNames
|
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-05-28 14:05:55 +00:00
|
|
|
<div className="woocommerce-profile-wizard__tracking">
|
|
|
|
<CheckboxControl
|
|
|
|
className="woocommerce-profile-wizard__tracking-checkbox"
|
2019-05-31 04:51:33 +00:00
|
|
|
checked={ allowTracking }
|
2019-05-28 14:05:55 +00:00
|
|
|
label={ __( trackingLabel, 'woocommerce-admin' ) }
|
|
|
|
onChange={ this.onTrackingChange }
|
|
|
|
/>
|
|
|
|
|
|
|
|
<FormToggle
|
|
|
|
aria-hidden="true"
|
2019-05-31 04:51:33 +00:00
|
|
|
checked={ allowTracking }
|
2019-05-28 14:05:55 +00:00
|
|
|
onChange={ this.onTrackingChange }
|
|
|
|
onClick={ e => e.stopPropagation() }
|
|
|
|
tabIndex="-1"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
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
|
|
|
|
onClick={ this.startWizard }
|
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-08-02 13:22:11 +00:00
|
|
|
<Button isLink className="woocommerce-profile-wizard__skip" onClick={ this.skipWizard }>
|
2019-08-23 12:56:57 +00:00
|
|
|
{ sprintf( __( 'Proceed without %s', 'woocommerce-admin' ), pluginNames ) }
|
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-08-23 12:56:57 +00:00
|
|
|
const {
|
|
|
|
getProfileItemsError,
|
|
|
|
getSettings,
|
|
|
|
getSettingsError,
|
|
|
|
isGetSettingsRequesting,
|
|
|
|
getActivePlugins,
|
|
|
|
} = select( 'wc-api' );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
const isSettingsError = Boolean( getSettingsError( 'advanced' ) );
|
|
|
|
const isSettingsRequesting = isGetSettingsRequesting( 'advanced' );
|
|
|
|
const isProfileItemsError = Boolean( getProfileItemsError() );
|
|
|
|
|
2019-08-23 12:56:57 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
|
|
|
|
|
|
|
return {
|
|
|
|
getSettings,
|
|
|
|
isSettingsError,
|
|
|
|
isProfileItemsError,
|
|
|
|
isSettingsRequesting,
|
|
|
|
activePlugins,
|
|
|
|
};
|
2019-05-31 04:51:33 +00:00
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-10-03 16:03:29 +00:00
|
|
|
const { updateProfileItems, updateOptions, updateSettings } = 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
|
|
|
updateSettings,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Start );
|