fix: handle undefined user name in UI components
- Added null check in getUserInitials function to return "??" for undefined names - Fixed logout button to handle undefined user.name when displaying first name - Prevents 500 errors when rendering components for users without names 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -130,7 +130,7 @@ $effect(() => {
|
|||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div class="text-left flex flex-col min-w-0 flex-1">
|
<div class="text-left flex flex-col min-w-0 flex-1">
|
||||||
<span class="text-sm font-medium text-foreground leading-none truncate transition-all duration-200 {isNearThreshold ? 'text-destructive' : ''}" style="opacity: {Math.max(0.15, 1 - slideProgress * 1.5)}">{user.name.split(" ")[0]}</span>
|
<span class="text-sm font-medium text-foreground leading-none truncate transition-all duration-200 {isNearThreshold ? 'text-destructive' : ''}" style="opacity: {Math.max(0.15, 1 - slideProgress * 1.5)}">{user.name ? user.name.split(" ")[0] : "User"}</span>
|
||||||
<span class="text-xs text-muted-foreground leading-none transition-all duration-200 {isNearThreshold ? 'text-destructive/70' : ''}" style="opacity: {Math.max(0.1, 1 - slideProgress * 1.8)}">
|
<span class="text-xs text-muted-foreground leading-none transition-all duration-200 {isNearThreshold ? 'text-destructive/70' : ''}" style="opacity: {Math.max(0.1, 1 - slideProgress * 1.8)}">
|
||||||
{slideProgress > 0.3 ? "Logout" : "Online"}
|
{slideProgress > 0.3 ? "Logout" : "Online"}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const calcReadingTime = (text: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getUserInitials = (name: string) => {
|
export const getUserInitials = (name: string) => {
|
||||||
|
if (!name) return "??";
|
||||||
return name
|
return name
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.map((word) => word.charAt(0))
|
.map((word) => word.charAt(0))
|
||||||
|
|||||||
Reference in New Issue
Block a user