Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug that calling split() on null value in the useStoreAddress hook #936

Merged
merged 1 commit into from
Aug 9, 2021

Conversation

eason9487
Copy link
Member

Changes proposed in this Pull Request:

  • Fix a bug that calling split() on null value in the useStoreAddress hook.
  • Make sure the returned data types of useStoreAddress hook are consistent.

image

Detailed test instructions:

  1. Clear store address via the WC Settings page or SQL:
    image
    DELETE FROM `wp_options` WHERE `option_name` IN ('woocommerce_store_address', 'woocommerce_store_address_2', 'woocommerce_store_city', 'woocommerce_default_country', 'woocommerce_store_postcode');
  2. Go to GLA's MC setup or settings pages.
  3. It should be able to render pages without the Cannot read property 'split' of null error.
  4. The returned fields in the data property of useStoreAddress hook should always be string types.

Changelog entry

Copy link
Member

@ecgan ecgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, working as expected, LGTM 👍

const [ address, address2 = '' ] = streetAddress.split( '\n' );
const country = countryNameDict[ countryCode ];
const country = countryNameDict[ wcAddress.country ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about whether want to specify fallback '' here in case wcAddress.country does not exist in countryNameDict, but in the end that is not necessary because users can only select a value from the predefined values in the country dropdown and cannot enter a value of their own, so there shouldn't be any problem.

@ecgan ecgan merged commit 18cd80b into feature/contact-info Aug 9, 2021
@ecgan ecgan deleted the fix/null-store-address branch August 9, 2021 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants