feat: add international phone number support#93
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds optional international phone number validation to the Join Flow, gated behind a new WordPress setting and using google-libphonenumber for region-aware checks.
Changes:
- Add
google-libphonenumber-based validation forphoneNumber, usingaddressCountrywhen available and requiring international format when it isn’t. - Add a new WP setting (
enable_international_phone_numbers) and expose it to the frontend env payload. - Prevent address fields from being required in the schema when the address section is hidden.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/join-flow/src/schema.ts | Adds libphonenumber validation + adjusts address-required logic based on HIDE_ADDRESS. |
| packages/join-flow/package.json | Adds google-libphonenumber dependency and TypeScript types. |
| packages/join-block/src/Settings.php | Adds admin setting to enable international phone validation (help text needs alignment). |
| packages/join-block/src/Blocks.php | Exposes ENABLE_INTERNATIONAL_PHONE_NUMBERS to the Join Flow frontend env JSON. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+183
to
+185
| phoneNumber: Boolean(getEnv("ENABLE_INTERNATIONAL_PHONE_NUMBERS")) | ||
| ? string().when("addressCountry", (country: string, schema) => { | ||
| const required = Boolean(getEnv("REQUIRE_PHONE_NUMBER")); |
Comment on lines
+186
to
+195
| const message = country | ||
| ? "Please enter a valid phone number" | ||
| : "Please enter a valid phone number, including the country code (e.g. +44...)"; | ||
| const test = schema.test( | ||
| "is-valid-phone", | ||
| message, | ||
| (value: string | undefined) => isValidInternationalPhone(value, country) | ||
| ); | ||
| return required ? test.required("Phone number is required") : test; | ||
| }) |
Comment on lines
+64
to
+66
| 'When enabled, phone numbers are validated against the country selected in the address. ' . | ||
| 'If the address section is hidden, members must enter a number in international format ' . | ||
| '(e.g. +44...). Otherwise, only UK numbers are accepted.' |
Comment on lines
21
to
25
| "bootstrap": "^4.5.2", | ||
| "css-loader": "^6.8.1", | ||
| "date-fns": "^2.16.1", | ||
| "google-libphonenumber": "^3.2.33", | ||
| "dotenv": "^8.2.0", |
4b34bfb to
d7feded
Compare
d7feded to
fa8f6ee
Compare
Comment on lines
+172
to
+174
| phoneNumber: Boolean(getEnv("ENABLE_INTERNATIONAL_PHONE_NUMBERS")) | ||
| ? string().when("addressCountry", (country: string, schema) => { | ||
| const required = Boolean(getEnv("REQUIRE_PHONE_NUMBER")); |
Comment on lines
+22
to
+23
| try { | ||
| const parsed = phoneUtil.parse(value, country || undefined); |
Comment on lines
+172
to
197
| phoneNumber: Boolean(getEnv("ENABLE_INTERNATIONAL_PHONE_NUMBERS")) | ||
| ? string().when("addressCountry", (country: string, schema) => { | ||
| const required = Boolean(getEnv("REQUIRE_PHONE_NUMBER")); | ||
| const message = country | ||
| ? "Please enter a valid phone number" | ||
| : "Please enter a valid phone number, including the country code (e.g. +44...)"; | ||
| const test = schema.test( | ||
| "is-valid-phone", | ||
| message, | ||
| (value: string | undefined) => isValidInternationalPhone(value, country) | ||
| ); | ||
| return required ? test.required("Phone number is required") : test; | ||
| }) | ||
| : Boolean(getEnv("REQUIRE_PHONE_NUMBER")) | ||
| ? string() | ||
| .phone("GB", false, "A valid UK phone number is required") | ||
| .required() | ||
| .test( | ||
| "is-valid-phone", | ||
| "A valid UK phone number is required", | ||
| (value) => isValidInternationalPhone(value, "GB") | ||
| ) | ||
| .required("Phone number is required") | ||
| : string().test( | ||
| // .test() used because .phone() forces .required() | ||
| "is-valid-phone", | ||
| "Please enter a valid UK phone number", | ||
| (value) => !value || string().phone("GB", false).isValidSync(value) | ||
| (value) => isValidInternationalPhone(value, "GB") | ||
| ), |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.