Skip to content

Fix user avatar fallback initials display in RiskAssessmentFeed.tsx, … - #840

Merged
timbastin merged 2 commits into
l3montree-dev:mainfrom
MNTarentula:fix-user-avatar-initials
Jul 27, 2026
Merged

Fix user avatar fallback initials display in RiskAssessmentFeed.tsx, …#840
timbastin merged 2 commits into
l3montree-dev:mainfrom
MNTarentula:fix-user-avatar-initials

Conversation

@MNTarentula

Copy link
Copy Markdown
Contributor

Fixed RiskAssessmentFeed default Icon is an "U" but should be user initals
l3montree-dev/devguard#2653

The issue was that the avatar fallback only used user.realName.charAt(0), so users without an avatar only showed one letter. Changed it to generate initials from the user name by taking the first letter of up to two name parts and converting them to uppercase.

While checking the issue I also looked into the findUser helper. It can return "Unknown" when the user ID from the event does not match any organization member or current user. I did not change this logic because I could not confirm this was the cause without a working backend/Ory environment, but it may be related to cases where the wrong user data is received.the file name is view.ts

I could not fully test the application locally because the frontend requires the backend and Ory services to run. The change was tested by checking the frontend code path and formatting/linting requirements. if need more detials ask.

…line 265

The risk assessment feed avatar fallback displayed only the first character
of a user's name. Update it to show up to two initials instead.

@juliankepka juliankepka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the quick PR! 🙏 The fix already goes in the right direction, but there's still a small bug: instead of the expected single initial (e.g. "J"), it currently shows "UU". See screenshot.

Image

As you suggested correctly, the root cause isn't in the code changed here, but in findUser in src/utils/view.ts. There, realName is built via name.first + " " + name.last. Since traits.name can also be a plain string (and first/last are optional), this ends up as "undefined undefined" → initials "UU".

What do you think about also making these changes in view.ts? It reuses the existing getUserFullName helper, which handles both the string and the {first, last} case (same as in UserNav.tsx):

 import { type Identity } from "@ory/client-fetch";
+import { getUserFullName, type User } from "@/types/auth";
 import { externalProviderIdToIntegrationName } from "./externalProvider";
   if (currentUser?.id === id) {
+    const fullName = getUserFullName(currentUser as unknown as User);
     return {
       displayName: "You",
       avatarUrl: currentUser.traits?.picture,
-      realName:
-        currentUser.traits?.name.first + " " + currentUser.traits?.name.last,
+      realName: fullName || currentUser.traits?.email || "You",
     };
   }

If you're happy with this, feel free to commit it and I'll approve the PR :)

@MNTarentula

Copy link
Copy Markdown
Contributor Author

got it, thanks. i will implement it and update the PR.

…emove the getting two initals of first and last name and changed to get only one intial like asked, i test the comments and now appear the real inital i tested with few accounts not one.
@MNTarentula

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the quick PR! 🙏 The fix already goes in the right direction, but there's still a small bug: instead of the expected single initial (e.g. "J"), it currently shows "UU". See screenshot.

Image As you suggested correctly, the root cause isn't in the code changed here, but in `findUser` in `src/utils/view.ts`. There, `realName` is built via `name.first + " " + name.last`. Since `traits.name` can also be a plain string (and `first`/`last` are optional), this ends up as `"undefined undefined"` → initials "UU".

What do you think about also making these changes in view.ts? It reuses the existing getUserFullName helper, which handles both the string and the {first, last} case (same as in UserNav.tsx):

 import { type Identity } from "@ory/client-fetch";
+import { getUserFullName, type User } from "@/types/auth";
 import { externalProviderIdToIntegrationName } from "./externalProvider";
   if (currentUser?.id === id) {
+    const fullName = getUserFullName(currentUser as unknown as User);
     return {
       displayName: "You",
       avatarUrl: currentUser.traits?.picture,
-      realName:
-        currentUser.traits?.name.first + " " + currentUser.traits?.name.last,
+      realName: fullName || currentUser.traits?.email || "You",
     };
   }

If you're happy with this, feel free to commit it and I'll approve the PR :)

sorry for waiting i just need to do other stuff. i commit and it ready, also what you suggest really fix that.
by the way i test that the issuse is gone now, also i remove the two initials and changed back to one, like you ask and i do it two before becuase i think it suppose to be like first name and last name initials.

@MNTarentula

Copy link
Copy Markdown
Contributor Author

thanks for your review and approving, bye and good luck in your stuff

@timbastin
timbastin merged commit 43fb97e into l3montree-dev:main Jul 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RiskAssessmentFeed default Icon is an "U" but should be user initals

3 participants