1
- import { signInPath , signUpPath } from '@/app/app/paths' ;
1
+ import Link from 'next/link' ;
2
+ import { usePathname } from 'next/navigation' ;
3
+ import { useState } from 'react' ;
4
+
5
+ import { signOutUser } from '@/api/utils/supabase/sign-out-user.server' ;
6
+ import { profilPath , signInPath , signUpPath } from '@/app/app/paths' ;
2
7
import { useDemoMode } from '@/app/users/demo-mode-support-provider' ;
3
- import { Button , Checkbox } from '@/ui' ;
4
- import MenuUtilisateur from './MenuUtilisateur' ;
8
+ import { Button , ButtonMenu , Checkbox } from '@/ui' ;
5
9
import { HeaderPropsWithModalState } from './types' ;
6
10
7
11
/** liens en "accès rapide" */
8
12
export const AccesRapide = ( props : HeaderPropsWithModalState ) => {
9
13
const { user, setModalOpened } = props ;
10
14
const { isDemoMode, toggleDemoMode } = useDemoMode ( ) ;
11
15
16
+ const pathname = usePathname ( ) ;
17
+
18
+ const isUserPath = pathname === profilPath ;
19
+
20
+ const [ isUserMenuOpen , setIsUserMenuOpen ] = useState ( false ) ;
21
+
12
22
return (
13
23
< ul className = "flex max-lg:flex-col mb-0" >
14
24
{ user ?. isSupport && (
@@ -24,11 +34,64 @@ export const AccesRapide = (props: HeaderPropsWithModalState) => {
24
34
</ li >
25
35
) }
26
36
< li onClick = { ( ) => setModalOpened ( false ) } >
27
- < Aide />
37
+ < Button
38
+ data-test = "nav-help"
39
+ variant = "white"
40
+ size = "sm"
41
+ icon = "question-line"
42
+ iconPosition = "left"
43
+ href = "https://aide.territoiresentransitions.fr/fr/"
44
+ external
45
+ >
46
+ Aide
47
+ </ Button >
28
48
</ li >
29
49
{ user ? (
30
50
< li >
31
- < MenuUtilisateur { ...props } />
51
+ < ButtonMenu
52
+ data-test = "nav-user"
53
+ variant = "white"
54
+ size = "sm"
55
+ icon = { `${ user . isSupport ? 'customer-service' : 'account-circle' } -${
56
+ isUserPath ? 'fill' : 'line'
57
+ } `}
58
+ className = "max-w-80"
59
+ menuContainerClassName = "z-[2000]"
60
+ text = { user . prenom }
61
+ withArrow
62
+ openState = { {
63
+ isOpen : isUserMenuOpen ,
64
+ setIsOpen : setIsUserMenuOpen ,
65
+ } }
66
+ >
67
+ < div
68
+ className = "flex flex-col text-center"
69
+ onClick = { ( ) => {
70
+ setModalOpened ( false ) ;
71
+ setIsUserMenuOpen ( false ) ;
72
+ } }
73
+ >
74
+ < Link
75
+ href = { profilPath }
76
+ data-test = "user-profile"
77
+ className = "p-3 text-sm hover:!bg-primary-1"
78
+ style = { { backgroundImage : 'none' } }
79
+ >
80
+ Profil
81
+ </ Link >
82
+ < div className = "h-[1px] bg-grey-4" />
83
+ { /** Bouton déconnexion */ }
84
+ < Link
85
+ className = "p-3 text-sm hover:!bg-primary-1"
86
+ style = { { backgroundImage : 'none' } }
87
+ data-test = "user-logout"
88
+ onClick = { async ( ) => await signOutUser ( ) }
89
+ href = "/"
90
+ >
91
+ < span className = "px-6" > Déconnexion</ span >
92
+ </ Link >
93
+ </ div >
94
+ </ ButtonMenu >
32
95
</ li >
33
96
) : (
34
97
< >
@@ -65,27 +128,3 @@ export const AccesRapide = (props: HeaderPropsWithModalState) => {
65
128
</ ul >
66
129
) ;
67
130
} ;
68
-
69
- /**
70
- * Ouvre le lien vers le centre d'aide.
71
- */
72
- const Aide = ( ) => {
73
- const onClick = async ( ) => {
74
- // on utilise un bouton avec ouverture explicite du lien pour ne pas
75
- // utiliser <a target="_blank"> qui empêche de mettre une icône...
76
- window . open ( 'https://aide.territoiresentransitions.fr/fr/' , '_blank' ) ;
77
- } ;
78
-
79
- return (
80
- < Button
81
- data-test = "nav-help"
82
- className = "text-primary-9"
83
- variant = "white"
84
- size = "sm"
85
- icon = "question-line"
86
- onClick = { onClick }
87
- >
88
- Aide
89
- </ Button >
90
- ) ;
91
- } ;
0 commit comments