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

Contact Form: Improve phone no formatting #37603

Merged
merged 4 commits into from
Nov 14, 2019
Merged

Conversation

eltongo
Copy link
Contributor

@eltongo eltongo commented Nov 14, 2019

Changes proposed in this Pull Request

This PR introduces an improvement of formatting code of the phone input in the contact form, fixing a few annoying issues, and increasing its stability in general 🙏

Testing instructions

To replicate the issues (before applying the changes):

  • Fill in a number with the country code (e.g. +441234567), and then insert a 0 between the + and the first digit of the country code (i.e. +0441234567). You'll notice the country code will be duplicated (in this example, it will become +44441234567)
  • Open the Dev Tools. Clear the field, choose a country (e.g. UK), and enter a national phone no starting with a few zeros: (e.g 000123456), and then save. In the Network tab of Dev Tools, check the phone number that is sent in the API call: it should be +44.00123456 (i.e. only one zero removed)

After applying the fix:

  • Verify that you can enter as many zeroes as you want between the + and the first digit of the country code. Also verify that those zeroes will be removed once you submit (check the API call as well)
  • Verify that all zeroes before the national number are removed (e.g. 000123456 with UK chosen as the country, becomes +44.123456 when sent to the backend)
  • Trying to enter any amount of zeroes followed by the country code for the currently selected country should "strip" the country code from the input (e.g. choosing UK and entering 0044123, the number becomes 0123)
  • Try to make it fail... please.

The modified regex fixes a few annoying issues with the phone
input (such as duplication of country code)
@eltongo eltongo added [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Feature Group] Emails & Domains Features related to email integrations and domain management. labels Nov 14, 2019
@eltongo eltongo requested review from klimeryk and a team November 14, 2019 16:15
@eltongo eltongo self-assigned this Nov 14, 2019
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

matticbot commented Nov 14, 2019

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~124 bytes added 📈 [gzipped])

name         parsed_size           gzip_size
woocommerce        +63 B  (+0.0%)      +31 B  (+0.0%)
purchases          +63 B  (+0.0%)      +31 B  (+0.0%)
domains            +63 B  (+0.0%)      +31 B  (+0.0%)
checkout           +63 B  (+0.0%)      +31 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~92 bytes added 📈 [gzipped])

name                          parsed_size           gzip_size
async-load-design-playground        +63 B  (+0.0%)      +31 B  (+0.0%)
async-load-design-blocks            +63 B  (+0.0%)      +30 B  (+0.0%)
async-load-design                   +63 B  (+0.0%)      +31 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@eltongo eltongo added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 14, 2019
Copy link
Contributor

@klimeryk klimeryk left a comment

Choose a reason for hiding this comment

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

Tested, no obvious regressions, seems to work exactly as I'd hoped - thanks! 👍

const nationalNumber = stripNonDigits( inputNumber ).replace(
new RegExp( '^(' + numberRegion.dialCode + ')?(' + numberRegion.nationalPrefix + ')?' ),
let nationalNumber = stripNonDigits( inputNumber ).replace(
new RegExp( '^(0{0,}' + numberRegion.dialCode + ')?(' + numberRegion.nationalPrefix + ')?' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Gotta admit, at first I thought it meant "0, followed by as many 0 as you can get".

AFAIK 0{0,} == 0*? If so, I'd say the latter is the clearer way of writing it IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh I knew there was a better way, so obvious 😅

Thank you, great suggestion.

@klimeryk klimeryk added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Feature Group] Emails & Domains Features related to email integrations and domain management.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants