Decode address entities in shipping calculator (https://github.com/woocommerce/woocommerce-blocks/pull/2009)

* Fix wrong optional label for city

* Decode all address entities in shipping calculator

* Move decodeEntities to useShippingRates

* Move decodeEntities to useShippingAddress
This commit is contained in:
Albert Juhé Lluveras 2020-03-24 11:28:19 +01:00 committed by GitHub
parent 2ba75fdc25
commit c7e20c29d9
2 changed files with 11 additions and 5 deletions

View File

@ -87,10 +87,7 @@ const AddressFields = {
}, },
city: { city: {
label: __( 'City', 'woo-gutenberg-products-block' ), label: __( 'City', 'woo-gutenberg-products-block' ),
optionalLabel: __( optionalLabel: __( 'City (optional)', 'woo-gutenberg-products-block' ),
'Apartment, suite, etc. (optional)',
'woo-gutenberg-products-block'
),
autocomplete: 'address-level2', autocomplete: 'address-level2',
required: true, required: true,
hidden: false, hidden: false,

View File

@ -6,6 +6,7 @@ import { useEffect, useState } from '@wordpress/element';
import isShallowEqual from '@wordpress/is-shallow-equal'; import isShallowEqual from '@wordpress/is-shallow-equal';
import { useDebounce } from 'use-debounce'; import { useDebounce } from 'use-debounce';
import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data'; import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data';
import { decodeEntities } from '@wordpress/html-entities';
/** /**
* Internal dependencies * Internal dependencies
@ -39,8 +40,16 @@ export const useShippingAddress = () => {
); );
} }
}, [ debouncedShippingAddress ] ); }, [ debouncedShippingAddress ] );
const decodedShippingAddress = {};
Object.keys( shippingAddress ).forEach( ( key ) => {
decodedShippingAddress[ key ] = decodeEntities(
shippingAddress[ key ]
);
} );
return { return {
shippingAddress, shippingAddress: decodedShippingAddress,
setShippingAddress, setShippingAddress,
}; };
}; };