2020-02-14 03:43:13 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-02-19 10:51:15 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-02-14 03:43:13 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2020-03-05 19:54:05 +00:00
|
|
|
import { usePrevious } from '@woocommerce/base-hooks';
|
2020-02-14 03:43:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-02-25 09:32:59 +00:00
|
|
|
import Packages from './packages';
|
2020-02-19 10:51:15 +00:00
|
|
|
import LoadingMask from '../loading-mask';
|
2020-02-25 09:32:59 +00:00
|
|
|
import './style.scss';
|
2020-02-14 03:43:13 +00:00
|
|
|
|
|
|
|
const ShippingRatesControl = ( {
|
2020-03-05 19:54:05 +00:00
|
|
|
shippingRates,
|
|
|
|
shippingRatesLoading,
|
2020-02-14 03:43:13 +00:00
|
|
|
className,
|
|
|
|
noResultsMessage,
|
|
|
|
renderOption,
|
|
|
|
} ) => {
|
2020-02-19 10:51:15 +00:00
|
|
|
const previousShippingRates = usePrevious(
|
|
|
|
shippingRates,
|
|
|
|
( newRates ) => newRates.length > 0
|
|
|
|
);
|
|
|
|
|
2020-02-25 09:32:59 +00:00
|
|
|
return (
|
2020-02-27 18:28:36 +00:00
|
|
|
<LoadingMask
|
|
|
|
isLoading={ shippingRatesLoading }
|
|
|
|
screenReaderLabel={ __(
|
|
|
|
'Loading shipping rates…',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
showSpinner={ true }
|
|
|
|
>
|
|
|
|
<Packages
|
|
|
|
className={ className }
|
|
|
|
noResultsMessage={ noResultsMessage }
|
|
|
|
renderOption={ renderOption }
|
|
|
|
shippingRates={ previousShippingRates || shippingRates }
|
|
|
|
/>
|
|
|
|
</LoadingMask>
|
2020-02-25 09:32:59 +00:00
|
|
|
);
|
2020-02-14 03:43:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ShippingRatesControl.propTypes = {
|
|
|
|
address: PropTypes.shape( {
|
|
|
|
address_1: PropTypes.string,
|
|
|
|
address_2: PropTypes.string,
|
|
|
|
city: PropTypes.string,
|
|
|
|
state: PropTypes.string,
|
|
|
|
postcode: PropTypes.string,
|
|
|
|
country: PropTypes.string,
|
|
|
|
} ),
|
|
|
|
noResultsMessage: PropTypes.string.isRequired,
|
|
|
|
renderOption: PropTypes.func.isRequired,
|
|
|
|
className: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShippingRatesControl;
|
2020-02-25 09:32:59 +00:00
|
|
|
export { Packages };
|