Add initials fallback for users without profile avatars - #27
Conversation
Signed-off-by: Anshika Guleria <anshikaguleria532@gmail.com>
|
@anshika-guleria is attempting to deploy a commit to the Parv Aggarwal's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthrough
ChangesAvatar Initials Fallback
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@barterly-frontend/src/components/layout/DashboardHeader.jsx`:
- Around line 29-32: The initials fallback logic does not properly handle
whitespace-only names. After the trim operation that creates the `trimmed`
variable on Line 29, add a guard check to verify that `trimmed` is not an empty
string. If it is empty (meaning the original name contained only whitespace),
return a visible fallback character or string instead of proceeding with the
empty string. This ensures the avatar will display a fallback indicator rather
than blank initials when given whitespace-only input.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d9514117-ba9d-48fd-a3de-4b85ddf95e3f
📒 Files selected for processing (1)
barterly-frontend/src/components/layout/DashboardHeader.jsx
| const trimmed = name.trim(); | ||
|
|
||
| // Has spaces (Jane Doe, jane doe) | ||
| const parts = trimmed.split(/\s+/); |
There was a problem hiding this comment.
Handle whitespace-only names in initials fallback.
On Line 29, name.trim() can become ""; current logic then returns an empty string (Line 52) instead of a visible fallback. Add a post-trim guard so the avatar never renders blank initials.
Proposed fix
const getInitials = (name) => {
if (!name) return "?";
const trimmed = name.trim();
+ if (!trimmed) return "?";
// Has spaces (Jane Doe, jane doe)
const parts = trimmed.split(/\s+/);Also applies to: 51-53
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@barterly-frontend/src/components/layout/DashboardHeader.jsx` around lines 29
- 32, The initials fallback logic does not properly handle whitespace-only
names. After the trim operation that creates the `trimmed` variable on Line 29,
add a guard check to verify that `trimmed` is not an empty string. If it is
empty (meaning the original name contained only whitespace), return a visible
fallback character or string instead of proceeding with the empty string. This
ensures the avatar will display a fallback indicator rather than blank initials
when given whitespace-only input.
What Changed
Added a fallback avatar in the dashboard header when a user has not uploaded a profile image.
Implemented a utility function to generate initials from the user's name.
Supported different name formats such as:
Replaced the default person icon with user initials for a more personalized experience.
Why
How To Test
Log in with a user account that does not have a profile image.
Open the dashboard.
Verify that initials are displayed instead of the default avatar icon.
Test with different name formats such as:
Related Issue
Closes #26
Checklist
CONTRIBUTING.md.Notes
Summary by CodeRabbit
Release Notes