-
-
Notifications
You must be signed in to change notification settings - Fork 813
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
Added Chat Route in App.tsx to make Chat feature accessible #3255
Added Chat Route in App.tsx to make Chat feature accessible #3255
Conversation
WalkthroughThe pull request introduces a new route for the chat functionality in the user portal, specifically adding Changes
Assessment against linked issues
Possibly related PRs
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
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
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
🔭 Outside diff range comments (1)
src/screens/UserPortal/Chat/Chat.tsx (1)
Remove redundant useEffect hook
The useEffect with
[chatsListData]
dependency is redundant as its functionality is already covered by the filterType useEffect. This duplication could lead to race conditions when switching filters.🔗 Analysis chain
Line range hint
183-186
: Verify the necessity of this useEffect.This useEffect seems redundant with the 'all' filter case in the previous useEffect. Consider consolidating the logic to avoid potential conflicts.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for other uses of chatsListData in the codebase rg "chatsListData" -A 5 -B 5Length of output: 2476
🧰 Tools
🪛 Biome (1.9.4)
[error] 167-167: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 172-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 177-177: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 184-184: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🧹 Nitpick comments (1)
src/App.tsx (1)
194-195
: Remove commented out route.The old route
/user/chat
is commented out but should be removed for cleaner code maintenance. There's also another commented route at the bottom of the file that should be removed.- {/* <Route path="/user/chat" element={<Chat />} /> */}
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/App.tsx
(2 hunks)src/screens/UserPortal/Chat/Chat.tsx
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/screens/UserPortal/Chat/Chat.tsx
[error] 167-167: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 172-172: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 177-177: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test Application
- GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/App.tsx (1)
194-194
: LGTM! Route is properly secured.The new chat route is correctly placed under
SecuredRouteForUser
, ensuring that only authenticated users can access it. The:orgId
parameter follows the same pattern as other organization-scoped routes.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3255 +/- ##
=====================================================
+ Coverage 8.51% 90.24% +81.73%
=====================================================
Files 309 330 +21
Lines 7811 8492 +681
Branches 1730 1934 +204
=====================================================
+ Hits 665 7664 +6999
+ Misses 7072 598 -6474
- Partials 74 230 +156 ☔ View full report in Codecov by Sentry. |
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: 0
🧹 Nitpick comments (2)
src/screens/UserPortal/Chat/Chat.tsx (2)
164-184
: LGTM! Race conditions are properly handled.The async/await implementation properly prevents race conditions by awaiting each refetch operation before updating the state.
Add error handling for refetch operations.
Consider adding try-catch blocks to handle potential refetch failures gracefully.
async function getChats(): Promise<void> { + try { if (filterType === 'all') { await chatsListRefetch(); if (chatsListData?.chatsByUserId) { setChats(chatsListData.chatsByUserId); } } else if (filterType === 'unread') { await unreadChatListRefetch(); if (unreadChatListData?.getUnreadChatsByUserId) { setChats(unreadChatListData.getUnreadChatsByUserId); } } else if (filterType === 'group') { await groupChatListRefetch(); if (groupChatListData?.getGroupChatsByUserId) { setChats(groupChatListData.getGroupChatsByUserId); } } + } catch (error) { + console.error('Failed to fetch chats:', error); + // Consider showing a user-friendly error message + } }Use optional chaining for safer property access.
Replace the conditional checks with optional chaining for more concise and safer code.
- if (chatsListData && chatsListData.chatsByUserId) { + if (chatsListData?.chatsByUserId) { setChats(chatsListData.chatsByUserId); } - if (unreadChatListData && unreadChatListData.getUnreadChatsByUserId) { + if (unreadChatListData?.getUnreadChatsByUserId) { setChats(unreadChatListData.getUnreadChatsByUserId); } - if (groupChatListData && groupChatListData.getGroupChatsByUserId) { + if (groupChatListData?.getGroupChatsByUserId) { setChats(groupChatListData.getGroupChatsByUserId); }🧰 Tools
🪛 Biome (1.9.4)
[error] 168-168: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 173-173: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 178-178: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Line range hint
186-190
: Simplify the condition using optional chaining.The condition can be more concise while maintaining the same functionality.
- if (chatsListData && chatsListData?.chatsByUserId.length) { + if (chatsListData?.chatsByUserId?.length) { setChats(chatsListData.chatsByUserId); }🧰 Tools
🪛 Biome (1.9.4)
[error] 168-168: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 173-173: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 178-178: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 187-187: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/screens/UserPortal/Chat/Chat.tsx
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/screens/UserPortal/Chat/Chat.tsx (2)
Learnt from: Aad1tya27
PR: PalisadoesFoundation/talawa-admin#3255
File: src/screens/UserPortal/Chat/Chat.tsx:0-0
Timestamp: 2025-01-12T16:25:38.818Z
Learning: In the Chat component of talawa-admin, the `chats` state is initialized with an empty array by default using `useState<Chat[]>([])`, making explicit empty array assignments in else conditions unnecessary.
Learnt from: Aad1tya27
PR: PalisadoesFoundation/talawa-admin#3255
File: src/screens/UserPortal/Chat/Chat.tsx:0-0
Timestamp: 2025-01-12T16:24:16.293Z
Learning: In React components where a useEffect triggers data fetching operations and a separate useEffect handles the state updates based on that data (e.g., watching query results), it's not necessary to include the data variables in the first useEffect's dependency array. This pattern helps prevent unnecessary re-runs while maintaining proper data flow.
🪛 Biome (1.9.4)
src/screens/UserPortal/Chat/Chat.tsx
[error] 168-168: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 173-173: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 178-178: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Test Application
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: 0
🧹 Nitpick comments (3)
src/screens/UserPortal/Chat/Chat.spec.tsx (3)
4341-4369
: Consider adding test cases for non-empty responses.While the empty response mocks are good for basic testing, consider adding test cases that verify the component's behavior with:
- Multiple unread chats
- Multiple group chats
- Error states
{ request: { query: UNREAD_CHAT_LIST, }, result: { data: { - getUnreadChatsByUserId: [], + getUnreadChatsByUserId: [ + { + _id: '1', + messages: [{ + messageContent: 'Unread message', + sender: { _id: '2', firstName: 'Test' } + }], + unseenMessagesByUsers: JSON.stringify({ '1': 1 }) + } + ], }, }, }
Line range hint
4371-4440
: Enhance test coverage with additional assertions.The test successfully verifies basic filter functionality, but consider adding:
- Assertions for loading states
- Verification of error handling
- Checks for correct filter button states (active/inactive)
await act(async () => { fireEvent.click(unreadChatButton); }); + expect(unreadChatButton).toHaveClass('active'); + expect(allChatButton).not.toHaveClass('active'); + expect(groupChatButton).not.toHaveClass('active'); await act(async () => { fireEvent.click(groupChatButton); }); + expect(groupChatButton).toHaveClass('active'); + expect(unreadChatButton).not.toHaveClass('active'); + expect(allChatButton).not.toHaveClass('active');
Line range hint
1-4568
: Use obviously fake data in test mocks.The test data contains realistic-looking emails and IDs. Consider:
- Using clearly fake domains (e.g.,
@example.test
)- Using consistent and obviously fake ID patterns
- Avoiding patterns that might match production data
This prevents accidental leaks and makes it clear the data is for testing.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/screens/UserPortal/Chat/Chat.spec.tsx
(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test Application
- GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (1)
src/screens/UserPortal/Chat/Chat.spec.tsx (1)
4293-4313
: Mock data structure looks good but consider adding validation tests.The mock data structure correctly includes all required fields for users and creator objects. However, consider adding test cases to verify the handling of null/empty values for optional fields like
image
.✅ Verification successful
Mock data structure is appropriate for testing chat creation
The null values in the mock data are suitable for testing chat creation functionality, as the Chat component primarily handles data management rather than direct image rendering. The image field's presence in the mock data correctly validates the expected data structure, while actual image rendering and null-handling are managed by child components.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if there are any null checks for image field in the component ast-grep --pattern 'image && $$$' || ast-grep --pattern 'image ? $$$'Length of output: 134
Script:
#!/bin/bash # Check Chat component for image handling ast-grep --pattern 'const Chat = $$$' -f src/screens/UserPortal/Chat/Chat.tsx # Look for image props or references in Chat rg "image[\"']?:" src/screens/UserPortal/Chat/Chat.tsx -A 2 # Check for different null check patterns rg "(\?\?|!=\s*null|!==\s*null|===\s*null|==\s*null).*image" src/screens/UserPortal/Chat/Chat.tsxLength of output: 891
Script:
#!/bin/bash # Look for Avatar or Image component imports and usage rg "import.*Avatar|import.*Image" src/screens/UserPortal/Chat/Chat.tsx # Look for JSX elements using image prop ast-grep --pattern '<$_$_ image={$_}' # Look for avatar usage in Chat.tsx rg "<Avatar|<Image" src/screens/UserPortal/Chat/Chat.tsx -A 2Length of output: 176
@palisadoes I've fixed the issue and 1 faulty test. The |
0af5a6f
into
PalisadoesFoundation:develop-postgres
@Aad1tya27 The Chat route that you added should be nested under the |
What kind of change does this PR introduce?
Added Chat route to make the Chat feature accessible
Issue Number:
Fixes #2875
Snapshots/Videos:
If relevant, did you update the documentation?
No
Does this PR introduce a breaking change?
Yes
Checklist
CodeRabbit AI Review
Test Coverage
Other information
Have you read the contributing guide?
Yes
Summary by CodeRabbit
New Features
Bug Fixes
The changes introduce a new chat functionality accessible via
/user/chat/:orgId
, providing users with a streamlined chat experience within the application.