1- import { faMusic , faSignOutAlt } from '@fortawesome/free-solid-svg-icons' ;
1+ 'use client' ;
2+
3+ import {
4+ faCheck ,
5+ faClose ,
6+ faMusic ,
7+ faPencil ,
8+ faSignOutAlt ,
9+ } from '@fortawesome/free-solid-svg-icons' ;
10+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
211import Image from 'next/image' ;
12+ import { useState } from 'react' ;
313
414import { LoggedUserData } from '@web/src/modules/auth/types/User' ;
515
@@ -13,8 +23,15 @@ import { UserMenuLink, UserMenuSplitLine } from './UserMenuLink';
1323import { UserMenuButton } from '../client/UserMenuButton' ;
1424
1525export function UserMenu ( { userData } : { userData : LoggedUserData } ) {
26+ const [ isEditingUsername , setIsEditingUsername ] = useState ( false ) ;
27+ const [ error , setError ] = useState < string > ( '' ) ;
28+
29+ // ERRORS:
30+ // 'This username is not available! :('
31+ // 'Your username may only contain these characters: A-Z a-z 0-9 - _ .'
32+
1633 return (
17- < Popover >
34+ < Popover onOpenChange = { ( ) => setIsEditingUsername ( false ) } >
1835 < PopoverTrigger >
1936 < UserMenuButton userData = { userData } />
2037 </ PopoverTrigger >
@@ -30,7 +47,7 @@ export function UserMenu({ userData }: { userData: LoggedUserData }) {
3047 < div className = 'min-w-48 max-w-64' >
3148 { /* User */ }
3249 < div className = 'flex flex-row gap-2 items-center p-4 pb-3' >
33- < div className = 'h-8 w-8' >
50+ < div className = 'h-8 w-8 aspect-square ' >
3451 < Image
3552 width = { 32 }
3653 height = { 32 }
@@ -40,10 +57,47 @@ export function UserMenu({ userData }: { userData: LoggedUserData }) {
4057 />
4158 </ div >
4259 < div className = 'flex-shrink min-w-0 flex flex-col leading-tight' >
43- < h4 className = 'truncate font-semibold' > { userData . username } </ h4 >
60+ < div className = 'flex justify-start items-center gap-2' >
61+ { ! isEditingUsername ? (
62+ < >
63+ < h4 className = 'truncate font-semibold w-48 py-px' >
64+ { userData . username }
65+ </ h4 >
66+ < button onClick = { ( ) => setIsEditingUsername ( true ) } >
67+ < FontAwesomeIcon
68+ icon = { faPencil }
69+ size = 'sm'
70+ className = 'text-zinc-400 hover:text-zinc-200'
71+ />
72+ </ button >
73+ </ >
74+ ) : (
75+ < >
76+ < input
77+ className = 'w-[calc(12rem-52px)] font-semibold bg-transparent border border-zinc-400 rounded-md px-1'
78+ defaultValue = { userData . username }
79+ > </ input >
80+ < button onClick = { ( ) => setIsEditingUsername ( false ) } >
81+ < FontAwesomeIcon
82+ icon = { faClose }
83+ size = 'lg'
84+ className = 'text-zinc-400 hover:text-red-500'
85+ />
86+ </ button >
87+ < button onClick = { ( ) => setIsEditingUsername ( false ) } >
88+ < FontAwesomeIcon
89+ icon = { faCheck }
90+ size = 'lg'
91+ className = 'text-zinc-400 hover:text-green-500'
92+ />
93+ </ button >
94+ </ >
95+ ) }
96+ </ div >
4497 < p className = 'text-zinc-300 text-xs truncate' > { userData . email } </ p >
4598 </ div >
4699 </ div >
100+ { error && < p className = 'text-sm text-red-400 px-4 pb-2' > { error } </ p > }
47101
48102 < UserMenuSplitLine />
49103
0 commit comments