This commit is contained in:
Seghir Nadir 2021-06-01 09:46:02 +01:00 committed by GitHub
parent 28206058d8
commit 1b87589f82
6 changed files with 3 additions and 31 deletions

View File

@ -7,7 +7,6 @@ import ProductName from '@woocommerce/base-components/product-name';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
mustContain,
Label,
} from '@woocommerce/blocks-checkout';
@ -48,7 +47,7 @@ const OrderSummaryItem = ( { cartItem } ) => {
const { receiveCart, ...cart } = useStoreCart();
const productPriceValidation = useCallback(
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
( value ) => mustContain( value, '<price/>' ),
[]
);
@ -68,7 +67,6 @@ const OrderSummaryItem = ( { cartItem } ) => {
defaultValue: initialName,
extensions,
arg,
validation: mustBeString,
} );
const regularPriceSingle = Dinero( {

View File

@ -7,7 +7,6 @@ import { RemovableChip } from '@woocommerce/base-components/chip';
import PropTypes from 'prop-types';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
TotalsItem,
} from '@woocommerce/blocks-checkout';
import { getSetting } from '@woocommerce/settings';
@ -60,7 +59,6 @@ const TotalsDiscount = ( {
{ cartCoupons.map( ( cartCoupon ) => {
const filteredCouponCode = __experimentalApplyCheckoutFilter(
{
validation: mustBeString,
arg: {
context: 'summary',
coupon: cartCoupon,

View File

@ -7,7 +7,6 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone
import PropTypes from 'prop-types';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
TotalsItem,
} from '@woocommerce/blocks-checkout';
import { useStoreCart } from '@woocommerce/base-context/hooks';
@ -34,8 +33,6 @@ const TotalsFooterItem = ( { currency, values } ) => {
defaultValue: __( 'Total', 'woo-gutenberg-products-block' ),
extensions: cart.extensions,
arg: { cart },
// Only accept strings.
validation: mustBeString,
} );
const parsedTaxValue = parseInt( totalTax, 10 );

View File

@ -24,7 +24,6 @@ import {
} from '@woocommerce/price-format';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
mustContain,
} from '@woocommerce/blocks-checkout';
import Dinero from 'dinero.js';
@ -112,7 +111,7 @@ const CartLineItemRow = ( {
const { dispatchStoreEvent } = useStoreEvents();
const productPriceValidation = useCallback(
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
( value ) => mustContain( value, '<price/>' ),
[]
);
@ -134,7 +133,6 @@ const CartLineItemRow = ( {
defaultValue: initialName,
extensions,
arg,
validation: mustBeString,
} );
const regularAmountSingle = Dinero( {

View File

@ -74,7 +74,7 @@ export const __experimentalApplyCheckoutFilter = < T >( {
/** Object containing arguments for the filter function. */
arg: CheckoutFilterArguments;
/** Function that needs to return true when the filtered value is passed in order for the filter to be applied. */
validation: ( value: unknown ) => true | Error;
validation?: ( value: T ) => true | Error;
} ): T => {
return useMemo( () => {
const filters = getCheckoutFilters( filterName );

View File

@ -3,25 +3,6 @@
*/
import { __, sprintf } from '@wordpress/i18n';
/**
* Checks if value passed is a string, throws an error if not.
*/
export const mustBeString = ( value: unknown ): true | Error => {
if ( typeof value !== 'string' ) {
throw Error(
sprintf(
/* translators: %s is type of value passed */
__(
'Returned value must be a string, you passed "%s"',
'woo-gutenberg-products-block'
),
typeof value
)
);
}
return true;
};
/**
* Checks if value passed contain passed label.
*/