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

Add max phone number length to user creation form #9952

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Jan 14, 2025

Proposed Changes

  • Fixes #issue_number
  • Change 1
  • Change 2
  • More?

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features
    • Added input length validation for phone number fields, limiting input to 13 characters.
    • Enhanced phone number input fields to optimize for telephone number entry on mobile devices by setting the input type to "tel".

@nihal467 nihal467 requested a review from a team as a code owner January 14, 2025 09:36
Copy link

netlify bot commented Jan 14, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 0c9114a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/678632f446a4f90008cbcca3
😎 Deploy Preview https://deploy-preview-9952--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

The pull request implements input validation enhancements for phone number fields across three components: CreateUserForm.tsx, CreateFacilityForm.tsx, and PatientRegistration.tsx. The changes include adding a maxLength attribute set to 13 characters for the phone_number and alt_phone_number fields in CreateUserForm.tsx and PatientRegistration.tsx. Additionally, the type attribute for the phone_number field in CreateFacilityForm.tsx has been changed to type="tel", optimizing it for numeric input on mobile devices. These modifications improve user input handling without altering existing functionalities.

Changes

File Change Summary
src/components/Users/CreateUserForm.tsx Added maxLength={13} attribute to phone_number and alt_phone_number input fields.
src/components/Facility/CreateFacilityForm.tsx Changed type attribute of phone_number input field to type="tel".
src/components/Patient/PatientRegistration.tsx Added type="tel" and maxLength={13} attributes to phone_number and emergency_phone_number input fields.

Possibly related PRs

Suggested labels

tested, needs review

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 A Rabbit's Phone Number Tale 🐰
Thirteen digits, no more, no less,
Input fields now pass the test!
Restricting numbers with gentle care,
A validation dance beyond compare!
Hop along, form validation's delight! 📱


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nihal467 nihal467 mentioned this pull request Jan 14, 2025
12 tasks
Copy link

cloudflare-workers-and-pages bot commented Jan 14, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0c9114a
Status: ✅  Deploy successful!
Preview URL: https://6f5331ce.care-fe.pages.dev
Branch Preview URL: https://maxlength-userform.care-fe.pages.dev

View logs

@nihal467
Copy link
Member Author

LGTM

Copy link

cypress bot commented Jan 14, 2025

CARE    Run #4301

Run Properties:  status check passed Passed #4301  •  git commit 0c9114a71b: Add max phone number length to user creation form
Project CARE
Branch Review maxlength-userform
Run status status check passed Passed #4301
Run duration 01m 47s
Commit git commit 0c9114a71b: Add max phone number length to user creation form
Committer Mohammed Nihal
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

let's add it everywhere else as well?

image

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/Users/CreateUserForm.tsx (2)

315-320: Consider input masking for better user experience.

While the maxLength restriction works, consider using an input mask library to:

  • Format the input as user types
  • Prevent invalid characters
  • Guide users with visual feedback

Consider using a library like react-input-mask or react-number-format:

<InputMask
  mask="+91 9999999999"
  type="tel"
  placeholder="+91XXXXXXXXXX"
  {...field}
/>

337-337: Redundant maxLength validation.

The maxLength attribute is redundant since the form's validation schema already enforces the exact format with regex /^\+91[0-9]{10}$/. Consider removing maxLength or updating the validation strategy to be consistent.

Either:

  1. Remove maxLength and rely on regex validation
  2. Or replace regex with simpler validation and keep maxLength:
phone_number: z
  .string()
  .min(13, t("invalid_phone_length"))
  .max(13, t("invalid_phone_length"))
  .startsWith("+91", t("must_start_with_country_code"))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f10987 and d3a69bb.

📒 Files selected for processing (1)
  • src/components/Users/CreateUserForm.tsx (2 hunks)

Comment on lines +315 to +320
<Input
type="tel"
placeholder="+91XXXXXXXXXX"
maxLength={13}
{...field}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Phone number validation requirements are overly restrictive

The current implementation enforces a strict Indian phone number format, but the codebase has utilities (parsePhoneNumber, formatPhoneNumber) that support more flexible phone number handling. Consider:

  • Using the existing phone utilities to allow formatted input (spaces, hyphens)
  • Supporting international numbers since the codebase already has this capability
  • Maintaining +91 validation only if it's a strict business requirement

Example locations that handle phone numbers more flexibly:

  • src/Utils/utils.ts: parsePhoneNumber() and formatPhoneNumber()
  • src/pages/PublicAppointments/auth/PatientLogin.tsx: Phone validation with formatting
🔗 Analysis chain

Verify phone number validation requirements.

The current implementation enforces:

  • Exactly 13 characters
  • Must start with +91
  • Exactly 10 digits after +91

Please confirm if these strict requirements align with the business needs:

  1. Should international numbers be supported?
  2. Should spaces or hyphens be allowed for formatting?
  3. Should shorter emergency numbers be allowed?

Also applies to: 337-337

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other phone number validation patterns in the codebase
rg -l "phone.*validation|phone.*regex" --type ts --type tsx

Length of output: 89


Script:

#!/bin/bash
# Search for phone-related validation patterns in TypeScript files
rg -t typescript -t javascriptreact -t typescriptreact "phone.*validation|phone.*regex|phoneNumber|phone.*schema" -A 5

# Search for form validation schemas
rg -t typescript -t typescriptreact "schema.*phone|validate.*phone" -A 5

# Search for test files related to phone validation
fd ".*\.(test|spec)\.(ts|tsx)$" --exec rg -l "phone|mobile"

Length of output: 327


Script:

#!/bin/bash
# Search for validation schema in CreateUserForm.tsx
rg "phone" src/components/Users/CreateUserForm.tsx -A 5 -B 5

# Search for validation-related imports and schemas
rg "import.*yup|import.*zod|schema.*=|validation.*=|phone.*=" src/components/Users/CreateUserForm.tsx

# Search for phone-related patterns in the entire codebase
rg "phone.*validation|phoneNumber|phone.*schema" --type-add 'ts:*.{ts,tsx}' -t ts

Length of output: 12071

Copy link

Reminder: To add the "needs testing" label, comment "ready for testing" on this PR.

@rithviknishad
Copy link
Member

@nihal467 there are places where type="tel" is also missing, let's add those as well

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/Facility/CreateFacilityForm.tsx (1)

266-266: LGTM! Consider enhancing validation feedback.

The changes improve user experience by:

  • Restricting input length to match the required format (+91 + 10 digits)
  • Optimizing mobile input with type="tel"

Consider adding pattern validation to provide immediate feedback before form submission:

   <Input
     type="tel"
     data-cy="facility-phone"
     placeholder="+91XXXXXXXXXX"
     maxLength={13}
+    pattern="^\+91[0-9]{10}$"
     {...field}
   />
src/components/Patient/PatientRegistration.tsx (1)

395-395: LGTM! Consider enhancing validation feedback.

The changes improve user experience by:

  • Restricting input length appropriately
  • Optimizing mobile input with type="tel"

Consider adding pattern validation to provide immediate feedback before form submission:

   <Input
     type="tel"
     {...field}
     maxLength={13}
+    pattern="^\+\d{12}$"
     data-cy="patient-emergency-phone-input"
   />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3a69bb and 0c9114a.

📒 Files selected for processing (2)
  • src/components/Facility/CreateFacilityForm.tsx (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages: care-fe

@@ -333,6 +333,7 @@ export default function PatientRegistration(
<FormLabel required>{t("phone_number")}</FormLabel>
<FormControl>
<Input
type="tel"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Phone number validation should be aligned with India-specific format

The current validation pattern /^\+\d{12}$/ allows any country code, but the application is designed specifically for Indian phone numbers:

  • All other components enforce the pattern /^\+91[0-9]{10}$/
  • UI messages explicitly state "Phone number must start with +91 followed by 10 digits"
  • Common validation utilities are India-specific

Consider updating the validation to maintain consistency:

.regex(/^\+91[0-9]{10}$/, t("phone_number_validation"))
🔗 Analysis chain

LGTM! Consider standardizing phone validation across components.

The changes improve UX, but there's an inconsistency in phone number validation:

  • This component allows any country code: /^\+\d{12}$/
  • CreateFacilityForm requires +91: /^\+91[0-9]{10}$/

Let's check for other phone number validation patterns:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for phone number validation patterns
rg -A 2 'phone.*regex'

Length of output: 24


Script:

#!/bin/bash
# Search for phone validation patterns with broader terms
echo "=== Phone validation patterns ==="
rg -i "phone.*valid|valid.*phone" -A 2

echo -e "\n=== Zod phone schemas ==="
rg "phone.*z\." -A 2

echo -e "\n=== General phone patterns ==="
rg -i "phone.*pattern|phone.*match" -A 2

Length of output: 8460


Script:

#!/bin/bash
# Check phonePreg implementation
echo "=== phonePreg implementation ==="
rg -A 2 "phonePreg.*=" 

echo -e "\n=== Phone regex constants ==="
rg -A 2 "PHONE.*REGEX.*="

Length of output: 1148

@rithviknishad rithviknishad merged commit 1021155 into develop Jan 14, 2025
25 checks passed
@rithviknishad rithviknishad deleted the maxlength-userform branch January 14, 2025 10:36
Copy link

@nihal467 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants