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

Always show "online" for authenticated user profiles #9574

Merged
merged 8 commits into from
Dec 26, 2024

Conversation

abhimanyurajeesh
Copy link
Contributor

@abhimanyurajeesh abhimanyurajeesh commented Dec 26, 2024

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 user status indicator to accurately reflect the online status of the authenticated user.
  • Style
    • Minor formatting adjustment in the UserStatusIndicator component.

@abhimanyurajeesh abhimanyurajeesh requested a review from a team as a code owner December 26, 2024 08:47
Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request modifies the UserStatusIndicator component in the UserListAndCard.tsx file to address the online status display for the authenticated user. A new check is introduced to ensure that the authenticated user is always shown as online, regardless of their actual online status. This change aims to resolve an issue where the authenticated user's profile was incorrectly displaying a "last online" status.

Changes

File Change Summary
src/components/Users/UserListAndCard.tsx - Added authUser variable using useAuthUser() hook
- Introduced isAuthUser to check if the current user is the authenticated user
- Updated cur_online to include isAuthUser condition

Assessment against linked issues

Objective Addressed Explanation
Always show online status for authenticated accounts [#9570]

Poem

🐰 A rabbit's tale of status bright,
Where online means always in sight,
No more "last seen" for the logged-in soul,
Your presence now shines, full control!
Tech magic with just a simple line,
Making user status truly divine! 🌟


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 Dec 26, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 357abc3
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676d3c70a34d9400086bcbd3
😎 Deploy Preview https://deploy-preview-9574--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 (2)
src/components/Users/UserListAndCard.tsx (2)

137-138: Remove trailing spaces to satisfy prettier rules.
Both lines 137 and 138 appear to have trailing whitespace that's flagged by ESLint.

-  const authUser = useAuthUser(); 
-  const isAuthUser = user.id === authUser.id; 
+  const authUser = useAuthUser();
+  const isAuthUser = user.id === authUser.id;
🧰 Tools
🪛 eslint

[error] 137-137: Delete ·

(prettier/prettier)


[error] 138-138: Delete ·

(prettier/prettier)


238-238: Remove trailing space for consistency.
On line 238, ESLint suggests removing the extra space at the end of the line.

-  <div className="grid grid-cols-1 gap-4 @xl:grid-cols-3 @4xl:grid-cols-4 @6xl:grid-cols-5 lg:grid-cols-2"> 
+  <div className="grid grid-cols-1 gap-4 @xl:grid-cols-3 @4xl:grid-cols-4 @6xl:grid-cols-5 lg:grid-cols-2">
🧰 Tools
🪛 eslint

[error] 238-238: Delete ·

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20fe265 and f797a16.

📒 Files selected for processing (1)
  • src/components/Users/UserListAndCard.tsx (2 hunks)
🧰 Additional context used
🪛 eslint
src/components/Users/UserListAndCard.tsx

[error] 137-137: Delete ·

(prettier/prettier)


[error] 138-138: Delete ·

(prettier/prettier)


[error] 238-238: Delete ·

(prettier/prettier)

🔇 Additional comments (1)
src/components/Users/UserListAndCard.tsx (1)

139-139: Implementation correctly ensures the authenticated user is always shown as online.
This addresses the primary issue of displaying "Online now" for the user's own profile.

src/components/Users/UserListAndCard.tsx Outdated Show resolved Hide resolved
@rithviknishad
Copy link
Member

rithviknishad commented Dec 26, 2024

@abhimanyurajeesh

Do add proper title for the PR.

Refer the following on getting started to contributing:

@rithviknishad rithviknishad changed the title Issue fix Always show "online" for authenticated user profiles Dec 26, 2024
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.

LGTM, implement Rithvik's comment :)

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Dec 26, 2024
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4279ac and a89dada.

📒 Files selected for processing (1)
  • src/components/Users/UserListAndCard.tsx (1 hunks)
🧰 Additional context used
🪛 eslint
src/components/Users/UserListAndCard.tsx

[error] 139-139: 'isOnline' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

🔇 Additional comments (2)
src/components/Users/UserListAndCard.tsx (2)

137-139: Follow consistent naming conventions

The variable name cur_online doesn't follow the common JavaScript/TypeScript naming convention for boolean variables. The new isOnline variable follows better naming practices.

Let's maintain consistency by using the isOnline naming convention throughout the codebase. This includes updating other components that use cur_online:

  1. Update in getNameAndStatusCard:
const getNameAndStatusCard = (
  user: UserModel | UserAssignedModel,
- cur_online: boolean,
+ isOnline: boolean,
  showDetailsButton = false,
) => {
  // ...
      className={classNames(
        "flex items-center gap-2 rounded-full px-3 py-1",
-       cur_online ? "bg-green-100" : "bg-gray-100",
+       isOnline ? "bg-green-100" : "bg-gray-100",
      )}
  // ...
}
  1. Update in UserCard:
const UserCard = ({ user }: { user: UserModel | UserAssignedModel }) => {
- const userOnline = isUserOnline(user);
+ const isOnline = isUserOnline(user);
  // ...
- {getNameAndStatusCard(user, userOnline)}
+ {getNameAndStatusCard(user, isOnline)}
  // ...
}
🧰 Tools
🪛 eslint

[error] 139-139: 'isOnline' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)


137-139: Verify the impact on user experience

The change to always show authenticated users as online might need additional UI/UX considerations:

  1. Should we visually distinguish between "actually online" and "self-view always online"?
  2. Should we show a tooltip or additional context when viewing our own status?

Let's check if there are any existing UI patterns for status indicators:

✅ Verification successful

Based on the code analysis, I can now provide a final response:

Current UI implementation already handles online status distinction appropriately

The current implementation already provides clear visual distinction between online statuses:

  1. The UserStatusIndicator component uses different visual styles:

    • A green background (bg-green-100) for online users
    • A gray background (bg-gray-100) for offline users
    • The status is shown in a rounded pill/badge format (rounded-full)
  2. The implementation is consistent across different views:

    • Used in user lists (UserListAndCard.tsx)
    • Used in user banners (UserBanner.tsx)
    • Maintains consistent styling with padding variations for different contexts

The existing implementation provides sufficient visual distinction between actual online status and self-view status, as it uses standard UI patterns (color-coded badges) that are intuitive for users. Additional tooltips or visual indicators would add unnecessary complexity to an already clear interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other status indicator patterns in the codebase
rg -l 'StatusIndicator|status.*indicator|online.*status' --type tsx --type ts

Length of output: 107


Script:

#!/bin/bash
# Search for other status indicator patterns in the codebase, adjusting file extensions
rg -l 'StatusIndicator|status.*indicator|online.*status' --type ts

Length of output: 145


Script:

#!/bin/bash
# Look for UI components or styles related to online status
rg -A 3 'isOnline|online.*status|user.*status' --type ts

Length of output: 6086


Script:

#!/bin/bash
# Search for tooltip or visual indicator implementations
rg -A 3 'tooltip|Tooltip|title=' --type ts

Length of output: 74922


Script:

#!/bin/bash
# Find files that might contain the status indicator component
fd -e ts -e tsx StatusIndicator

Length of output: 33


Script:

#!/bin/bash
# Search for online status implementation and visual indicators
rg -A 5 'isOnline|online.*status|user.*status|status.*indicator' src/components/Users/

Length of output: 1144


Script:

#!/bin/bash
# Look for any UI components that show user status
ast-grep --pattern 'const $status = $$$; return <$$$>{$status}$$$' src/components/Users/

Length of output: 90


Script:

#!/bash/shell
# Search for any existing tooltip implementations for user status
rg -A 3 'title=.*online|tooltip.*online|aria-label.*online' src/components/Users/

Length of output: 83


Script:

#!/bin/bash
# Look for the implementation of isUserOnline function
rg -A 5 'function isUserOnline|const isUserOnline' --type ts

Length of output: 347


Script:

#!/bin/bash
# Search for any visual indicators or styles related to online status
rg -A 3 'className.*online|style.*online|<.*online' src/components/Users/

Length of output: 75


Script:

#!/bin/bash
# Look for any existing user status display components
rg -A 5 '<.*Status.*>|status.*indicator|status.*badge' src/components/Users/

Length of output: 1354


Script:

#!/bin/bash
# Look for the UserStatusIndicator component implementation
rg -A 10 'UserStatusIndicator' src/components/Users/ --type ts

Length of output: 4056


Script:

#!/bin/bash
# Search for any existing visual indicators or status dots
rg -A 3 'rounded-full.*bg-|h-[1-2].*w-[1-2].*bg-' src/components/Users/

Length of output: 73


Script:

#!/bin/bash
# Look for any existing tooltip or title implementations in the status indicator
ast-grep --pattern 'const $$ = isUserOnline($user); return <div $$$>{$$$}</div>' src/components/Users/

Length of output: 104


Script:

#!/bin/bash
# Look for the actual implementation of the status indicator's JSX
rg -A 10 'const isOnline = isUserOnline\(user\).*\{' src/components/Users/

Length of output: 76


Script:

#!/bin/bash
# Search for any existing status dot implementations
rg -A 3 'div.*className.*h-.*w-.*rounded.*bg-' src/components/Users/

Length of output: 70


Script:

#!/bin/bash
# Look for any existing tooltip components used with online status
rg -A 5 'Tooltip.*online|title.*online' src/CAREUI/

Length of output: 53


Script:

#!/bin/bash
# Look for the actual implementation of the status indicator's render logic
rg -A 10 'isOnline = isUserOnline.*\|\| isAuthUser' src/components/Users/

Length of output: 843


Script:

#!/bin/bash
# Search for any existing status dot implementations in RecordMeta
rg -A 5 'isOnline.*rounded-full' src/CAREUI/display/RecordMeta.tsx

Length of output: 68


Script:

#!/bin/bash
# Look for any existing online status implementations in the codebase
rg -A 5 'const isOnline.*return.*div' --type ts

Length of output: 49

🧰 Tools
🪛 eslint

[error] 139-139: 'isOnline' is assigned a value but never used. Allowed unused vars must match /^_/u.

(@typescript-eslint/no-unused-vars)

src/components/Users/UserListAndCard.tsx Show resolved Hide resolved
@rithviknishad rithviknishad added good to merge and removed needs testing needs review Deploy-Failed Deplyment is not showing preview labels Dec 26, 2024
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/Users/UserListAndCard.tsx (1)

137-141: Implementation looks good, consider adding type safety

The implementation correctly ensures that authenticated users are shown as online on their own profiles. However, consider adding type guards to handle potential undefined values.

  const authUser = useAuthUser();
- const isAuthUser = user.id === authUser.id;
+ const isAuthUser = Boolean(user.id && authUser.id && user.id === authUser.id);
  const isOnline = isUserOnline(user) || isAuthUser;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a89dada and 357abc3.

📒 Files selected for processing (1)
  • src/components/Users/UserListAndCard.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Users/UserListAndCard.tsx (1)

147-147: Verify consistent behavior across all component usages

The implementation correctly updates all instances where online status is used. The changes maintain consistency in the UI by updating:

  • Background color classes
  • Status indicator color
  • Text color
  • Status text display

Let's verify all usages of the UserStatusIndicator component:

Also applies to: 154-154, 160-160, 163-163

✅ Verification successful

Let me verify the implementation of UserStatusIndicator to ensure consistent behavior.


Let me check the full implementation of the component to verify the consistency.


Let me try one final check to see the complete implementation of the component.


Online status styling is consistently implemented across all usages

Based on the verification:

  • The UserStatusIndicator component is used in 3 locations: UserListAndCard.tsx (2 instances) and UserBanner.tsx (1 instance)
  • The component implementation shows consistent styling:
    • Container: bg-green-100 for online, bg-gray-100 for offline
    • Status dot: bg-green-500 for online, bg-gray-400 for offline
    • Text shows either "online" or relative time since last login
  • All instances use the same component with identical styling behavior, passing only the required user prop and optional padding
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all instances where UserStatusIndicator is used
# to ensure the changes don't have unintended side effects

# Find direct component usage
rg -A 2 "<UserStatusIndicator"

# Find imports of the component
rg "import.*UserStatusIndicator"

Length of output: 831


Script:

#!/bin/bash
# Find the implementation of UserStatusIndicator component
ast-grep --pattern 'const UserStatusIndicator = ({ $$ }) => {
  $$$
}'

# Also check for any other status-related styling
rg -A 3 'isOnline.*bg-' 

Length of output: 605


Script:

#!/bin/bash
# Get the full component implementation with more context
rg -B 5 -A 15 'const UserStatusIndicator'

# Check for any other online status related styling patterns
rg 'online.*className' -A 2

Length of output: 1334


Script:

#!/bin/bash
# Get a larger context around the UserStatusIndicator component
rg -B 5 -A 30 'export const UserStatusIndicator'

# Also check for any status-related text
rg '"online"' -A 2

Length of output: 2600

@rithviknishad rithviknishad merged commit 4d2e0d0 into ohcnetwork:develop Dec 26, 2024
22 checks passed
Copy link

@abhimanyurajeesh 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
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Incorrect online status for authenticated account's profile
3 participants