plane/space/app/[workspaceSlug]/[projectId]/page.tsx

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-05-14 20:55:38 +00:00
"use client";
2024-06-04 08:08:47 +00:00
import { useEffect, useState } from "react";
import { notFound, useSearchParams } from "next/navigation";
// components
2024-06-04 08:08:47 +00:00
import { LogoSpinner } from "@/components/common";
// helpers
import { navigate } from "@/helpers/actions";
// services
import PublishService from "@/services/publish.service";
const publishService = new PublishService();
2024-06-04 08:08:47 +00:00
type Props = {
params: {
workspaceSlug: string;
projectId: string;
2024-06-04 08:08:47 +00:00
};
};
2024-06-04 08:08:47 +00:00
const ProjectIssuesPage = (props: Props) => {
const { params } = props;
const { workspaceSlug, projectId } = params;
2024-06-04 08:08:47 +00:00
// states
const [error, setError] = useState(false);
// params
const searchParams = useSearchParams();
2024-06-04 08:08:47 +00:00
const board = searchParams.get("board") || undefined;
const peekId = searchParams.get("peekId") || undefined;
2024-06-04 08:08:47 +00:00
useEffect(() => {
if (!workspaceSlug || !projectId) return;
2024-06-04 08:08:47 +00:00
publishService
2024-06-04 13:49:27 +00:00
.fetchAnchorFromProjectDetails(workspaceSlug, projectId)
2024-06-04 08:08:47 +00:00
.then((res) => {
let url = "";
if (res.entity_name === "project") {
url = `/issues/${res.anchor}`;
const params = new URLSearchParams();
if (board) params.append("board", board);
if (peekId) params.append("peekId", peekId);
if (params.toString()) url += `?${params.toString()}`;
navigate(url);
} else throw Error("Invalid entity name");
2024-06-04 08:08:47 +00:00
})
.catch(() => setError(true));
}, [board, peekId, projectId, workspaceSlug]);
2024-06-04 08:08:47 +00:00
if (error) notFound();
return <LogoSpinner />;
};
2024-06-04 08:08:47 +00:00
export default ProjectIssuesPage;