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

Deleted errors.tsx and input-with-error.tsx, and updated PatientRegis… #9737

Conversation

sanjayh-2022
Copy link

@sanjayh-2022 sanjayh-2022 commented Jan 4, 2025

…tration.tsx, FacilityOrganizationSelector.tsx, and OrganizationSelector.tsx to replace InputWithError and InputError with Shadcn components accordingly.

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

  • New Features

    • Enhanced patient registration form with improved error handling and accessibility
    • Added clearer labels and error messages for input fields
    • Improved form validation and user feedback mechanisms
  • Refactor

    • Removed InputWithError component
    • Restructured input field handling in multiple components
    • Updated organization selector components with more streamlined label and error display
  • Bug Fixes

    • Implemented stricter input validation for phone numbers and date of birth
    • Improved error message display for form fields

…tration.tsx, FacilityOrganizationSelector.tsx, and OrganizationSelector.tsx to replace InputWithError and InputError with Shadcn components accordingly.
@sanjayh-2022 sanjayh-2022 requested a review from a team as a code owner January 4, 2025 10:23
Copy link
Contributor

coderabbitai bot commented Jan 4, 2025

Walkthrough

This pull request focuses on removing the custom InputWithError and InputErrors components across multiple files in favor of directly using Shadcn UI components. The changes primarily involve restructuring input fields in components like PatientRegistration, FacilityOrganizationSelector, and OrganizationSelector. The modifications aim to simplify error handling, improve accessibility, and use more standardized UI components by directly implementing labels, inputs, and error displays.

Changes

File Change Summary
src/components/Patient/PatientRegistration.tsx Restructured input fields, replaced InputWithError with direct Label and Input components, enhanced error handling and field validation
src/components/ui/errors.tsx Removed InputErrors function component
src/components/ui/input-with-error.tsx Deleted entire component file
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx Replaced InputWithError with Label, added translation function
src/pages/Organization/components/OrganizationSelector.tsx Replaced InputWithError with Label, simplified error handling

Assessment against linked issues

Objective Addressed Explanation
Delete input-with-error.tsx
Replace usages with Shadcn components

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 In the realm of code, where components dance,
InputWithError takes its final stance
Shadcn's UI now leads the way
Cleaner, simpler - hip hooray!
A rabbit's code refactor, neat and bright 🌟


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 Jan 4, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit cbeeb64
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67790c20a88c5c0008d04871
😎 Deploy Preview https://deploy-preview-9737--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 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 (12)
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (2)

108-114: Localized translation mapping.
The t function for mapping translations is straightforward. If the application grows, consider leveraging a centralized i18n solution to keep translations consistent and track them more easily.


197-199: Follow through on error handling.
The comment suggests future error handling. Confirm if or when error messages will be displayed here to make sure end users are informed of invalid states.

Do you want help incorporating a standardized error display mechanism for these fields?

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

317-338: Optional chaining to handle potential undefined errors.
According to the static analysis, you can replace repeated usage like errors.name && errors.name.map(...) with optional chaining: errors.name?.map(...). This avoids lengthier condition checks.

- {errors.name &&
-   errors.name.map((error, index) => (
-     <span key={index} className="text-sm text-red-500 mt-1">
-       {error}
-     </span>
-   ))
- }
+ {errors.name?.map((error, index) => (
+   <span key={index} className="text-sm text-red-500 mt-1">
+     {error}
+   </span>
+ ))}
🧰 Tools
🪛 Biome (1.9.4)

[error] 332-337: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


364-370: Apply optional chaining in phone number errors.
Similar to the recommendation above, using optional chaining can streamline error handling code for errors.phone_number.

🧰 Tools
🪛 Biome (1.9.4)

[error] 364-369: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 373-387: Maintain consistent naming and spacing for the checkbox state.
The logic is correct, but ensure variable naming or comments clarify the rationale for tying the emergency phone number to the main phone number.

🧰 Tools
🪛 Biome (1.9.4)

[error] 364-369: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 395-428: Optional chaining for errors.emergency_phone_number.
As recommended by static analysis, apply optional chaining to simplify this pattern.


Line range hint 482-509: Use optional chaining for blood group errors.
Consolidate the checks by applying optional chaining.


Line range hint 724-758: Optional chaining for address errors.
As above, replacing explicit checks like errors["address"] && errors["address"].map(...) with errors.address?.map(...) streamlines error rendering.


Line range hint 761-794: Consider central logic for same address default.
Since the address duplication logic is repeated, extracting it into a reusable helper or custom hook might simplify the code.

🧰 Tools
🪛 Biome (1.9.4)

[error] 786-791: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


797-826: Optional chaining for permanent address errors.
All these conditional checks can use optional chaining.


834-858: Use optional chaining for pincode errors.
As before, use errors.pincode?.map(...).

src/pages/Organization/components/OrganizationSelector.tsx (1)

Line range hint 116-141: Replacing InputWithError with Label and direct error handling.
This refactor is consistent with the rest of the PR’s changes (removal of InputWithError). If more complex validations are required later, consider a dedicated form library or reuse your existing pattern in PatientRegistration.tsx.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68c4c3d and cbeeb64.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • src/components/Patient/PatientRegistration.tsx (15 hunks)
  • src/components/ui/errors.tsx (0 hunks)
  • src/components/ui/input-with-error.tsx (0 hunks)
  • src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (4 hunks)
  • src/pages/Organization/components/OrganizationSelector.tsx (5 hunks)
💤 Files with no reviewable changes (2)
  • src/components/ui/errors.tsx
  • src/components/ui/input-with-error.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Patient/PatientRegistration.tsx

[error] 332-337: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 364-369: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 786-791: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (8)
src/pages/FacilityOrganization/components/FacilityOrganizationSelector.tsx (3)

9-9: Good addition of Shadcn's Label.
This promotes consistency across all form fields by consistently using the Label component from the shared UI library.


34-34: Renaming required to _required.
Renaming the prop helps avoid potential naming conflicts, but ensure that _required is not needed for conditional checks or validations in this component.


116-119: Proper labeling for organization selection.
Using the <Label> component improves accessibility, as screen readers can associate the label with the corresponding form field.

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

529-569: Improve date-of-birth calculations.
Consider verifying numeric boundaries for days (1–31) and months (1–12). For example, a user might enter “00” or “32” for days. Although you have boundaries in place, ensure there's a fallback or validation.


Line range hint 874-902: Autocomplete usage for nationality.
Implementation looks good. Always ensure the country list is complete or updated as needed.

src/pages/Organization/components/OrganizationSelector.tsx (3)

8-8: Label import consistency.
Good move to align this import with the approach used elsewhere.


31-31: Renaming prop to _required.
Make sure to validate whether _required might be needed for future usage or form library integration.


Line range hint 149-175: Error display placeholder.
Right now, the error UI is hardcoded to false. If you plan to display errors here eventually, ensure the correct condition is set.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 5, 2025
Copy link

github-actions bot commented Jan 5, 2025

👋 Hi, @sanjayh-2022,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@rithviknishad
Copy link
Member

most of the diff doesn't make sense. do read the docs and readme and other examples in existing codebase and follow the merge checklist

@@ -31,7 +31,7 @@ interface AutoCompleteOption {
export default function FacilityOrganizationSelector(
props: FacilityOrganizationSelectorProps,
) {
const { onChange, required, facilityId } = props;
const { onChange, required: _required, facilityId } = props;
Copy link
Member

Choose a reason for hiding this comment

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

why alias it?

Comment on lines +108 to +114
function t(key: string): string {
const translations: { [key: string]: string } = {
Organization: "Organization",
};
return translations[key] || key;
}

Copy link
Member

Choose a reason for hiding this comment

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

what's this?

Comment on lines +117 to +119
<Label htmlFor="organization" className="">
{t("Organization")}
</Label>
Copy link
Member

Choose a reason for hiding this comment

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

i don't see where required is handled here

@@ -185,6 +194,8 @@ export default function FacilityOrganizationSelector(
</div>
)}
</div>
</InputWithError>

{/* Handle errors if needed */}
Copy link
Member

Choose a reason for hiding this comment

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

and where is it being handled?

@@ -28,7 +28,7 @@ interface AutoCompleteOption {
}

export default function OrganizationSelector(props: OrganizationSelectorProps) {
const { onChange, required } = props;
const { onChange, required: _required } = props;
Copy link
Member

Choose a reason for hiding this comment

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

again, why alias it?


{false && (
<span className="text-sm text-red-500 mt-1">
{"This field is required"}
Copy link
Member

Choose a reason for hiding this comment

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

i18n, follow translations guidelines in readme/docs

@@ -135,18 +132,28 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
<CareIcon icon="l-trash" className="h-4 w-4" />
</Button>
</div>
</InputWithError>

{false && (
Copy link
Member

Choose a reason for hiding this comment

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

false &&? doesn't make sense

>
<div className="mb-4">
<Label
htmlFor={`organization-level-${selectedLevels.length}`}
Copy link
Member

Choose a reason for hiding this comment

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

where is the equivalent id being passed for the input?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove InputWithError and InputErrors component in favour of shadcn's components being used directly
2 participants