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' ;
2
11
import Image from 'next/image' ;
12
+ import { useState } from 'react' ;
3
13
4
14
import { LoggedUserData } from '@web/src/modules/auth/types/User' ;
5
15
@@ -13,8 +23,15 @@ import { UserMenuLink, UserMenuSplitLine } from './UserMenuLink';
13
23
import { UserMenuButton } from '../client/UserMenuButton' ;
14
24
15
25
export 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
+
16
33
return (
17
- < Popover >
34
+ < Popover onOpenChange = { ( ) => setIsEditingUsername ( false ) } >
18
35
< PopoverTrigger >
19
36
< UserMenuButton userData = { userData } />
20
37
</ PopoverTrigger >
@@ -30,7 +47,7 @@ export function UserMenu({ userData }: { userData: LoggedUserData }) {
30
47
< div className = 'min-w-48 max-w-64' >
31
48
{ /* User */ }
32
49
< 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 ' >
34
51
< Image
35
52
width = { 32 }
36
53
height = { 32 }
@@ -40,10 +57,47 @@ export function UserMenu({ userData }: { userData: LoggedUserData }) {
40
57
/>
41
58
</ div >
42
59
< 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 >
44
97
< p className = 'text-zinc-300 text-xs truncate' > { userData . email } </ p >
45
98
</ div >
46
99
</ div >
100
+ { error && < p className = 'text-sm text-red-400 px-4 pb-2' > { error } </ p > }
47
101
48
102
< UserMenuSplitLine />
49
103
0 commit comments