feat: pages list

This commit is contained in:
Ivan Rezchikov
2026-07-13 19:31:55 +03:00
parent 22122aedeb
commit 2e356e4c47
2 changed files with 47 additions and 6 deletions
+14 -6
View File
@@ -220,7 +220,7 @@ export default async function Page({ params }: { params: Promise<{ type: string;
if (!PAGE_TYPES.includes(pageType)) notFound(); if (!PAGE_TYPES.includes(pageType)) notFound();
const page = await getPageBySlug(slug, pageType); 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); 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 isNews = page.type === "NEWS";
const isArchived = page.status === "ARCHIVED"; 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 location = (page.meta as PageMeta)?.location;
const wasUpdatedByOther = page.updatedBy && page.createdBy !== page.updatedBy; 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, publishedAt: isNews ? formatDate(page.publishedAt) : null,
updatedAt: (wasUpdated || !isNews) ? formatDate(page.updatedAt) : null, updatedAt: (wasUpdated || !isNews) ? formatDate(page.updatedAt) : null,
location: location ?? null, location: location ?? null,
author: user?.isAdmin ? `${createdBy?.firstName} ${createdBy?.secondName}` : null, author:
updatedBy: user?.isAdmin && wasUpdatedByOther ? `${updatedBy?.firstName} ${updatedBy?.secondName}` : null, user?.isAdmin && createdBy
? `${createdBy.firstName} ${createdBy.secondName}`
: null,
updatedBy:
user?.isAdmin && wasUpdatedByOther && updatedBy
? `${updatedBy.firstName} ${updatedBy.secondName}`
: null,
}; };
return ( return (
@@ -255,8 +263,8 @@ export default async function Page({ params }: { params: Promise<{ type: string;
<Link href={`/${page.type.toLowerCase()}/${page.slug}/edit`}> <Link href={`/${page.type.toLowerCase()}/${page.slug}/edit`}>
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button> <Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
</Link> </Link>
{!isArchived && <ArchiveButton pageId={page.id} slug={page.slug} type={page.type} />} {!(isArchived || isDraft) && <ArchiveButton pageId={page.id} slug={page.slug} type={page.type} />}
{!isArchived && <PinToggleButton pageId={page.id} isPinned={!!navlink} />} {!(isArchived || isDraft) && <PinToggleButton pageId={page.id} isPinned={!!navlink} />}
</div> </div>
)} )}
</div> </div>
+33
View File
@@ -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 (
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
<h2>All pages of type ${type}</h2>
<div className="flex flex-col gap-6">
{
pages.length > 0 ? pages.map((n) => (
<NewsCard news={n} key={n.id} />
)) : <h2 className="text-muted-foreground">There are no pages of that type yet...</h2>
}
</div>
</div>
);
}