File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 11import { LogOut } from "lucide-react" ;
2+ import { toast } from "sonner" ;
23import { DropdownMenuItem } from "@/components/ui/dropdown-menu" ;
34import { signOut } from "@/lib/auth/auth-client" ;
45
56export 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 (
Original file line number Diff line number Diff 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+ */
714function 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
1525export function UserAvatar ( { userName } : UserAvatarProps ) {
You can’t perform that action at this time.
0 commit comments