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: Error message on Phone Input #10583

Closed

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 13, 2025

Proposed Changes

@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

  • Bug Fixes
    • Improved phone number validations across user, facility, patient, and resource forms.
    • Updated error messages now clearly indicate when a phone number is required or invalid.
    • Enhanced form feedback ensures mandatory fields are properly validated, providing a smoother user experience.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 13, 2025 03:35
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

The changes update the phone number validation logic across the codebase. Error messages in Cypress page objects have been modified from "Invalid input" to "Required." The forms in various components now use a Zod-based schema with an isValidPhoneNumber refinement and a new localized error message. Additionally, the legacy phone number validator has been removed from the utilities. There is also an adjustment for handling an unset gender value in the user form.

Changes

File(s) Change Summary
cypress/pageObject/Users/UserCreation.ts, cypress/pageObject/facility/FacilityCreation.ts Updated verifyValidationErrors method to change the phone number error message from "Invalid input" to "Required".
public/locale/en.json Added new localization entry: "invalid_phone_number": "Invalid phone number".
src/components/Facility/FacilityForm.tsx, src/components/Patient/PatientRegistration.tsx, src/components/Resource/ResourceCreate.tsx, src/components/Users/UserForm.tsx Replaced custom validators with a new Zod schema for phone number validation using isValidPhoneNumber with refined error messages; updated import statements accordingly; adjusted user data loading (gender) in UserForm.tsx.
src/Utils/validators.ts Removed the phoneNumber validation schema from the exported validators object.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Form
    participant Validator
    participant Localization

    User->>Form: Input phone number
    Form->>Validator: Validate using Zod & isValidPhoneNumber
    Validator-->>Form: Return validation result
    alt Validation fails
        Form->>Localization: Fetch "invalid_phone_number" message
        Localization-->>Form: Return error message text
        Form-->>User: Display error message
    else Validation passes
        Form-->>User: Proceed with submission
    end
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a rabbit coding under the moon so bright,
Hopping through validations with pure delight.
Phone numbers now refined with Zod’s gentle grace,
Each error message finds its perfect place.
Leaping into code with a joyful, bouncy beat,
Celebrating changes that make our logic neat! 🐇


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9bf2c7 and 6ad1e7b.

📒 Files selected for processing (8)
  • cypress/pageObject/Users/UserCreation.ts (1 hunks)
  • cypress/pageObject/facility/FacilityCreation.ts (1 hunks)
  • public/locale/en.json (1 hunks)
  • src/Utils/validators.ts (0 hunks)
  • src/components/Facility/FacilityForm.tsx (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (2 hunks)
  • src/components/Users/UserForm.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • src/Utils/validators.ts
🧰 Additional context used
🧠 Learnings (2)
cypress/pageObject/Users/UserCreation.ts (1)
Learnt from: AnveshNalimela
PR: ohcnetwork/care_fe#8930
File: cypress/pageobject/Users/UserCreation.ts:31-42
Timestamp: 2024-11-12T10:23:10.322Z
Learning: In `UserCreationPage` of `UserCreation.ts`, methods like `typePhoneNumber` and `typeUserPhoneNumber` target different input fields and are both necessary.
src/components/Users/UserForm.tsx (1)
Learnt from: rajku-dev
PR: ohcnetwork/care_fe#9887
File: src/components/Users/CreateUserForm.tsx:93-93
Timestamp: 2025-01-14T09:22:13.878Z
Learning: In CreateUserForm.tsx, the gender validation schema uses string literals that match GENDER_TYPES.map(g => g.id). Using GENDER_TYPES directly with z.enum() fails because it's marked with 'as const' which makes it a readonly tuple type incompatible with Zod's enum.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (12)
cypress/pageObject/facility/FacilityCreation.ts (1)

95-95: LGTM! Error message update aligns with validation changes.

The change from "Invalid input" to "Required" aligns with the new Zod-based phone number validation schema being implemented across the application.

cypress/pageObject/Users/UserCreation.ts (1)

73-73: LGTM! Error message update is consistent.

The change from "Invalid input" to "Required" maintains consistency with the facility creation form and aligns with the new validation approach.

src/components/Resource/ResourceCreate.tsx (2)

7-7: LGTM! Import added for phone validation.

Added import for isValidPhoneNumber from react-phone-number-input to support the new validation approach.


79-82: LGTM! Phone validation schema updated correctly.

The new Zod-based validation schema:

  • Requires a non-empty string
  • Validates phone number format
  • Uses localized error messages
src/components/Facility/FacilityForm.tsx (2)

6-6: LGTM! Import added for phone validation.

Added import for isValidPhoneNumber from react-phone-number-input to support the new validation approach.


70-73: LGTM! Phone validation schema updated correctly.

The new Zod-based validation schema:

  • Requires a non-empty string
  • Validates phone number format
  • Uses localized error messages
src/components/Users/UserForm.tsx (3)

6-6: LGTM!

The import of isValidPhoneNumber is correctly placed and necessary for the phone number validation.


93-96: LGTM!

The phone number validation schema is well-structured with:

  • Required field validation
  • Phone number format validation
  • Properly localized error messages

151-151: LGTM!

The gender field handling correctly defaults to undefined when no gender value is provided, which aligns with the gender validation schema requirements.

src/components/Patient/PatientRegistration.tsx (2)

89-92: LGTM!

The phone number validation schema is consistent with UserForm.tsx and includes:

  • Required field validation
  • Phone number format validation
  • Properly localized error messages

94-97: LGTM!

The emergency phone number validation schema:

  • Matches the primary phone number validation
  • Works correctly with the same_phone_number checkbox functionality
  • Uses proper localization for error messages
public/locale/en.json (1)

1156-1156:

✅ Verification successful

LGTM! The new error message is well-formatted and consistent.

The added localization entry for invalid phone number validation follows the established conventions and provides a clear error message.

Let's verify that the new message is being used correctly in the components:


🏁 Script executed:

#!/bin/bash
# Description: Check the usage of the new error message in the codebase.

# Search for usage of the new error message key
rg -A 2 "invalid_phone_number" 

Length of output: 1795


LGTM: The new error message is clear, well-formatted, and applied consistently across the codebase.

  • The key "invalid_phone_number" in public/locale/en.json follows the established naming conventions and provides a concise validation message.
  • Verification confirms its usage in multiple components including:
    • src/components/Users/UserForm.tsx
    • src/components/Resource/ResourceCreate.tsx
    • src/components/Facility/FacilityForm.tsx
    • src/components/Patient/PatientRegistration.tsx
  • The message aligns with similar error messages, ensuring a uniform user experience.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 6ad1e7b
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ad689a0425f3000856cfe3
😎 Deploy Preview https://deploy-preview-10583.preview.ohc.network
📱 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
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 not do it this way. this is so much code duplication and we already have error message with different translation key for phone number validation

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