diff --git a/space/app/[workspaceSlug]/[projectId]/layout.tsx b/space/app/[workspaceSlug]/[projectId]/layout.tsx deleted file mode 100644 index a205d599f..000000000 --- a/space/app/[workspaceSlug]/[projectId]/layout.tsx +++ /dev/null @@ -1,17 +0,0 @@ -"use client"; - -type Props = { - children: React.ReactNode; - params: { - workspaceSlug: string; - projectId: string; - }; -}; - -const IssuesLayout = (props: Props) => { - const { children } = props; - - return <>{children}; -}; - -export default IssuesLayout; diff --git a/space/app/[workspaceSlug]/[projectId]/page.ts b/space/app/[workspaceSlug]/[projectId]/page.ts new file mode 100644 index 000000000..8af878397 --- /dev/null +++ b/space/app/[workspaceSlug]/[projectId]/page.ts @@ -0,0 +1,42 @@ +import { notFound, redirect } from "next/navigation"; +// services +import PublishService from "@/services/publish.service"; +// types +import { TPublishSettings } from "@/types/publish"; + +const publishService = new PublishService(); + +type Props = { + params: { + workspaceSlug: string; + projectId: string; + }; + searchParams: any; +}; + +export default async function IssuesPage(props: Props) { + const { params, searchParams } = props; + // query params + const { workspaceSlug, projectId } = params; + const { board, peekId } = searchParams; + + let response: TPublishSettings | undefined = undefined; + try { + response = await publishService.fetchAnchorFromProjectDetails(workspaceSlug, projectId); + } catch (error) { + // redirect to 404 page on error + notFound(); + } + + let url = ""; + if (response.entity_name === "project") { + url = `/issues/${response.anchor}`; + const params = new URLSearchParams(); + if (board) params.append("board", board); + if (peekId) params.append("peekId", peekId); + if (params.toString()) url += `?${params.toString()}`; + redirect(url); + } else { + notFound(); + } +} diff --git a/space/app/[workspaceSlug]/[projectId]/page.tsx b/space/app/[workspaceSlug]/[projectId]/page.tsx deleted file mode 100644 index 04d60fce9..000000000 --- a/space/app/[workspaceSlug]/[projectId]/page.tsx +++ /dev/null @@ -1,54 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import { notFound, useSearchParams, useRouter } from "next/navigation"; -// components -import { LogoSpinner } from "@/components/common"; -// services -import PublishService from "@/services/publish.service"; -const publishService = new PublishService(); - -type Props = { - params: { - workspaceSlug: string; - projectId: string; - }; -}; - -const IssuesPage = (props: Props) => { - const { params } = props; - const { workspaceSlug, projectId } = params; - // states - const [error, setError] = useState(false); - // router - const router = useRouter(); - // params - const searchParams = useSearchParams(); - const board = searchParams.get("board"); - const peekId = searchParams.get("peekId"); - - useEffect(() => { - if (!workspaceSlug || !projectId) return; - publishService - .fetchAnchorFromProjectDetails(workspaceSlug, projectId) - .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()}`; - router.push(url); - // navigate(url); - } else throw Error("Invalid entity name"); - }) - .catch(() => setError(true)); - }, [board, peekId, projectId, router, workspaceSlug]); - - if (error) notFound(); - - return ; -}; - -export default IssuesPage;