From f061323d26c467987b2d36e084d000422f65dd98 Mon Sep 17 00:00:00 2001 From: Moon Date: Mon, 11 Mar 2024 14:22:40 -0700 Subject: [PATCH] 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 --- .../settings/general/store-address.tsx | 3 +++ .../test/__snapshots__/index.js.snap | 12 ++++----- .../fills/tax/components/store-location.tsx | 25 ++++++++++++++++--- .../client/task-lists/fills/tax/utils.ts | 8 ++++-- .../45367-fix-44805-cannot-configure-tax-rate | 4 +++ 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 plugins/woocommerce/changelog/45367-fix-44805-cannot-configure-tax-rate diff --git a/plugins/woocommerce-admin/client/dashboard/components/settings/general/store-address.tsx b/plugins/woocommerce-admin/client/dashboard/components/settings/general/store-address.tsx index 1fce7fa37a3..413269e631f 100644 --- a/plugins/woocommerce-admin/client/dashboard/components/settings/general/store-address.tsx +++ b/plugins/woocommerce-admin/client/dashboard/components/settings/general/store-address.tsx @@ -375,6 +375,7 @@ export function StoreAddress( { { ! locale?.address_1?.hidden && ( { 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; } diff --git a/plugins/woocommerce-admin/client/task-lists/fills/tax/utils.ts b/plugins/woocommerce-admin/client/task-lists/fills/tax/utils.ts index 72290d430a1..d938ae9ac9d 100644 --- a/plugins/woocommerce-admin/client/task-lists/fills/tax/utils.ts +++ b/plugins/woocommerce-admin/client/task-lists/fills/tax/utils.ts @@ -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 ); }; /** diff --git a/plugins/woocommerce/changelog/45367-fix-44805-cannot-configure-tax-rate b/plugins/woocommerce/changelog/45367-fix-44805-cannot-configure-tax-rate new file mode 100644 index 00000000000..a992440a6e1 --- /dev/null +++ b/plugins/woocommerce/changelog/45367-fix-44805-cannot-configure-tax-rate @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Tax task - do not require postcode input for countries without postcode. \ No newline at end of file