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:
Moon 2024-03-11 14:22:40 -07:00 committed by GitHub
parent f901f60e4c
commit f061323d26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 12 deletions

View File

@ -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"

View File

@ -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=""

View File

@ -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;
}

View File

@ -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 );
};
/**

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Tax task - do not require postcode input for countries without postcode.