Skip to content

Commit

Permalink
(FE) Add Retrieving a Workspace (#73)
Browse files Browse the repository at this point in the history
* Add retrieving a workspace

* Fix lint
  • Loading branch information
devleejb authored Jan 19, 2024
1 parent cbd38ea commit 03c4fa5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions frontend/src/components/drawers/WorkspaceDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Box,
Divider,
Drawer,
IconButton,
ListItem,
ListItemAvatar,
ListItemButton,
Expand All @@ -14,11 +15,16 @@ import { useSelector } from "react-redux";
import { selectUser } from "../../store/userSlice";
import { MouseEventHandler, useState } from "react";
import ProfilePopover from "../common/ProfilePopover";
import { useParams } from "react-router-dom";
import { useGetWorkspaceQuery } from "../../hooks/api/workspace";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";

const DRAWER_WIDTH = 240;

function WorkspaceDrawer() {
const params = useParams();
const userStore = useSelector(selectUser);
const { data: workspace } = useGetWorkspaceQuery(params.workspaceId);
const [profileAnchorEl, setProfileAnchorEl] = useState<(EventTarget & Element) | null>(null);

const handleOpenProfilePopover: MouseEventHandler = (event) => {
Expand All @@ -43,6 +49,22 @@ function WorkspaceDrawer() {
anchor="left"
open
>
<ListItem disablePadding>
<ListItemButton>
<ListItemText
primary={workspace?.title}
primaryTypographyProps={{
variant: "subtitle1",
noWrap: true,
}}
/>
<ListItemSecondaryAction>
<IconButton>
<KeyboardArrowDownIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItemButton>
</ListItem>
<Box sx={{ mt: "auto" }}>
<Divider />
<ListItem disablePadding>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/hooks/api/types/workspace.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Workspace {
id: string;
title: string;
createdAt: Date;
updatedAt: Date;
}

export class GetWorkspaceResponse extends Workspace {}
23 changes: 23 additions & 0 deletions frontend/src/hooks/api/workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
import { GetWorkspaceResponse } from "./types/workspace";

export const generateGetWorkspaceQueryKey = (workspaceId: string) => {
return ["workspaces", workspaceId];
};

export const useGetWorkspaceQuery = (workspaceId?: string) => {
const query = useQuery({
queryKey: generateGetWorkspaceQueryKey(workspaceId || ""),
enabled: Boolean(workspaceId),
queryFn: async () => {
const res = await axios.get<GetWorkspaceResponse>(`/workspaces/${workspaceId}`);
return res.data;
},
meta: {
errorMessage: "This is a non-existent or unauthorized Workspace.",
},
});

return query;
};

0 comments on commit 03c4fa5

Please sign in to comment.