Skip to content

Commit 8ffdefa

Browse files
committed
apply claude's recommendations
1 parent b18dd80 commit 8ffdefa

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/components/user-menu/sign-out-menu-item.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { LogOut } from "lucide-react";
2+
import { toast } from "sonner";
23
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
34
import { signOut } from "@/lib/auth/auth-client";
45

56
export function SignOutMenuItem() {
67
const handleSignOut = async () => {
7-
await signOut();
8+
try {
9+
await signOut();
10+
} catch (error) {
11+
console.error("Sign out failed:", error);
12+
toast.error("Failed to sign out. Please try again.");
13+
}
814
};
915

1016
return (

src/components/user-menu/user-avatar.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ interface UserAvatarProps {
44
userName: string;
55
}
66

7+
/**
8+
* Extracts initials from a user's full name.
9+
* Takes the first letter of the first word and last word (max 2 characters).
10+
* @example getInitials("John Doe") // "JD"
11+
* @example getInitials("Madonna") // "M"
12+
* @example getInitials("") // "?"
13+
*/
714
function getInitials(name: string): string {
8-
return name
9-
.split(" ")
10-
.map((word) => word[0])
11-
.join("")
12-
.toUpperCase();
15+
const words = name.trim().split(/\s+/).filter(Boolean);
16+
if (words.length === 0) return "?";
17+
18+
// Take first letter of first word and first letter of last word (max 2 chars)
19+
const first = words[0][0];
20+
const last = words.length > 1 ? words[words.length - 1][0] : "";
21+
22+
return (first + last).toUpperCase();
1323
}
1424

1525
export function UserAvatar({ userName }: UserAvatarProps) {

0 commit comments

Comments
 (0)