Files
eu/app/[type]/page.tsx
T
2026-07-13 19:31:55 +03:00

34 lines
1.1 KiB
TypeScript

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>
);
}