Tax task - Make postcode optional for countries without postcodes (#45367)
* Set field IDs * Validate post code only when it is actually required * Add changefile(s) from automation for the following project(s): woocommerce * Remove unused import * Update test snapshot * Update test snapshot --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
f901f60e4c
commit
f061323d26
|
@ -375,6 +375,7 @@ export function StoreAddress( {
|
|||
|
||||
{ ! locale?.address_1?.hidden && (
|
||||
<TextControl
|
||||
id={ 'woocommerce-store-address-form-address_1' }
|
||||
label={
|
||||
locale?.address_1?.label ||
|
||||
__( 'Address', 'woocommerce' )
|
||||
|
@ -386,6 +387,7 @@ export function StoreAddress( {
|
|||
|
||||
{ ! locale?.postcode?.hidden && (
|
||||
<TextControl
|
||||
id={ 'woocommerce-store-address-form-postcode' }
|
||||
label={
|
||||
locale?.postcode?.label ||
|
||||
__( 'Post code', 'woocommerce' )
|
||||
|
@ -397,6 +399,7 @@ export function StoreAddress( {
|
|||
|
||||
{ ! locale?.city?.hidden && (
|
||||
<TextControl
|
||||
id={ 'woocommerce-store-address-form-city' }
|
||||
label={ locale?.city?.label || __( 'City', 'woocommerce' ) }
|
||||
{ ...getInputProps( 'city' ) }
|
||||
autoComplete="address-level2"
|
||||
|
|
|
@ -144,7 +144,7 @@ Object {
|
|||
<input
|
||||
autocomplete="address-line1"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-0"
|
||||
id="woocommerce-store-address-form-address_1"
|
||||
placeholder="Address"
|
||||
type="text"
|
||||
value=""
|
||||
|
@ -168,7 +168,7 @@ Object {
|
|||
<input
|
||||
autocomplete="postal-code"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-1"
|
||||
id="woocommerce-store-address-form-postcode"
|
||||
placeholder="Post code"
|
||||
type="text"
|
||||
value=""
|
||||
|
@ -192,7 +192,7 @@ Object {
|
|||
<input
|
||||
autocomplete="address-level2"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-2"
|
||||
id="woocommerce-store-address-form-city"
|
||||
placeholder="City"
|
||||
type="text"
|
||||
value=""
|
||||
|
@ -459,7 +459,7 @@ Object {
|
|||
<input
|
||||
autocomplete="address-line1"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-0"
|
||||
id="woocommerce-store-address-form-address_1"
|
||||
placeholder="Address"
|
||||
type="text"
|
||||
value=""
|
||||
|
@ -483,7 +483,7 @@ Object {
|
|||
<input
|
||||
autocomplete="postal-code"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-1"
|
||||
id="woocommerce-store-address-form-postcode"
|
||||
placeholder="Post code"
|
||||
type="text"
|
||||
value=""
|
||||
|
@ -507,7 +507,7 @@ Object {
|
|||
<input
|
||||
autocomplete="address-level2"
|
||||
class="components-text-control__input"
|
||||
id="inspector-text-control-2"
|
||||
id="woocommerce-store-address-form-city"
|
||||
placeholder="City"
|
||||
type="text"
|
||||
value=""
|
||||
|
|
|
@ -21,17 +21,27 @@ import {
|
|||
const validateLocationForm = ( values: FormValues ) => {
|
||||
const errors = defaultValidate( values );
|
||||
|
||||
if ( ! values.addressLine1.trim().length ) {
|
||||
if (
|
||||
document.getElementById( 'woocommerce-store-address-form-address_1' ) &&
|
||||
! values.addressLine1.trim().length
|
||||
) {
|
||||
errors.addressLine1 = __( 'Please enter an address', 'woocommerce' );
|
||||
}
|
||||
|
||||
if ( ! values.postCode.trim().length ) {
|
||||
if (
|
||||
document.getElementById( 'woocommerce-store-address-form-postcode' ) &&
|
||||
! values.postCode.trim().length
|
||||
) {
|
||||
errors.postCode = __( 'Please enter a post code', 'woocommerce' );
|
||||
}
|
||||
|
||||
if ( ! values.city.trim().length ) {
|
||||
if (
|
||||
document.getElementById( 'woocommerce-store-address-form-city' ) &&
|
||||
! values.city.trim().length
|
||||
) {
|
||||
errors.city = __( 'Please enter a city', 'woocommerce' );
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
||||
|
@ -63,7 +73,14 @@ export const StoreLocation: React.FC< {
|
|||
if (
|
||||
isResolving ||
|
||||
isUpdating ||
|
||||
! hasCompleteAddress( generalSettings || {} )
|
||||
! hasCompleteAddress(
|
||||
generalSettings || {},
|
||||
Boolean(
|
||||
document.getElementById(
|
||||
'woocommerce-store-address-form-postcode'
|
||||
)
|
||||
)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,14 +18,18 @@ export const AUTOMATION_PLUGINS = [ 'woocommerce-services' ];
|
|||
* @param {Object} generalSettings.woocommerce_store_postcode Store postal code.
|
||||
*/
|
||||
export const hasCompleteAddress = (
|
||||
generalSettings: Record< string, string >
|
||||
generalSettings: Record< string, string >,
|
||||
requiresPostcode = true
|
||||
): boolean => {
|
||||
const {
|
||||
woocommerce_store_address: storeAddress,
|
||||
woocommerce_default_country: defaultCountry,
|
||||
woocommerce_store_postcode: storePostCode,
|
||||
} = generalSettings;
|
||||
return Boolean( storeAddress && defaultCountry && storePostCode );
|
||||
if ( requiresPostcode ) {
|
||||
return Boolean( storeAddress && defaultCountry && storePostCode );
|
||||
}
|
||||
return Boolean( storeAddress && defaultCountry );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Tax task - do not require postcode input for countries without postcode.
|
Loading…
Reference in New Issue