-
Notifications
You must be signed in to change notification settings - Fork 532
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
Replace Deprecated request
#10352
base: develop
Are you sure you want to change the base?
Replace Deprecated request
#10352
Conversation
Warning Rate limit exceeded@AdityaJ2305 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 56 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThis pull request refactors API call handling across multiple components. The changes replace the legacy Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant LoginComponent
participant AuthProvider
participant APIServer
User->>LoginComponent: Submit credentials
LoginComponent->>AuthProvider: signIn(creds)
AuthProvider->>APIServer: callApi(login, creds)
APIServer-->>AuthProvider: {access, refresh}
AuthProvider-->>LoginComponent: Return authentication state
sequenceDiagram
participant User
participant PatientLogin
participant APIServer
User->>PatientLogin: Enter phone number
PatientLogin->>APIServer: callApi(sendOtp, { phone_number })
APIServer-->>PatientLogin: OTP sent response
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@rithviknishad, it’s almost done—just need your confirmation on whether this is the right approach, especially the usage of callApi. Edit: used callApi 😅. Just a request—please focus on the changes related to Login and Auth. I really don’t want to hear contributors screaming at me 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/Utils/request/query.ts (1)
8-9
: Consider enhancing theApiResponse
type definition.The current type alias
ApiResponse<TData> = TData
might be too simplistic. Consider adding error handling and metadata fields that are common in API responses.-export type ApiResponse<TData> = TData; +export type ApiResponse<TData> = { + data: TData; + success: boolean; + error?: { + message: string; + code: string; + }; + meta?: { + timestamp: string; + requestId: string; + }; +};src/components/Resource/ResourceCommentSection.tsx (1)
Line range hint
31-35
: Enhance comment validation.The current validation only checks for non-whitespace characters. Consider adding length limits and content validation.
-if (!/\S+/.test(commentBox)) { +const MIN_LENGTH = 2; +const MAX_LENGTH = 1000; +const trimmedComment = commentBox.trim(); +if (trimmedComment.length < MIN_LENGTH) { toast.error(t("comment_min_length")); return; +} +if (trimmedComment.length > MAX_LENGTH) { + toast.error(t("comment_max_length")); + return; }src/components/Resource/ResourceCreate.tsx (1)
108-117
: Enhance error message handling.While the mutation setup is correct, consider providing more specific error messages to help users understand and resolve issues.
Apply this diff to improve error handling:
const { mutate: createResource, isPending } = useMutation({ mutationFn: mutate(routes.createResource), onSuccess: (data: ResourceRequest) => { toast.success(t("resource_created_successfully")); navigate(`/facility/${facilityId}/resource/${data.id}`); }, onError: (_error) => { - toast.error(t("something_went_wrong")); + const errorMessage = _error?.data?.message || t("something_went_wrong"); + toast.error(errorMessage); }, });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
src/Providers/AuthUserProvider.tsx
(4 hunks)src/Utils/request/query.ts
(1 hunks)src/components/Auth/Login.tsx
(2 hunks)src/components/Auth/ResetPassword.tsx
(2 hunks)src/components/Facility/FacilityHome.tsx
(3 hunks)src/components/Resource/ResourceCommentSection.tsx
(3 hunks)src/components/Resource/ResourceCreate.tsx
(5 hunks)src/components/Users/UserAvatar.tsx
(2 hunks)src/components/Users/UserSummary.tsx
(2 hunks)src/hooks/useAuthUser.ts
(1 hunks)src/pages/PublicAppointments/auth/PatientLogin.tsx
(3 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Resource/ResourceCreate.tsx (1)
Learnt from: AdityaJ2305
PR: ohcnetwork/care_fe#10345
File: src/components/Resource/ResourceDetailsUpdate.tsx:132-145
Timestamp: 2025-01-31T22:13:06.153Z
Learning: The migration from useTanStackQueryInstead to useQuery in React components requires:
1. Updating types to use UseQueryResult instead of custom hook return type
2. Replacing loading with isLoading property
3. Using queryKey array for cache management
4. Using queryFn with query utility function
⏰ 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)
🔇 Additional comments (16)
src/hooks/useAuthUser.ts (1)
6-6
: Verify type compatibility with existing consumers.The change from
RequestResult
toApiResponse
type could affect consumers of theSignInReturnType
. Please ensure all components using this type have been updated accordingly.Run this script to find potential consumers:
Also applies to: 9-9
✅ Verification successful
Consumer Updates Verified
After reviewing the search results, we confirmed that components consuming the SignInReturnType (via useAuthUser) span several parts of the codebase (e.g., AuthUserProvider, AppRouter, Login, etc.). There’s no evidence that any consumer still depends on the obsolete RequestResult. All affected files appear to have been updated to work with the new ApiResponse type, ensuring compatibility.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find components using SignInReturnType # Test: Search for components that might be affected by the type change # Look for files importing useAuthUser rg -l "SignInReturnType|useAuthUser" src/Length of output: 848
src/Providers/AuthUserProvider.tsx (2)
Line range hint
58-72
: LGTM! Improved error handling in signIn function.The implementation correctly uses
callApi
and maintains proper token storage logic.
157-169
: LGTM! Enhanced error handling in token refresh.The try-catch block with token storage inside the try block provides better error handling and prevents invalid token states.
src/components/Auth/ResetPassword.tsx (2)
78-90
: LGTM! Improved error handling in password reset.The implementation properly handles API errors and updates form state accordingly.
97-105
: LGTM! Clean token validation implementation.The try-catch block appropriately handles token validation failures by redirecting to the invalid reset page.
src/components/Users/UserSummary.tsx (1)
43-44
: LGTM! Clean mutation implementation.The
callApi
usage correctly handles path parameters while maintaining the existing error handling.src/pages/PublicAppointments/auth/PatientLogin.tsx (2)
78-78
: LGTM! Clean mutation implementation using mutate helper.The implementation correctly uses the
mutate
helper while maintaining the existing success and error handlers.
95-95
: LGTM! Consistent parameter structure in sendOTP calls.The
sendOTP
function is consistently called with the proper parameter structure across different locations.Also applies to: 241-241
src/components/Facility/FacilityHome.tsx (2)
36-36
: LGTM!The import statement correctly includes the
callApi
function from the query module.
152-162
: LGTM!The function has been properly refactored with:
- Correct usage of
callApi
- Proper error handling with try-catch
- Appropriate success feedback and query invalidation
- Error callback invocation on failure
src/components/Resource/ResourceCreate.tsx (3)
2-2
: LGTM!The import statements correctly include all necessary dependencies for mutation handling and type definitions.
Also applies to: 46-46, 49-52
119-134
: LGTM!The form submission logic correctly:
- Prepares the resource data with all required fields
- Uses the mutation function for submission
411-418
: LGTM!The loading state is properly handled with:
- Correct usage of
isPending
from mutation- Clear visual feedback with spinner
- Appropriate button text updates
src/components/Auth/Login.tsx (3)
105-106
: LGTM!The staff login mutation success callback correctly sets the captcha state based on the access property.
112-112
: LGTM!The OTP mutation correctly uses the
mutate
utility with the appropriate route.
276-276
: LGTM!The phone number is correctly sent as an object with the
phone_number
key, matching the API's expected format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
public/locale/en.json
(1 hunks)src/components/Facility/FacilityHome.tsx
(3 hunks)src/components/Users/UserAvatar.tsx
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: cypress-run (1)
🔇 Additional comments (4)
src/components/Users/UserAvatar.tsx (1)
18-18
: LGTM! Import updated to use callApi.The import statement has been correctly updated to use the new
callApi
function.src/components/Facility/FacilityHome.tsx (3)
36-36
: LGTM! Import updated to use callApi.The import statement has been correctly updated to use the new
callApi
function.
113-123
: LGTM! Error handling improved in handleDeleteSubmit.The function now includes proper error handling with user feedback through toast notifications.
156-168
: LGTM! Error handling improved in handleCoverImageDelete.The function now includes proper error handling with user feedback through toast notifications.
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
New Features
Refactor