1
- import { ReactElement } from "react" ;
1
+ import { ReactElement , useState } from "react" ;
2
2
3
3
import { ErrorOutline } from "@mui/icons-material" ;
4
4
import {
5
5
Avatar ,
6
+ Box ,
6
7
ButtonBase ,
7
8
CircularProgress ,
9
+ Divider ,
10
+ Drawer ,
8
11
MenuItem ,
9
12
Skeleton ,
13
+ Typography ,
10
14
} from "@mui/material" ;
11
15
12
16
import { OrganizationDetails , SwitchOrganizationCommand } from "src/api" ;
@@ -21,6 +25,7 @@ import {
21
25
useQueryClient ,
22
26
} from "src/core/query" ;
23
27
import { useSnackbar } from "src/core/snackbar" ;
28
+ import { useIsMobile } from "src/hooks/useIsMobile" ;
24
29
25
30
interface MenuContentProps {
26
31
currentOrganizationId : number ;
@@ -64,22 +69,42 @@ function MenuContent({ currentOrganizationId }: MenuContentProps) {
64
69
) ;
65
70
}
66
71
72
+ const filteredOrganizations = query . data . filter (
73
+ ( organization ) => organization . id !== currentOrganizationId
74
+ ) ;
75
+
67
76
return (
68
77
< >
69
- { query . data . map ( ( organization ) => (
78
+ { filteredOrganizations . map ( ( organization ) => (
70
79
< MenuItem
80
+ sx = { { maxWidth : "65vw" } }
71
81
key = { organization . id }
72
82
onClick = { ( ) => handleClick ( organization ) }
73
83
selected = { organization . id === currentOrganizationId }
74
84
>
75
- { organization . name }
85
+ < Avatar sx = { { height : 30 , width : 30 , mr : 2 } } >
86
+ { organization . name [ 0 ] }
87
+ </ Avatar >
88
+ < Typography
89
+ sx = { {
90
+ overflow : "hidden" ,
91
+ textOverflow : "ellipsis" ,
92
+ whiteSpace : "nowrap" ,
93
+ } }
94
+ >
95
+ { organization . name }
96
+ </ Typography >
76
97
</ MenuItem >
77
98
) ) }
78
99
</ >
79
100
) ;
80
101
}
81
102
82
103
export function CurrentOrganizationAvatar ( ) : ReactElement {
104
+ const isMobile = useIsMobile ( ) ;
105
+
106
+ const [ drawerIsOpen , setIsDrawerOpen ] = useState ( false ) ;
107
+
83
108
const query = useQuery ( {
84
109
queryKey : [ CacheKeysConstants . CurrentOrganization ] ,
85
110
queryFn : ( ) => organizationsApi . getCurrentOrganization ( ) ,
@@ -93,6 +118,46 @@ export function CurrentOrganizationAvatar(): ReactElement {
93
118
return < ErrorOutline color = "error" sx = { { height : 30 , width : 30 } } /> ;
94
119
}
95
120
121
+ if ( isMobile ) {
122
+ return (
123
+ < >
124
+ < ButtonBase onClick = { ( ) => setIsDrawerOpen ( true ) } >
125
+ < Avatar sx = { { height : 30 , width : 30 } } > { query . data . name [ 0 ] } </ Avatar >
126
+ </ ButtonBase >
127
+
128
+ < Drawer
129
+ onClose = { ( ) => setIsDrawerOpen ( false ) }
130
+ open = { drawerIsOpen }
131
+ sx = { { zIndex : ( theme ) => theme . zIndex . drawer + 2 } }
132
+ >
133
+ < Box
134
+ sx = { {
135
+ display : "flex" ,
136
+ alignItems : "center" ,
137
+ p : 2 ,
138
+ gap : 2 ,
139
+ width : "65vw" ,
140
+ } }
141
+ >
142
+ < Avatar sx = { { height : 30 , width : 30 } } > { query . data . name [ 0 ] } </ Avatar >
143
+ < Typography
144
+ sx = { {
145
+ overflow : "hidden" ,
146
+ textOverflow : "ellipsis" ,
147
+ whiteSpace : "nowrap" ,
148
+ } }
149
+ variant = "h6"
150
+ >
151
+ { query . data . name }
152
+ </ Typography >
153
+ </ Box >
154
+ < Divider sx = { { mb : 1 } } />
155
+ < MenuContent currentOrganizationId = { query . data . id } />
156
+ </ Drawer >
157
+ </ >
158
+ ) ;
159
+ }
160
+
96
161
return (
97
162
< Menu
98
163
anchorOrigin = { {
0 commit comments