Use new util functions in ShippingRatesControl (https://github.com/woocommerce/woocommerce-blocks/pull/2153)
* Use new util functions in ShippingRatesControl * Import from base-utils
This commit is contained in:
parent
0000cac384
commit
db4f7820c6
|
@ -6,6 +6,10 @@ import { useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { speak } from '@wordpress/a11y';
|
import { speak } from '@wordpress/a11y';
|
||||||
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
import LoadingMask from '@woocommerce/base-components/loading-mask';
|
||||||
|
import {
|
||||||
|
getShippingRatesPackageCount,
|
||||||
|
getShippingRatesRateCount,
|
||||||
|
} from '@woocommerce/base-utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -25,11 +29,8 @@ const ShippingRatesControl = ( {
|
||||||
if ( shippingRatesLoading ) {
|
if ( shippingRatesLoading ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const packages = shippingRates.length;
|
const packages = getShippingRatesPackageCount( shippingRates );
|
||||||
const shippingOptions = shippingRates.reduce(
|
const shippingOptions = getShippingRatesRateCount( shippingRates );
|
||||||
( acc, shippingRate ) => acc + shippingRate.shipping_rates.length,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
if ( shippingOptions === 0 ) {
|
if ( shippingOptions === 0 ) {
|
||||||
speak(
|
speak(
|
||||||
__(
|
__(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export * from './errors';
|
export * from './errors';
|
||||||
export * from './price';
|
export * from './price';
|
||||||
export * from './address';
|
export * from './address';
|
||||||
|
export * from './shipping-rates';
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @param {Array} shippingRates Shipping rates and packages array.
|
* @param {Array} shippingRates Shipping rates and packages array.
|
||||||
*/
|
*/
|
||||||
export const getShippingRatesPackageCount = ( shippingRates ) => {
|
export const getShippingRatesPackageCount = ( shippingRates ) => {
|
||||||
return Object.keys( shippingRates ).length;
|
return shippingRates.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -15,7 +15,11 @@ import {
|
||||||
} from '@woocommerce/base-components/cart-checkout';
|
} from '@woocommerce/base-components/cart-checkout';
|
||||||
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
|
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
|
||||||
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
|
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
|
||||||
import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils';
|
import {
|
||||||
|
getCurrencyFromPriceResponse,
|
||||||
|
getShippingRatesPackageCount,
|
||||||
|
getShippingRatesRateCount,
|
||||||
|
} from '@woocommerce/base-utils';
|
||||||
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
|
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
|
||||||
import {
|
import {
|
||||||
CheckoutProvider,
|
CheckoutProvider,
|
||||||
|
@ -46,10 +50,6 @@ import CheckoutSidebar from './sidebar';
|
||||||
import CheckoutOrderError from './checkout-order-error';
|
import CheckoutOrderError from './checkout-order-error';
|
||||||
import NoShippingPlaceholder from './no-shipping-placeholder';
|
import NoShippingPlaceholder from './no-shipping-placeholder';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
import {
|
|
||||||
getShippingRatesPackageCount,
|
|
||||||
getShippingRatesRateCount,
|
|
||||||
} from './utils';
|
|
||||||
|
|
||||||
const Block = ( props ) => (
|
const Block = ( props ) => (
|
||||||
<CheckoutProvider>
|
<CheckoutProvider>
|
||||||
|
|
Loading…
Reference in New Issue