Skip to content

fix: add initials fallback for users without avatars to profile and s… - #31

Merged
Parvaggarwal01 merged 1 commit into
Parvaggarwal01:mainfrom
anshika-guleria:fix/avatar-initials-fallback
Jun 21, 2026
Merged

fix: add initials fallback for users without avatars to profile and s…#31
Parvaggarwal01 merged 1 commit into
Parvaggarwal01:mainfrom
anshika-guleria:fix/avatar-initials-fallback

Conversation

@anshika-guleria

@anshika-guleria anshika-guleria commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Added a reusable getInitials utility function.

  • Updated the Dashboard Header avatar fallback to display user initials when no profile image is available.

  • Improved handling for:

    • Multi-word names (e.g. "Anshika Guleria" → AG)
    • CamelCase names
    • Single-word names

Why

Previously, users without a profile picture saw a generic fallback. Displaying initials provides a more personalized and user-friendly experience. I updated it for Profile and Sidebar as well

How To Test

  1. Run the frontend application.

  2. Log in with a user that does not have a profile image.

  3. Navigate to the dashboard.

  4. Verify that the avatar in the header displays the correct initials.

  5. Test with different name formats:

    • Single-word names
    • Multi-word names
    • CamelCase names

Related Issue

Closes #28

Notes

This update only affects the DashboardHeader, Profile, and Sidebar avatar fallback. Similar improvements for Profile and Sidebar components can be implemented using a utility for consistency.

Summary by CodeRabbit

  • Improvements
    • Enhanced user avatar fallback behavior across dashboard components. Avatar placeholders now display user initials instead of generic icons when a profile picture is unavailable, improving user recognition and visual consistency throughout the app.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new shared getInitials(name) utility is added and imported into DashboardHeader, Sidebar, and Profile. Each component's avatar fallback is updated to display user initials instead of a generic material "person" icon. Profile.jsx also removes an unused ReviewModal import and reformats several JSX blocks.

Changes

Shared getInitials utility and avatar fallback rollout

Layer / File(s) Summary
getInitials utility
barterly-frontend/src/utils/getInitials.js
Adds getInitials(name) with tiered extraction: multi-word names use first+last word initials, single-word names use first+last uppercase characters, and a default falls back to the first two characters. Returns "?" for falsy input.
Avatar fallback wiring in DashboardHeader and Sidebar
barterly-frontend/src/components/layout/DashboardHeader.jsx, barterly-frontend/src/components/layout/Sidebar.jsx
DashboardHeader replaces its removed local getInitials with the shared import. Sidebar adds the import and replaces the gray "person" icon placeholder with a bg-primary centered initials container derived from user?.name.
Profile avatar fallback and JSX reformatting
barterly-frontend/src/pages/user/Profile.jsx
Adds getInitials import, removes unused ReviewModal, and switches the header avatar fallback from a material "person" icon to rendered initials. The rest of the diff is JSX reformatting of stars, rating bars, skills section, reviews section, and the edit-profile modal with no behavioral changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Parvaggarwal01/Barterly#27: Introduced an in-file getInitials helper in DashboardHeader.jsx for the same avatar-fallback purpose; this PR extracts and centralizes that logic into the shared utility.

Poem

🐇 Hop hop, no more "person" icon in sight,
Initials now shimmer with getInitials light!
One utility shared across every page,
DashboardHeader, Sidebar, Profile — all the rage.
The rabbit refactored, the duplicates gone,
Clean utility code helps the frontend march on! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title concisely describes the main change: adding initials fallback for users without avatars across multiple components (profile and sidebar).
Linked Issues check ✅ Passed All coding requirements from issue #28 are met: getInitials utility created and integrated into Profile, Sidebar, and DashboardHeader components to display initials consistently.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #28 objectives: creating the getInitials utility and updating the three specified components to use it for avatar fallbacks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (1)
barterly-frontend/src/pages/user/Profile.jsx (1)

419-421: ⚡ Quick win

Keep avatar fallback consistent inside the Edit Profile modal.

Line 420 still renders a generic person icon while the page now uses initials fallbacks elsewhere. Reusing getInitials here keeps the experience consistent.

Suggested refactor
                 <div className="w-20 h-20 border-2 border-black bg-neutral-200 overflow-hidden shrink-0">
                   {avatarPreview ? (
                     <img src={avatarPreview} alt="Preview" className="w-full h-full object-cover" />
                   ) : (
                     <div className="w-full h-full flex items-center justify-center bg-primary">
-                      <span className="material-symbols-outlined text-4xl">person</span>
+                      <span className="font-black text-2xl text-black uppercase select-none">
+                        {getInitials(editForm.name || user?.name)}
+                      </span>
                     </div>
                   )}
                 </div>
🤖 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/pages/user/Profile.jsx` around lines 419 - 421, The
avatar fallback in the Edit Profile modal is rendering a generic person icon
instead of using initials like other parts of the application. Replace the span
element that contains the material-symbols-outlined "person" icon with a text
display that uses the getInitials function to show user initials, ensuring
consistent fallback behavior throughout the component.
🤖 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/utils/getInitials.js`:
- Around line 2-6: The getInitials function does not handle whitespace-only
names properly. After trimming the input name on the line with trim(), add a
check to verify that the trimmed result is not an empty string. If the trimmed
string is empty, return "?" as a fallback instead of continuing with the split
operation. This validation should occur immediately after the trim() assignment
and before the split(/\s+/) call to catch names that consist only of whitespace
characters.

---

Nitpick comments:
In `@barterly-frontend/src/pages/user/Profile.jsx`:
- Around line 419-421: The avatar fallback in the Edit Profile modal is
rendering a generic person icon instead of using initials like other parts of
the application. Replace the span element that contains the
material-symbols-outlined "person" icon with a text display that uses the
getInitials function to show user initials, ensuring consistent fallback
behavior throughout the component.
🪄 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: 0f10aa1a-a2db-462a-a46b-c317de982315

📥 Commits

Reviewing files that changed from the base of the PR and between d532961 and 8bbff12.

📒 Files selected for processing (4)
  • barterly-frontend/src/components/layout/DashboardHeader.jsx
  • barterly-frontend/src/components/layout/Sidebar.jsx
  • barterly-frontend/src/pages/user/Profile.jsx
  • barterly-frontend/src/utils/getInitials.js

Comment on lines +2 to +6
if (!name) return "?";

const trimmed = name.trim();

const parts = trimmed.split(/\s+/);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Handle whitespace-only names before splitting.

On Line 4, a whitespace-only string becomes empty after trim(), and Line 24 then returns an empty initials string instead of a visible fallback ("?").

Suggested fix
 export const getInitials = (name) => {
-  if (!name) return "?";
-
-  const trimmed = name.trim();
+  if (typeof name !== "string") return "?";
+  const trimmed = name.trim();
+  if (!trimmed) return "?";

Also applies to: 24-24

🤖 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/utils/getInitials.js` around lines 2 - 6, The
getInitials function does not handle whitespace-only names properly. After
trimming the input name on the line with trim(), add a check to verify that the
trimmed result is not an empty string. If the trimmed string is empty, return
"?" as a fallback instead of continuing with the split operation. This
validation should occur immediately after the trim() assignment and before the
split(/\s+/) call to catch names that consist only of whitespace characters.

@Parvaggarwal01
Parvaggarwal01 merged commit 8bbff12 into Parvaggarwal01:main Jun 21, 2026
4 of 5 checks passed
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.

fix: The name initials arent working on other pages

2 participants