feat: pages list
This commit is contained in:
@@ -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;
|
||||
<Link href={`/${page.type.toLowerCase()}/${page.slug}/edit`}>
|
||||
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
|
||||
</Link>
|
||||
{!isArchived && <ArchiveButton pageId={page.id} slug={page.slug} type={page.type} />}
|
||||
{!isArchived && <PinToggleButton pageId={page.id} isPinned={!!navlink} />}
|
||||
{!(isArchived || isDraft) && <ArchiveButton pageId={page.id} slug={page.slug} type={page.type} />}
|
||||
{!(isArchived || isDraft) && <PinToggleButton pageId={page.id} isPinned={!!navlink} />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user