diff --git a/app/[type]/[slug]/page.tsx b/app/[type]/[slug]/page.tsx index 5c289e6..3187654 100644 --- a/app/[type]/[slug]/page.tsx +++ b/app/[type]/[slug]/page.tsx @@ -220,7 +220,7 @@ export default async function Page({ params }: { params: Promise<{ type: string; if (!PAGE_TYPES.includes(pageType)) notFound(); const page = await getPageBySlug(slug, pageType); - if (!page || (!user?.isAdmin && page.status == "ARCHIVED")) notFound(); + if (!page || (!user?.isAdmin && (page.status === "ARCHIVED" || page.status === "DRAFT"))) notFound(); const navlink = await getNavLinkByPageId(page.id); @@ -233,7 +233,8 @@ export default async function Page({ params }: { params: Promise<{ type: string; const isNews = page.type === "NEWS"; const isArchived = page.status === "ARCHIVED"; - const wasUpdated = formatDate(page.publishedAt) !== formatDate(page.updatedAt); + const isDraft = page.status === "DRAFT"; + const wasUpdated = page.updatedAt !== page.publishedAt; const location = (page.meta as PageMeta)?.location; const wasUpdatedByOther = page.updatedBy && page.createdBy !== page.updatedBy; @@ -241,8 +242,15 @@ export default async function Page({ params }: { params: Promise<{ type: string; publishedAt: isNews ? formatDate(page.publishedAt) : null, updatedAt: (wasUpdated || !isNews) ? formatDate(page.updatedAt) : null, location: location ?? null, - author: user?.isAdmin ? `${createdBy?.firstName} ${createdBy?.secondName}` : null, - updatedBy: user?.isAdmin && wasUpdatedByOther ? `${updatedBy?.firstName} ${updatedBy?.secondName}` : null, + author: + user?.isAdmin && createdBy + ? `${createdBy.firstName} ${createdBy.secondName}` + : null, + + updatedBy: + user?.isAdmin && wasUpdatedByOther && updatedBy + ? `${updatedBy.firstName} ${updatedBy.secondName}` + : null, }; return ( @@ -255,8 +263,8 @@ export default async function Page({ params }: { params: Promise<{ type: string; - {!isArchived && } - {!isArchived && } + {!(isArchived || isDraft) && } + {!(isArchived || isDraft) && } )} diff --git a/app/[type]/page.tsx b/app/[type]/page.tsx new file mode 100644 index 0000000..cc9bba6 --- /dev/null +++ b/app/[type]/page.tsx @@ -0,0 +1,33 @@ +import { NewsCard } from "@/components/news-card"; +import { getPages } from "@/lib/pages/repository"; +import { PAGE_TYPES, PageType } from "@/lib/pages/types"; +import { getCurrentUser } from "@/lib/user"; +import { Metadata } from "next"; +import { notFound, redirect } from "next/navigation"; + +export const metadata: Metadata = { title: "Pages" }; + +export default async function Pages({ params }: { params: Promise<{ type: string }> }) { + const user = await getCurrentUser(); + if (!user?.isAdmin) redirect("/"); + + const { type } = await params; + if (!PAGE_TYPES.includes(type as PageType)) { + notFound(); + } + + const pages = await getPages(type as PageType, "PUBLISHED"); + + return ( +
+

All pages of type ${type}

+
+ { + pages.length > 0 ? pages.map((n) => ( + + )) :

There are no pages of that type yet...

+ } +
+
+ ); +}