@@ -4,10 +4,13 @@ import { observer } from 'mobx-react-lite'
4
4
5
5
import { linksConfig } from '@postgres.ai/shared/config/links'
6
6
import { Button } from '@postgres.ai/shared/components/MenuButton'
7
+ import { ROUTES } from 'config/routes'
7
8
9
+ import { SignOutModal } from './SignOutModal'
8
10
import { Header } from './Header'
9
11
import githubIconUrl from './icons/github.svg'
10
12
import docsIconUrl from './icons/docs.svg'
13
+ import exitIcon from './icons/exit-icon.svg'
11
14
import discussionIconUrl from './icons/discussion.svg'
12
15
import arrowLeftIconUrl from './icons/arrow-left.svg'
13
16
import arrowRightIconUrl from './icons/arrow-right.svg'
@@ -17,66 +20,90 @@ import styles from './styles.module.scss'
17
20
const LAPTOP_WIDTH_PX = 1024
18
21
const SIDEBAR_COLLAPSED_PARAM = 'sidebarMenuCollapsed'
19
22
20
- export const Menu = observer ( ( ) => {
21
- const [ isCollapsed , setIsCollapsed ] = useState (
22
- ( ) =>
23
- window . innerWidth < LAPTOP_WIDTH_PX ||
24
- localStorage . getItem ( SIDEBAR_COLLAPSED_PARAM ) === '1' ,
25
- )
23
+ export const Menu = observer (
24
+ ( { isValidToken } : { isValidToken : boolean | undefined } ) => {
25
+ const [ isOpen , setIsOpen ] = useState ( false )
26
+ const [ isCollapsed , setIsCollapsed ] = useState (
27
+ ( ) =>
28
+ window . innerWidth < LAPTOP_WIDTH_PX ||
29
+ localStorage . getItem ( SIDEBAR_COLLAPSED_PARAM ) === '1' ,
30
+ )
26
31
27
- const handleClick = ( ) => {
28
- setIsCollapsed ( ! isCollapsed )
29
- localStorage . setItem ( SIDEBAR_COLLAPSED_PARAM , isCollapsed ? '0' : '1' )
30
- }
32
+ const handleCollapse = ( ) => {
33
+ setIsCollapsed ( ! isCollapsed )
34
+ localStorage . setItem ( SIDEBAR_COLLAPSED_PARAM , isCollapsed ? '0' : '1' )
35
+ }
31
36
32
- return (
33
- < div className = { cn ( styles . root , isCollapsed && styles . collapsed ) } >
34
- < div className = { styles . content } >
35
- < Header isCollapsed = { isCollapsed } />
36
- </ div >
37
- < footer className = { styles . footer } >
38
- < Button
39
- type = "gateway-link"
40
- href = { linksConfig . github }
41
- icon = { < img src = { githubIconUrl } alt = "GitHub" /> }
42
- isCollapsed = { isCollapsed }
43
- >
44
- Star us on GitHub
45
- </ Button >
37
+ const handleSignOut = ( ) => {
38
+ localStorage . removeItem ( 'token' )
39
+ window . location . href = ROUTES . AUTH . path
40
+ }
46
41
47
- < Button
48
- type = "gateway-link"
49
- href = { linksConfig . docs }
50
- icon = { < img src = { docsIconUrl } alt = "Documentation" /> }
51
- isCollapsed = { isCollapsed }
52
- >
53
- Documentation
54
- </ Button >
42
+ return (
43
+ < div className = { cn ( styles . root , isCollapsed && styles . collapsed ) } >
44
+ < div className = { styles . content } >
45
+ < Header isCollapsed = { isCollapsed } />
46
+ </ div >
47
+ < footer className = { styles . footer } >
48
+ < Button
49
+ type = "gateway-link"
50
+ href = { linksConfig . github }
51
+ icon = { < img src = { githubIconUrl } alt = "GitHub" /> }
52
+ isCollapsed = { isCollapsed }
53
+ >
54
+ Star us on GitHub
55
+ </ Button >
55
56
56
- < Button
57
- type = "gateway-link"
58
- href = { linksConfig . support }
59
- className = { styles . supportBtn }
60
- icon = { < img src = { discussionIconUrl } alt = "Discussion" /> }
61
- isCollapsed = { isCollapsed }
62
- >
63
- Ask support
64
- </ Button >
57
+ < Button
58
+ type = "gateway-link"
59
+ href = { linksConfig . docs }
60
+ icon = { < img src = { docsIconUrl } alt = "Documentation" /> }
61
+ isCollapsed = { isCollapsed }
62
+ >
63
+ Documentation
64
+ </ Button >
65
65
66
- < Button
67
- className = { styles . collapseBtn }
68
- onClick = { handleClick }
69
- isCollapsed = { isCollapsed }
70
- icon = {
71
- < img
72
- src = { isCollapsed ? arrowRightIconUrl : arrowLeftIconUrl }
73
- alt = { isCollapsed ? 'Arrow right' : 'Arrow left' }
74
- />
75
- }
76
- >
77
- Collapse
78
- </ Button >
79
- </ footer >
80
- </ div >
81
- )
82
- } )
66
+ < Button
67
+ type = "gateway-link"
68
+ href = { linksConfig . support }
69
+ className = { styles . supportBtn }
70
+ icon = { < img src = { discussionIconUrl } alt = "Discussion" /> }
71
+ isCollapsed = { isCollapsed }
72
+ >
73
+ Ask support
74
+ </ Button >
75
+ { isValidToken && (
76
+ < Button
77
+ type = "button"
78
+ onClick = { ( ) => setIsOpen ( true ) }
79
+ icon = { < img src = { exitIcon } alt = "Profile" /> }
80
+ isCollapsed = { isCollapsed }
81
+ >
82
+ Sign out
83
+ </ Button >
84
+ ) }
85
+ < Button
86
+ className = { styles . collapseBtn }
87
+ onClick = { handleCollapse }
88
+ isCollapsed = { isCollapsed }
89
+ icon = {
90
+ < img
91
+ src = { isCollapsed ? arrowRightIconUrl : arrowLeftIconUrl }
92
+ alt = { isCollapsed ? 'Arrow right' : 'Arrow left' }
93
+ />
94
+ }
95
+ >
96
+ Collapse
97
+ </ Button >
98
+ </ footer >
99
+ { isOpen && (
100
+ < SignOutModal
101
+ handleSignOut = { handleSignOut }
102
+ onClose = { ( ) => setIsOpen ( false ) }
103
+ isOpen = { isOpen }
104
+ />
105
+ ) }
106
+ </ div >
107
+ )
108
+ } ,
109
+ )
0 commit comments