Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FE) Add Retrieving a Workspace #73

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading