mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
32 lines
764 B
TypeScript
32 lines
764 B
TypeScript
|
import useSWR from "swr";
|
||
|
import { useRouter } from "next/router";
|
||
|
// types
|
||
|
import { IWorkspace } from "types";
|
||
|
// services
|
||
|
import workspaceService from "services/workspace.service";
|
||
|
// constants
|
||
|
import { USER_WORKSPACES } from "constants/fetch-keys";
|
||
|
|
||
|
const useWorkspaces = () => {
|
||
|
// router
|
||
|
const router = useRouter();
|
||
|
const { workspaceSlug } = router.query;
|
||
|
// API to fetch user information
|
||
|
const {
|
||
|
data = [],
|
||
|
error,
|
||
|
mutate,
|
||
|
} = useSWR<IWorkspace[]>(USER_WORKSPACES, () => workspaceService.userWorkspaces());
|
||
|
// active workspace
|
||
|
const activeWorkspace = data?.find((w) => w.slug === workspaceSlug);
|
||
|
|
||
|
return {
|
||
|
workspaces: data,
|
||
|
error,
|
||
|
activeWorkspace,
|
||
|
mutateWorkspaces: mutate,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export default useWorkspaces;
|