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: country prefill bug #299

Merged
merged 3 commits into from
Jan 31, 2024
Merged

fix: country prefill bug #299

merged 3 commits into from
Jan 31, 2024

Conversation

madassdev
Copy link
Collaborator

@madassdev madassdev commented Jan 31, 2024

Summary by CodeRabbit

  • Refactor
    • Improved the phone number input handling, including state initialization and input sanitization for better user experience.

@madassdev madassdev requested a review from JhumanJ January 31, 2024 09:39
Copy link
Contributor

coderabbitai bot commented Jan 31, 2024

Walkthrough

The update involves enhancing the PhoneInput.vue component by refining its methods and functionality. A new method named compVal has been introduced to manage value comparisons, and the initState method has been crafted for initialization purposes. The mounted lifecycle hook now leverages initState for more efficient setup. Additionally, the onInput method has been optimized to cleanse the input value by eliminating any whitespace, ensuring cleaner and more accurate data handling.

Changes

File Path Change Summary
client/components/.../PhoneInput.vue Introduced compVal method; Added initState method; Refactored mounted hook; Updated onInput method to remove whitespace.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 428ab4f and beedcbe.
Files selected for processing (1)
  • client/components/forms/PhoneInput.vue (4 hunks)

Comment on lines +96 to +98
compVal(newVal, oldVal){
this.initState()
},
Copy link
Contributor

Choose a reason for hiding this comment

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

The compVal method is designed to handle changes in the component's value but currently only calls this.initState() without actually comparing newVal and oldVal or handling them in any specific way. This might not align with the PR objectives that suggest compVal should effectively deal with new and old values to ensure the country prefill functionality works as intended.

Consider implementing logic within compVal that utilizes newVal and oldVal to adjust the component's state or value accordingly.

}
this.inputVal = phoneObj.nationalNumber
}
this.initState()
Copy link
Contributor

Choose a reason for hiding this comment

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

The mounted hook calls this.initState() conditionally based on the presence of this.compVal. This approach might not be reliable for initializing the component's state, especially if compVal is not set at the time of mounting. It's crucial to ensure that the component is correctly initialized regardless of the compVal state.

Ensure that the component's initialization logic in mounted does not solely depend on compVal. Consider always calling initState and handling any necessary conditions within initState itself.

@@ -131,6 +124,7 @@ export default {
},
onInput (event) {
this.inputVal = event?.target?.value.replace(/[^0-9]/g, '')

Copy link
Contributor

Choose a reason for hiding this comment

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

The onInput method strips all non-numeric characters from the input value. While this helps in removing whitespace and ensuring data quality, it also removes any plus signs (+) that might be part of an international phone number prefix. This could potentially alter the intended input value.

Consider allowing the plus sign (+) in the input value to support international phone numbers fully. Adjust the regex to exclude the plus sign from being removed.

Comment on lines +137 to +151
initState() {
if(this.compVal === null){
return;
}
if (!this.compVal.startsWith('+')) {
this.selectedCountryCode = this.getCountryBy(this.compVal.substring(2, 0))
}

const phoneObj = parsePhoneNumber(this.compVal)
if (phoneObj !== undefined && phoneObj) {
if (!this.selectedCountryCode && phoneObj.country !== undefined && phoneObj.country) {
this.selectedCountryCode = this.getCountryBy(phoneObj.country)
}
this.inputVal = phoneObj.nationalNumber
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The initState method attempts to parse and set the phone number and country code from compVal. However, there are a few concerns:

  • Line 142 uses this.compVal.substring(2, 0), which will always return an empty string due to the way substring parameters are ordered. It seems like the intention was to extract the country code, but this will not work as expected.

  • The method does not handle cases where parsePhoneNumber returns undefined or an invalid object, which could lead to runtime errors if phoneObj.nationalNumber or phoneObj.country are accessed without checking.

  • Correct the substring parameters to properly extract the country code.

  • Add error handling for cases where parsePhoneNumber does not return a valid phone object.

@JhumanJ JhumanJ merged commit de3e2d6 into main Jan 31, 2024
4 checks passed
@JhumanJ JhumanJ deleted the 0e356-bug-phone-country-pre-fill branch January 31, 2024 11:49
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