Skip to content

Commit b129161

Browse files
Johan BookJohan Book
Johan Book
authored and
Johan Book
committed
feat(web-ui): use drawer to show organization list on mobile
1 parent e441528 commit b129161

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

services/web-ui/src/components/nav/AppBar/CurrentOrganizationAvatar.tsx

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { ReactElement } from "react";
1+
import { ReactElement, useState } from "react";
22

33
import { ErrorOutline } from "@mui/icons-material";
44
import {
55
Avatar,
6+
Box,
67
ButtonBase,
78
CircularProgress,
9+
Divider,
10+
Drawer,
811
MenuItem,
912
Skeleton,
13+
Typography,
1014
} from "@mui/material";
1115

1216
import { OrganizationDetails, SwitchOrganizationCommand } from "src/api";
@@ -21,6 +25,7 @@ import {
2125
useQueryClient,
2226
} from "src/core/query";
2327
import { useSnackbar } from "src/core/snackbar";
28+
import { useIsMobile } from "src/hooks/useIsMobile";
2429

2530
interface MenuContentProps {
2631
currentOrganizationId: number;
@@ -64,14 +69,21 @@ function MenuContent({ currentOrganizationId }: MenuContentProps) {
6469
);
6570
}
6671

72+
const filteredOrganizations = query.data.filter(
73+
(organization) => organization.id !== currentOrganizationId
74+
);
75+
6776
return (
6877
<>
69-
{query.data.map((organization) => (
78+
{filteredOrganizations.map((organization) => (
7079
<MenuItem
7180
key={organization.id}
7281
onClick={() => handleClick(organization)}
7382
selected={organization.id === currentOrganizationId}
7483
>
84+
<Avatar sx={{ height: 30, width: 30, mr: 2 }}>
85+
{organization.name[0]}
86+
</Avatar>
7587
{organization.name}
7688
</MenuItem>
7789
))}
@@ -80,6 +92,10 @@ function MenuContent({ currentOrganizationId }: MenuContentProps) {
8092
}
8193

8294
export function CurrentOrganizationAvatar(): ReactElement {
95+
const isMobile = useIsMobile();
96+
97+
const [drawerIsOpen, setIsDrawerOpen] = useState(false);
98+
8399
const query = useQuery({
84100
queryKey: [CacheKeysConstants.CurrentOrganization],
85101
queryFn: () => organizationsApi.getCurrentOrganization(),
@@ -93,6 +109,29 @@ export function CurrentOrganizationAvatar(): ReactElement {
93109
return <ErrorOutline color="error" sx={{ height: 30, width: 30 }} />;
94110
}
95111

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+
96135
return (
97136
<Menu
98137
anchorOrigin={{

0 commit comments

Comments
 (0)