mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
1026ae3eb1
* chore: use estimate points hook created * chore: user auth layer * fix: build error
43 lines
1021 B
TypeScript
43 lines
1021 B
TypeScript
import { useEffect } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import useSWR from "swr";
|
|
|
|
// services
|
|
import projectService from "services/project.service";
|
|
// fetch-keys
|
|
import { PROJECT_DETAILS } from "constants/fetch-keys";
|
|
|
|
const useProjectDetails = () => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
const {
|
|
data: projectDetails,
|
|
error: projectDetailsError,
|
|
mutate: mutateProjectDetails,
|
|
} = useSWR(
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
workspaceSlug && projectId
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
: null
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (projectDetailsError?.status === 404) {
|
|
router.push("/404");
|
|
} else if (projectDetailsError) {
|
|
router.push("/error");
|
|
}
|
|
}, [projectDetailsError, router]);
|
|
|
|
return {
|
|
projectDetails,
|
|
projectDetailsError,
|
|
mutateProjectDetails,
|
|
};
|
|
};
|
|
|
|
export default useProjectDetails;
|