2020-02-17 11:12:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import Button from '@woocommerce/base-components/button';
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2020-03-03 10:46:53 +00:00
|
|
|
import AddressForm from '../address-form';
|
2020-02-17 11:12:15 +00:00
|
|
|
|
|
|
|
const ShippingCalculatorAddress = ( { address: initialAddress, onUpdate } ) => {
|
|
|
|
const [ address, setAddress ] = useState( initialAddress );
|
|
|
|
|
|
|
|
return (
|
2020-02-19 15:10:26 +00:00
|
|
|
<form className="wc-block-shipping-calculator-address">
|
2020-03-03 10:46:53 +00:00
|
|
|
<AddressForm
|
|
|
|
fields={ [ 'country', 'state', 'city', 'postcode' ] }
|
|
|
|
onChange={ setAddress }
|
|
|
|
values={ address }
|
2020-02-17 11:12:15 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
className="wc-block-shipping-calculator-address__button"
|
|
|
|
disabled={ isShallowEqual( address, initialAddress ) }
|
2020-03-05 19:54:05 +00:00
|
|
|
onClick={ ( e ) => {
|
|
|
|
e.preventDefault();
|
|
|
|
return onUpdate( address );
|
|
|
|
} }
|
2020-02-21 16:26:27 +00:00
|
|
|
type="submit"
|
2020-02-17 11:12:15 +00:00
|
|
|
>
|
|
|
|
{ __( 'Update', 'woo-gutenberg-products-block' ) }
|
|
|
|
</Button>
|
2020-02-19 15:10:26 +00:00
|
|
|
</form>
|
2020-02-17 11:12:15 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ShippingCalculatorAddress.propTypes = {
|
|
|
|
address: PropTypes.shape( {
|
|
|
|
city: PropTypes.string,
|
|
|
|
state: PropTypes.string,
|
|
|
|
postcode: PropTypes.string,
|
|
|
|
country: PropTypes.string,
|
|
|
|
} ),
|
|
|
|
onUpdate: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShippingCalculatorAddress;
|