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: Add fallback url for goback() | OTP field auto focus | Add Search Feature for users #10146

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

Rishith25
Copy link
Contributor

@Rishith25 Rishith25 commented Jan 24, 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

  • New Features
    • Enhanced Input Experience: OTP fields in login forms now auto-focus to streamline verification.
    • Refined Navigation: Cancel buttons across appointment, registration, resource, and public pages now redirect users to specific, context-relevant pages.
    • Improved User Management: The organization users view features enhanced search and pagination for a more intuitive management experience.

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request improves navigation and user interaction across multiple components. Several cancel and back buttons now pass explicit fallback URLs to handle cases with no browser history. The OTP input fields in login components have been enhanced with an auto-focus attribute for immediate user input. Furthermore, the Facility Organization Users component now incorporates a more robust search feature using a custom hook with debounced API calls and improved loading states. No changes were made to any exported or public entities.

Changes

File(s) Change Summary
src/components/Auth/Login.tsx, src/pages/PublicAppointments/auth/PatientLogin.tsx Added autoFocus attribute to OTP input fields.
src/components/Patient/EncounterQuestionnaire.tsx, src/components/Patient/PatientRegistration.tsx, src/components/Resource/ResourceCreate.tsx, src/components/Resource/ResourceDetailsUpdate.tsx, src/pages/Appointments/BookAppointment.tsx, src/pages/Patients/VerifyPatient.tsx, src/pages/PublicAppointments/Schedule.tsx Modified cancel/back button handlers to pass explicit fallback URLs with route parameters.
src/pages/Facility/.../FacilityOrganizationUsers.tsx Replaced useQueryParams with useFilters, integrated a search input with debounced API calls, and enhanced loading state and pagination for user filtering.

Assessment against linked issues

Objective Addressed Explanation
Add fallback url for goBack() ([#10131])
OTP field auto focus ([#10131])
Add Search Feature for users ([#10131])

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a rabbit hopping through lines of code,
Where auto-focus makes the OTP mode explode.
Fallback URLs guide each cancel and back,
And search blooms fresh along the track.
With every hop, our code’s easier to reload! 🥕🐇


📜 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 05da6fc and 3dac6e7.

📒 Files selected for processing (4)
  • src/components/Auth/Login.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/components/Resource/ResourceDetailsUpdate.tsx (1 hunks)
  • src/pages/PublicAppointments/auth/PatientLogin.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/Resource/ResourceCreate.tsx
  • src/pages/PublicAppointments/auth/PatientLogin.tsx
  • src/components/Resource/ResourceDetailsUpdate.tsx
  • src/components/Auth/Login.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: cypress-run (1)

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 24, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 3dac6e7
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67a5920c4c17f700089b7594
😎 Deploy Preview https://deploy-preview-10146--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.

@Rishith25 Rishith25 marked this pull request as ready for review January 25, 2025 02:48
@Rishith25 Rishith25 requested a review from a team as a code owner January 25, 2025 02:48
@Rishith25
Copy link
Contributor Author

@rithviknishad @Jacobjeevan @nihal467 i have implemented username searching for users in facility organization. But backend response is not filtered by username. In backend username filtering is not happening.

Image

In response all users are coming

Image

I made the changes in backend , it worked fined. Shall i raise a PR in backend??

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 25, 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 (3)
src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (3)

40-53: Consider adding error handling for the query.

The query configuration is well-structured with proper debouncing and pagination. However, error handling should be implemented to improve user experience when API calls fail.

Add error handling:

 const { data: users, isLoading: isLoadingUsers } = useQuery({
+  onError: (error) => {
+    // Handle error appropriately (e.g., show toast notification)
+    console.error('Failed to fetch users:', error);
+  },
   queryKey: [

69-80: Enhance search input accessibility.

The search implementation is well-structured with proper test attributes. Consider adding ARIA labels and announcing search results for better accessibility.

Add accessibility enhancements:

 <Input
   type="text"
   placeholder="Search users..."
+  aria-label={t("search_users")}
+  role="searchbox"
   value={qParams.search || ""}
   onChange={(e) =>
     updateQuery({
       search: e.target.value as string,
     })
   }
   className="w-full"
   data-cy="search-user"
 />

110-117: Consider virtualizing the user list for better performance.

The empty state and loading handling are well-implemented. For better performance with large lists, consider implementing virtualization.

Consider using a virtualized list library like react-window or react-virtualized when dealing with large datasets:

+import { FixedSizeGrid } from 'react-window';
+
-<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
+<FixedSizeGrid
+  columnCount={3}
+  columnWidth={300}
+  height={800}
+  rowCount={Math.ceil(users?.results?.length / 3)}
+  rowHeight={200}
+  width={1000}
+>
   {users?.results?.map((userRole: OrganizationUserRole) => (
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e43fe7d and e44190c.

📒 Files selected for processing (11)
  • src/components/Auth/Login.tsx (2 hunks)
  • src/components/Form/FormFields/PhoneNumberFormField.tsx (2 hunks)
  • src/components/Patient/EncounterQuestionnaire.tsx (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/components/Resource/ResourceDetailsUpdate.tsx (1 hunks)
  • src/pages/Appointments/BookAppointment.tsx (1 hunks)
  • src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (2 hunks)
  • src/pages/Patients/VerifyPatient.tsx (1 hunks)
  • src/pages/PublicAppointments/Schedule.tsx (1 hunks)
  • src/pages/PublicAppointments/auth/PatientLogin.tsx (3 hunks)
🔇 Additional comments (15)
src/components/Patient/EncounterQuestionnaire.tsx (1)

49-51: LGTM! Improved navigation with specific fallback URL.

The addition of a specific fallback URL for the cancel action ensures consistent navigation behavior.

src/pages/Appointments/BookAppointment.tsx (1)

163-171: LGTM! Clear navigation path for cancel action.

The cancel button now correctly navigates back to the patient's appointments list, maintaining proper context with facility and patient IDs.

src/components/Resource/ResourceDetailsUpdate.tsx (1)

282-286: LGTM! Consistent cancel navigation behavior.

The cancel button properly navigates back to the resource details page, maintaining consistency with other cancel actions.

src/pages/Patients/VerifyPatient.tsx (1)

242-242: LGTM! Clear error state navigation.

The error state button now correctly navigates back to the facility's patients list, maintaining proper context.

src/pages/PublicAppointments/Schedule.tsx (1)

219-219: LGTM! Navigation path is correctly specified.

The back button now navigates to a specific facility page using the facilityId prop, providing a more predictable navigation experience.

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

442-446: LGTM! Navigation path is correctly specified.

The cancel button now navigates to the resource requests page for a specific patient using both facilityId and related_patient parameters, providing a more contextual navigation experience.

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

731-731: LGTM! Navigation path is correctly specified.

The cancel button now navigates to the patients list page using the facilityId prop, providing a more predictable navigation experience.

src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (2)

30-33: Well-structured filter configuration!

Good use of useFilters hook with appropriate caching strategy. The cacheBlacklist for search prevents unwanted persistence of search terms.


190-190: LGTM! Pagination implementation is clean and effective.

The pagination is well-integrated with the API response and filter hooks.

src/pages/PublicAppointments/auth/PatientLogin.tsx (3)

179-179: LGTM! Good UX improvement.

Adding autoFocus to the phone number input field enhances user experience by allowing immediate input without requiring an extra click.


224-229: LGTM! Smooth transition to OTP input.

The autoFocus attribute on the InputOTP component creates a seamless flow from phone number entry to OTP verification.


283-283: LGTM! Improved navigation reliability.

Using a specific fallback URL (/facility/${facilityId}) instead of relying on browser history provides more predictable navigation behavior.

src/components/Form/FormFields/PhoneNumberFormField.tsx (2)

40-40: LGTM! Well-typed prop addition.

The autoFocus property is correctly added to the Props interface with an optional boolean type.


155-155: LGTM! Proper prop implementation.

The autoFocus prop is correctly passed to the underlying input element.

src/components/Auth/Login.tsx (1)

649-649: LGTM! Enhanced initial focus.

Adding autoFocus to the phone input improves the login flow by immediately allowing phone number entry.

src/components/Auth/Login.tsx Show resolved Hide resolved
@Jacobjeevan Jacobjeevan added waiting for backend and removed question Further information is requested needs-triage labels Jan 28, 2025
Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

Waiting for backend, does looks good otherwise.

src/components/Form/FormFields/PhoneNumberFormField.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 28, 2025
Copy link

👋 Hi, @Rishith25,
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.

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Jan 28, 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: 0

🧹 Nitpick comments (2)
src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (2)

67-81: Add accessibility attributes to the search input.

While the search implementation looks good, consider adding these accessibility improvements:

 <Input
   type="text"
   placeholder="Search users..."
   value={qParams.search || ""}
   onChange={(e) =>
     updateQuery({
       search: e.target.value as string,
     })
   }
   className="w-full"
   data-cy="search-user"
+  aria-label={t("search_users")}
+  role="searchbox"
 />

105-187: Enhance semantic HTML structure in user cards.

The user list implementation looks good, but consider these semantic HTML improvements:

-<h1 className="text-base font-bold break-words pr-2">
+<h3 className="text-base font-bold break-words pr-2">
   {userRole.user.first_name}{" "}
   {userRole.user.last_name}
-</h1>
+</h3>

Rationale:

  • Use h3 instead of h1 as these are sub-headings within the page
  • h1 should be used for the main page heading only
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e44190c and d509275.

📒 Files selected for processing (7)
  • src/components/Auth/Login.tsx (1 hunks)
  • src/components/Patient/PatientRegistration.tsx (1 hunks)
  • src/components/Resource/ResourceCreate.tsx (1 hunks)
  • src/pages/Appointments/BookAppointment.tsx (1 hunks)
  • src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (2 hunks)
  • src/pages/PublicAppointments/Schedule.tsx (1 hunks)
  • src/pages/PublicAppointments/auth/PatientLogin.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/components/Patient/PatientRegistration.tsx
  • src/pages/PublicAppointments/auth/PatientLogin.tsx
  • src/components/Auth/Login.tsx
  • src/pages/Appointments/BookAppointment.tsx
  • src/components/Resource/ResourceCreate.tsx
  • src/pages/PublicAppointments/Schedule.tsx
🔇 Additional comments (3)
src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx (3)

8-8: LGTM! Good setup of the useFilters hook.

The hook configuration with cacheBlacklist: ["search"] is a good practice to prevent persisting search terms across sessions.

Also applies to: 11-11, 14-14, 30-33


190-190: LGTM! Clean pagination implementation.

The pagination setup with total count from the API response is clean and follows good practices.


40-53: Verify the offset calculation for edge cases.

The offset calculation looks good, but let's ensure it handles all edge cases correctly:

  1. When qParams.page is undefined (first page)
  2. When qParams.page is 0 or negative
✅ Verification successful

Offset calculation is implemented correctly

The current implementation ((qParams.page ?? 1) - 1) * resultsPerPage properly handles all edge cases:

  • Defaults to page 1 when qParams.page is undefined
  • Cannot produce negative offsets due to the nullish coalescing operator
  • Correctly converts from 1-based page numbers to 0-based offset calculation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other pagination implementations in the codebase
rg -A 2 "offset.*page.*resultsPerPage" --type typescript

Length of output: 93


Script:

#!/bin/bash
# Search for pagination-related patterns
rg -t ts -t tsx -A 3 "offset.*=.*page" 

# Search for page parameter usage in query configurations
rg -t ts -t tsx -A 5 "queryParams.*page"

# Search specifically for resultsPerPage usage
rg -t ts -t tsx -A 2 "resultsPerPage"

Length of output: 205

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

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

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

nihal467 commented Feb 3, 2025

@Rishith25 what is the status on this PR

@Rishith25
Copy link
Contributor Author

@Rishith25 what is the status on this PR

@nihal467 I have to write test case for this functionality in the backend.
I have requested @rithviknishad to guide me how to write the test cases for username searching as we don't have test cases for that in backend

@github-actions github-actions bot added needs-triage question Further information is requested labels Feb 3, 2025
@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Feb 3, 2025
@khavinshankar
Copy link
Member

@Rishith25 fix the deploy failure and the cypress tests, lets get the frontend merged, you can do the username filter asynchronously.

@khavinshankar khavinshankar added changes required and removed needs-triage question Further information is requested labels Feb 4, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Feb 4, 2025
Copy link

github-actions bot commented Feb 4, 2025

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @Rishith25

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

@Rishith25
Copy link
Contributor Author

Rishith25 commented Feb 5, 2025

@Rishith25 fix the deploy failure and the cypress tests, lets get the frontend merged, you can do the username filter asynchronously.

@khavinshankar Resolved the merge conflicts and deploy is now successful

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Feb 5, 2025
@Jacobjeevan Jacobjeevan removed changes required Deploy-Failed Deplyment is not showing preview labels Feb 7, 2025
Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

Minor change, other lgtm barring BE filter.

src/components/Resource/ResourceDetailsUpdate.tsx Outdated Show resolved Hide resolved
@Rishith25 Rishith25 requested a review from Jacobjeevan February 7, 2025 04:57
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.

Add fallback url for goback() | OTP field auto focus | Add Search Feature for users
4 participants