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,14 +69,21 @@ 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
71
80
key = { organization . id }
72
81
onClick = { ( ) => handleClick ( organization ) }
73
82
selected = { organization . id === currentOrganizationId }
74
83
>
84
+ < Avatar sx = { { height : 30 , width : 30 , mr : 2 } } >
85
+ { organization . name [ 0 ] }
86
+ </ Avatar >
75
87
{ organization . name }
76
88
</ MenuItem >
77
89
) ) }
@@ -80,6 +92,10 @@ function MenuContent({ currentOrganizationId }: MenuContentProps) {
80
92
}
81
93
82
94
export function CurrentOrganizationAvatar ( ) : ReactElement {
95
+ const isMobile = useIsMobile ( ) ;
96
+
97
+ const [ drawerIsOpen , setIsDrawerOpen ] = useState ( false ) ;
98
+
83
99
const query = useQuery ( {
84
100
queryKey : [ CacheKeysConstants . CurrentOrganization ] ,
85
101
queryFn : ( ) => organizationsApi . getCurrentOrganization ( ) ,
@@ -93,6 +109,29 @@ export function CurrentOrganizationAvatar(): ReactElement {
93
109
return < ErrorOutline color = "error" sx = { { height : 30 , width : 30 } } /> ;
94
110
}
95
111
112
+ if ( isMobile ) {
113
+ return (
114
+ < >
115
+ < ButtonBase onClick = { ( ) => setIsDrawerOpen ( true ) } >
116
+ < Avatar sx = { { height : 30 , width : 30 } } > { query . data . name [ 0 ] } </ Avatar >
117
+ </ ButtonBase >
118
+
119
+ < Drawer
120
+ onClose = { ( ) => setIsDrawerOpen ( false ) }
121
+ open = { drawerIsOpen }
122
+ sx = { { zIndex : ( theme ) => theme . zIndex . drawer + 2 } }
123
+ >
124
+ < Box sx = { { display : "flex" , alignItems : "center" , p : 2 , gap : 2 } } >
125
+ < Avatar sx = { { height : 30 , width : 30 } } > { query . data . name [ 0 ] } </ Avatar >
126
+ < Typography > { query . data . name } </ Typography >
127
+ </ Box >
128
+ < Divider />
129
+ < MenuContent currentOrganizationId = { query . data . id } />
130
+ </ Drawer >
131
+ </ >
132
+ ) ;
133
+ }
134
+
96
135
return (
97
136
< Menu
98
137
anchorOrigin = { {
0 commit comments