2019-08-21 05:58:47 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-12-02 17:39:22 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
2019-08-21 05:58:47 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
|
|
|
import { Form } from '@woocommerce/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
StoreAddress,
|
|
|
|
validateStoreAddress,
|
2020-08-13 02:05:22 +00:00
|
|
|
} from '../../../dashboard/components/settings/general/store-address';
|
2019-08-21 05:58:47 +00:00
|
|
|
|
|
|
|
export default class StoreLocation extends Component {
|
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
this.onSubmit = this.onSubmit.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
async onSubmit( values ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
onComplete,
|
|
|
|
createNotice,
|
|
|
|
isSettingsError,
|
2020-04-21 00:12:38 +00:00
|
|
|
updateAndPersistSettingsForGroup,
|
2020-06-23 02:47:02 +00:00
|
|
|
settings,
|
2020-02-14 02:23:21 +00:00
|
|
|
} = this.props;
|
2019-08-21 05:58:47 +00:00
|
|
|
|
2020-04-21 00:12:38 +00:00
|
|
|
await updateAndPersistSettingsForGroup( 'general', {
|
2019-08-21 05:58:47 +00:00
|
|
|
general: {
|
2020-06-23 02:47:02 +00:00
|
|
|
...settings,
|
2019-08-21 05:58: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,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( ! isSettingsError ) {
|
2019-10-07 20:27:34 +00:00
|
|
|
onComplete( values );
|
2019-08-21 05:58:47 +00:00
|
|
|
} else {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
2020-02-14 02:23:21 +00:00
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem saving your store location',
|
2020-02-14 02:23:21 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
2019-08-21 05:58:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getInitialValues() {
|
|
|
|
const { settings } = this.props;
|
|
|
|
|
|
|
|
const {
|
2020-02-14 02:23:21 +00:00
|
|
|
woocommerce_store_address: storeAddress,
|
|
|
|
woocommerce_store_address_2: storeAddress2,
|
|
|
|
woocommerce_store_city: storeCity,
|
|
|
|
woocommerce_default_country: defaultCountry,
|
|
|
|
woocommerce_store_postcode: storePostcode,
|
2019-08-21 05:58:47 +00:00
|
|
|
} = settings;
|
|
|
|
|
|
|
|
return {
|
2020-02-14 02:23:21 +00:00
|
|
|
addressLine1: storeAddress || '',
|
|
|
|
addressLine2: storeAddress2 || '',
|
|
|
|
city: storeCity || '',
|
|
|
|
countryState: defaultCountry || '',
|
|
|
|
postCode: storePostcode || '',
|
2019-08-21 05:58:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { isSettingsRequesting } = this.props;
|
|
|
|
|
|
|
|
if ( isSettingsRequesting ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
initialValues={ this.getInitialValues() }
|
2021-05-18 04:24:24 +00:00
|
|
|
onSubmit={ this.onSubmit }
|
2019-08-21 05:58:47 +00:00
|
|
|
validate={ validateStoreAddress }
|
|
|
|
>
|
2019-10-30 23:44:57 +00:00
|
|
|
{ ( { getInputProps, handleSubmit, setValue } ) => (
|
2019-08-21 05:58:47 +00:00
|
|
|
<Fragment>
|
2020-02-14 02:23:21 +00:00
|
|
|
<StoreAddress
|
|
|
|
getInputProps={ getInputProps }
|
|
|
|
setValue={ setValue }
|
|
|
|
/>
|
2019-08-21 05:58:47 +00:00
|
|
|
<Button isPrimary onClick={ handleSubmit }>
|
|
|
|
{ __( 'Continue', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
) }
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|