-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FE) Add Retrieving a Workspace (#73)
* Add retrieving a workspace * Fix lint
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |