2019-05-22 16:19:56 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } 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-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal depdencies
|
|
|
|
*/
|
|
|
|
import { Card, H, Link } from '@woocommerce/components';
|
|
|
|
import SecurityIcon from './images/security';
|
|
|
|
import SalesTaxIcon from './images/local_atm';
|
|
|
|
import SpeedIcon from './images/flash_on';
|
|
|
|
import MobileAppIcon from './images/phone_android';
|
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
|
|
|
|
|
|
|
const benefits = [
|
|
|
|
{
|
|
|
|
title: __( 'Security', 'woocommerce-admin' ),
|
|
|
|
icon: <SecurityIcon />,
|
|
|
|
description: __(
|
|
|
|
'Jetpack automatically blocks brute force attacks to protect your store from unauthorized access.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-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-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-07-23 03:26:46 +00:00
|
|
|
const { 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-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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-31 04:51:33 +00:00
|
|
|
const { allowTracking } = this.state;
|
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( {
|
|
|
|
mixedString: __(
|
|
|
|
'Simplify and enhance the setup of your store with features and benefits offered by ' +
|
|
|
|
'{{strong}}Jetpack & WooCommerce Services{{/strong}}.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
components: {
|
|
|
|
strong: <strong />,
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<Card>
|
|
|
|
<div className="woocommerce-profile-wizard__benefits">
|
|
|
|
{ benefits.map( benefit => this.renderBenefit( benefit ) ) }
|
2019-05-22 16:19:56 +00:00
|
|
|
</div>
|
|
|
|
|
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"
|
2019-07-04 15:56:28 +00:00
|
|
|
className="woocommerce-profile-wizard__toggle"
|
2019-05-28 14:05:55 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<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-05-27 16:37:02 +00:00
|
|
|
{ __( 'Proceed without Jetpack or WooCommerce Services', 'woocommerce-admin' ) }
|
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 => {
|
|
|
|
const { getProfileItemsError, getSettings, getSettingsError, isGetSettingsRequesting } = select(
|
|
|
|
'wc-api'
|
|
|
|
);
|
|
|
|
|
|
|
|
const isSettingsError = Boolean( getSettingsError( 'advanced' ) );
|
|
|
|
const isSettingsRequesting = isGetSettingsRequesting( 'advanced' );
|
|
|
|
const isProfileItemsError = Boolean( getProfileItemsError() );
|
|
|
|
|
|
|
|
return { getSettings, isSettingsError, isProfileItemsError, isSettingsRequesting };
|
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { updateProfileItems, updateSettings } = dispatch( 'wc-api' );
|
|
|
|
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,
|
|
|
|
updateSettings,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Start );
|