2019-05-30 07:15:39 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-08-21 05:58:47 +00:00
|
|
|
import { Button, CheckboxControl } from 'newspack-components';
|
2019-05-30 07:15:39 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { withDispatch } from '@wordpress/data';
|
2019-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-05-30 07:15:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal depdencies
|
|
|
|
*/
|
2019-08-26 05:49:04 +00:00
|
|
|
import { getCountryCode } from 'dashboard/utils';
|
2019-08-05 01:41:47 +00:00
|
|
|
import { H, Card, Form } from '@woocommerce/components';
|
2019-05-30 07:15:39 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-08-21 05:58:47 +00:00
|
|
|
import {
|
|
|
|
StoreAddress,
|
|
|
|
validateStoreAddress,
|
|
|
|
} from '../../components/settings/general/store-address';
|
2019-10-10 14:05:13 +00:00
|
|
|
import UsageModal from './usage-modal';
|
2019-05-30 07:15:39 +00:00
|
|
|
|
|
|
|
class StoreDetails extends Component {
|
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
|
2019-10-10 14:05:13 +00:00
|
|
|
this.state = {
|
|
|
|
showUsageModal: false,
|
|
|
|
};
|
|
|
|
|
2019-08-05 01:41:47 +00:00
|
|
|
this.initialValues = {
|
|
|
|
addressLine1: '',
|
|
|
|
addressLine2: '',
|
|
|
|
city: '',
|
|
|
|
countryState: '',
|
|
|
|
postCode: '',
|
|
|
|
isClient: false,
|
2019-05-30 07:15:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onContinue = this.onContinue.bind( this );
|
2019-10-10 14:05:13 +00:00
|
|
|
this.onSubmit = this.onSubmit.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit( values ) {
|
|
|
|
const { profileItems } = this.props;
|
|
|
|
|
2019-10-17 14:57:29 +00:00
|
|
|
if ( 'already-installed' === profileItems.plugins ) {
|
2019-10-10 14:05:13 +00:00
|
|
|
this.setState( { showUsageModal: true } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onContinue( values );
|
2019-05-30 07:15:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 01:41:47 +00:00
|
|
|
async onContinue( values ) {
|
2019-08-01 17:29:35 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
goToNextStep,
|
|
|
|
isSettingsError,
|
|
|
|
updateSettings,
|
|
|
|
updateProfileItems,
|
|
|
|
isProfileItemsError,
|
|
|
|
} = this.props;
|
2019-05-30 07:15:39 +00:00
|
|
|
|
2019-07-01 18:13:29 +00:00
|
|
|
recordEvent( 'storeprofiler_store_details_continue', {
|
2019-08-26 05:49:04 +00:00
|
|
|
store_country: getCountryCode( values.countryState ),
|
2019-08-05 01:41:47 +00:00
|
|
|
setup_client: values.isClient,
|
2019-07-01 18:13:29 +00:00
|
|
|
} );
|
|
|
|
|
2019-05-30 07:15:39 +00:00
|
|
|
await updateSettings( {
|
|
|
|
general: {
|
2019-08-05 01:41:47 +00:00
|
|
|
woocommerce_store_address: values.addressLine1,
|
|
|
|
woocommerce_store_address_2: values.addressLine2,
|
|
|
|
woocommerce_default_country: values.countryState,
|
|
|
|
woocommerce_store_city: values.city,
|
|
|
|
woocommerce_store_postcode: values.postCode,
|
2019-05-30 07:15:39 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2019-08-05 01:41:47 +00:00
|
|
|
await updateProfileItems( { setup_client: values.isClient } );
|
2019-08-01 17:29:35 +00:00
|
|
|
|
|
|
|
if ( ! isSettingsError && ! isProfileItemsError ) {
|
2019-05-30 07:15:39 +00:00
|
|
|
goToNextStep();
|
|
|
|
} else {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__( 'There was a problem saving your store details.', 'woocommerce-admin' )
|
|
|
|
);
|
2019-05-30 07:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-10-10 14:05:13 +00:00
|
|
|
const { showUsageModal } = this.state;
|
2019-05-30 07:15:39 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
2019-08-08 18:41:26 +00:00
|
|
|
{ __( 'Where is your store based?', 'woocommerce-admin' ) }
|
2019-05-30 07:15:39 +00:00
|
|
|
</H>
|
|
|
|
<H className="woocommerce-profile-wizard__header-subtitle">
|
2019-08-08 18:41:26 +00:00
|
|
|
{ __(
|
|
|
|
'This will help us configure your store and get you started quickly',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2019-05-30 07:15:39 +00:00
|
|
|
</H>
|
|
|
|
|
|
|
|
<Card>
|
2019-08-05 01:41:47 +00:00
|
|
|
<Form
|
|
|
|
initialValues={ this.initialValues }
|
2019-10-10 14:05:13 +00:00
|
|
|
onSubmitCallback={ this.onSubmit }
|
2019-08-21 05:58:47 +00:00
|
|
|
validate={ validateStoreAddress }
|
2019-08-05 01:41:47 +00:00
|
|
|
>
|
2019-10-10 14:05:13 +00:00
|
|
|
{ ( { getInputProps, handleSubmit, values, isValidForm } ) => (
|
2019-08-05 01:41:47 +00:00
|
|
|
<Fragment>
|
2019-10-10 14:05:13 +00:00
|
|
|
{ showUsageModal && (
|
|
|
|
<UsageModal
|
|
|
|
onContinue={ () => this.onContinue( values ) }
|
|
|
|
onClose={ () => this.setState( { showUsageModal: false } ) }
|
|
|
|
/>
|
|
|
|
) }
|
2019-08-21 05:58:47 +00:00
|
|
|
<StoreAddress getInputProps={ getInputProps } />
|
2019-08-05 01:41:47 +00:00
|
|
|
<CheckboxControl
|
2019-08-08 18:41:26 +00:00
|
|
|
label={ __( "I'm setting up a store for a client", 'woocommerce-admin' ) }
|
2019-08-05 01:41:47 +00:00
|
|
|
{ ...getInputProps( 'isClient' ) }
|
|
|
|
/>
|
|
|
|
|
2019-10-04 13:46:27 +00:00
|
|
|
<Button isPrimary onClick={ handleSubmit } disabled={ ! isValidForm }>
|
2019-08-05 01:41:47 +00:00
|
|
|
{ __( 'Continue', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
) }
|
|
|
|
</Form>
|
2019-05-30 07:15:39 +00:00
|
|
|
</Card>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
2019-10-10 14:05:13 +00:00
|
|
|
const {
|
|
|
|
getSettings,
|
|
|
|
getSettingsError,
|
|
|
|
isGetSettingsRequesting,
|
|
|
|
getProfileItemsError,
|
|
|
|
getProfileItems,
|
|
|
|
} = select( 'wc-api' );
|
|
|
|
|
|
|
|
const profileItems = getProfileItems();
|
2019-05-30 07:15:39 +00:00
|
|
|
|
|
|
|
const settings = getSettings( 'general' );
|
2019-08-01 17:29:35 +00:00
|
|
|
const isSettingsError = Boolean( getSettingsError( 'general' ) );
|
|
|
|
const isSettingsRequesting = isGetSettingsRequesting( 'general' );
|
|
|
|
const isProfileItemsError = Boolean( getProfileItemsError() );
|
2019-05-30 07:15:39 +00:00
|
|
|
|
2019-10-10 14:05:13 +00:00
|
|
|
return {
|
|
|
|
getSettings,
|
|
|
|
isProfileItemsError,
|
|
|
|
profileItems,
|
|
|
|
isSettingsError,
|
|
|
|
isSettingsRequesting,
|
|
|
|
settings,
|
|
|
|
};
|
2019-05-30 07:15:39 +00:00
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-08-01 17:29:35 +00:00
|
|
|
const { updateSettings, updateProfileItems } = dispatch( 'wc-api' );
|
2019-05-30 07:15:39 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-05-30 07:15:39 +00:00
|
|
|
updateSettings,
|
2019-08-01 17:29:35 +00:00
|
|
|
updateProfileItems,
|
2019-05-30 07:15:39 +00:00
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( StoreDetails );
|