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 Translations Not Loading for Global Zod Validators Error Messages and Improve Patient Registration Error Messages #10581

Merged

Conversation

rajku-dev
Copy link
Contributor

@rajku-dev rajku-dev commented Feb 13, 2025

Proposed Changes

Before

image
image

After

image
image
image

@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

Summary by CodeRabbit

  • New Features

    • Enhanced error feedback for age and location inputs, leading to more precise validation messages.
  • Refactor

    • Streamlined the form validation process across the application by dynamically generating validation rules, ensuring a more consistent and flexible user experience.
    • Removed the validation message for phone number length requirement.

@rajku-dev rajku-dev requested a review from a team as a code owner February 13, 2025 02:12
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

This pull request modifies the localization file by removing a specific validation message related to phone number requirements. Additionally, it transitions the validation logic across several components from static object exports to dynamic function calls. The phone number validation now includes a minimum length check and updates the error messages accordingly. Various form components have been updated to utilize the new validation schema function, enhancing the flexibility of the validation logic.

Changes

File(s) Change Summary
public/locale/en.json Deleted the entry for "phone_number_must_be_10_digits" with the corresponding validation message.
src/Utils/validators.ts Changed export from a static object to a function returning an object; updated phoneNumber validation to include a minimum length check and updated the required error message.
src/components/Facility/FacilityForm.tsx, src/components/Patient/PatientRegistration.tsx, src/components/Resource/ResourceCreate.tsx, src/components/Users/UserForm.tsx Updated validation schema import from a static object reference to a dynamic function call (validators()); modified validation logic for geo_organization and age handling in PatientRegistration.tsx.

Possibly related PRs

Suggested labels

needs review, tested, changes required

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a little rabbit, hopping through the code,
Removing old messages, lightening the load.
With dynamic checks, we leap and we bound,
Validations now flexible, joyfully found.
Let's celebrate changes, with a hop and a cheer!
🐇✨


📜 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 95cd4ef and 2219970.

📒 Files selected for processing (6)
  • public/locale/en.json (0 hunks)
  • src/Utils/validators.ts (1 hunks)
  • src/components/Facility/FacilityForm.tsx (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (4 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/components/Users/UserForm.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • public/locale/en.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/Users/UserForm.tsx
  • src/components/Resource/ResourceCreate.tsx
  • src/components/Patient/PatientRegistration.tsx
  • src/components/Facility/FacilityForm.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: cypress-run (1)
🔇 Additional comments (2)
src/Utils/validators.ts (2)

5-5: LGTM! Good fix for the translation loading timing.

Converting the static object export to a function ensures translations are fetched dynamically when needed inside components, which properly handles i18next's asynchronous nature.

Also applies to: 33-33


14-19:

✅ Verification successful

LGTM! Good improvements to phone number validation.

The changes improve validation by:

  1. Adding proper empty field validation with a clear message
  2. Maintaining format validation while removing the misleading 10-digit requirement

Let's verify that all components using this validator have been updated:


🏁 Script executed:

#!/bin/bash
# Description: Find all components using the phone number validator

# Search for phoneNumber validator usage
rg -A 5 'validators.*phoneNumber'

Length of output: 2303


Approval: Phone number validation improvements are solid.

The updates in src/Utils/validators.ts (lines 14-19) now properly enforce non-empty inputs with a clear "field_required" error message and maintain robust format validation via isValidPhoneNumber. The removal of the outdated 10-digit requirement has been correctly implemented.

  • Verified usage in:
    • src/components/Facility/FacilityForm.tsx
    • src/components/Users/UserForm.tsx
    • src/components/Resource/ResourceCreate.tsx
    • src/components/Patient/PatientRegistration.tsx

No additional changes are needed, and the dependent components are using the updated validator correctly.

✨ 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 2219970
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ad7878603b890008367590
😎 Deploy Preview https://deploy-preview-10581.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
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: 0

🧹 Nitpick comments (1)
src/components/Patient/PatientRegistration.tsx (1)

557-557: Verify the type casting approach.

The type casting (null as unknown as number) is a workaround to handle empty values. Consider using a more type-safe approach:

-  : (null as unknown as number), // intentionally setting to undefined, when the value is empty to avoid 0 in the input field
+  : undefined, // intentionally setting to undefined, when the value is empty to avoid 0 in the input field
📜 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 e356a78.

📒 Files selected for processing (6)
  • public/locale/en.json (1 hunks)
  • src/Utils/validators.ts (1 hunks)
  • src/components/Facility/FacilityForm.tsx (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (3 hunks)
  • src/components/Resource/ResourceCreate.tsx (2 hunks)
  • src/components/Users/UserForm.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (8)
src/Utils/validators.ts (2)

5-5: Improved i18n initialization by making validators dynamic.

The change from a static object to a function ensures that translations are properly initialized when the validation schema is created.


14-19: Enhanced phone number validation with required field check.

The validation now properly enforces both format and presence requirements:

  1. .min(1) ensures the field is not empty
  2. .refine() validates the phone number format
src/components/Resource/ResourceCreate.tsx (1)

49-64: LGTM! Validation schema properly initialized.

The component correctly adapts to the new validation schema initialization pattern.

src/components/Facility/FacilityForm.tsx (1)

41-63: LGTM! Validation schema properly initialized.

The component correctly adapts to the new validation schema initialization pattern and maintains both phone number and coordinates validation.

src/components/Users/UserForm.tsx (1)

41-63: LGTM! Validation schema properly initialized.

The component correctly adapts to the new validation schema initialization pattern.

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

59-59: LGTM! Import change aligns with translation fix.

The change from static validators import to dynamic getValidationSchema function should help resolve the translation loading issues.


569-577: LGTM! Improved age validation feedback.

Good addition of validation feedback for invalid age and clear display of calculated year of birth.

public/locale/en.json (1)

1618-1618: LGTM! Clear and consistent error message.

The added translation for phone number validation is clear and follows the existing message style in the file.

@rajku-dev rajku-dev changed the title Fix Translations Not Loading for Global Zod Validators Error Messages and Patient Registration Age and Y.O.B fields Fix Translations Not Loading for Global Zod Validators Error Messages and Improve Patient Registration Error Messages Feb 13, 2025
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 (1)
src/components/Patient/PatientRegistration.tsx (1)

560-560: Consider using undefined instead of null for age reset.

Using null as unknown as number is a type assertion that could be avoided. Since the age field is optional in the schema, undefined would be more appropriate.

-                                  : (null as unknown as number),
+                                  : undefined,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e356a78 and 705f2a8.

📒 Files selected for processing (1)
  • src/components/Patient/PatientRegistration.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (2)
src/components/Patient/PatientRegistration.tsx (2)

59-59: LGTM! Dynamic validation schema initialization.

The change from static import to dynamic initialization using getValidationSchema() aligns with the PR objective of fixing translation loading issues.

Also applies to: 85-86


569-578: LGTM! Enhanced age validation feedback.

The improved display logic for year of birth calculation with proper error handling for invalid age values provides better user 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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/components/Patient/PatientRegistration.tsx (2)

560-560: Consider improving type safety for age handling.

The current type casting (null as unknown as number) is a workaround that could be improved for better type safety.

Consider updating the form schema to properly handle nullable numbers:

-age: z
+age: z.union([
+  z
     .number()
     .int()
     .positive()
     .min(1, t("age_must_be_positive"))
     .max(120, t("age_must_be_below_120"))
-    .optional(),
+  z.null()
+]).optional(),

569-578: Consider enhancing accessibility for error states.

While the color-coded messages provide good visual feedback, they could be more accessible.

Consider adding ARIA attributes for better screen reader support:

-              <span className="text-red-600">Invalid age</span>
+              <span className="text-red-600" role="alert" aria-label={t("invalid_age_error")}>Invalid age</span>
-              <span className="text-violet-600">
+              <span className="text-violet-600" role="status" aria-label={t("year_of_birth_calculation")}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 705f2a8 and 95cd4ef.

📒 Files selected for processing (2)
  • public/locale/en.json (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • public/locale/en.json
⏰ 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: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (2)
src/components/Patient/PatientRegistration.tsx (2)

59-59: LGTM! Good improvement in validation initialization.

The change from static import to dynamic validation schema generation improves the handling of internationalized validation messages.

Also applies to: 85-85


125-128: LGTM! Well-structured validation for geo_organization.

The validation properly checks for UUID format and uses internationalized error messages.

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.

overlooked this thing earlier, other than that LGTM

@rithviknishad rithviknishad merged commit 6c5cefc into ohcnetwork:develop Feb 13, 2025
13 of 15 checks passed
Copy link

@rajku-dev 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
Labels
None yet
Projects
None yet
2 participants