|
|
|
@@ -4,44 +4,131 @@ import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository";
|
|
|
|
|
import { getCurrentUser, getUser } from "@/lib/user";
|
|
|
|
|
import { notFound } from "next/navigation";
|
|
|
|
|
import { Block, PAGE_TYPES, PageMeta, PageType } from "@/lib/pages/types";
|
|
|
|
|
import { formatDate } from "@/lib/utils";
|
|
|
|
|
import { ArchiveIcon, CalendarIcon, Globe2Icon, InfoIcon, PencilIcon, UserIcon } from "lucide-react";
|
|
|
|
|
import { cn, formatDate } from "@/lib/utils";
|
|
|
|
|
import { CalendarIcon, DotIcon, Globe2Icon, InfoIcon, PencilIcon, UserIcon } from "lucide-react";
|
|
|
|
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
|
|
|
|
import Link from "next/link";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { archivePageAction } from "@/lib/pages/actions";
|
|
|
|
|
import { ArchiveButton } from "./archiveButton";
|
|
|
|
|
import { PinToggleButton } from "./pinToggleButton";
|
|
|
|
|
import { getNavLinkByPageId } from "@/lib/navlinks/repository";
|
|
|
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
|
|
|
|
import Image from "next/image";
|
|
|
|
|
|
|
|
|
|
function BlockRenderer({ block }: { block: Block }) {
|
|
|
|
|
const b = block.content;
|
|
|
|
|
|
|
|
|
|
function BlockRenderer({ block }: {block: Block }) {
|
|
|
|
|
const b = block.content
|
|
|
|
|
switch (b.type) {
|
|
|
|
|
case "PARAGRAPH":
|
|
|
|
|
return <h4>{b.text}</h4>
|
|
|
|
|
return (
|
|
|
|
|
<p className="leading-relaxed whitespace-pre-wrap">
|
|
|
|
|
{b.text}
|
|
|
|
|
</p>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "HEADING":
|
|
|
|
|
switch (b.level) {
|
|
|
|
|
case 1:
|
|
|
|
|
return <h1>{b.text}</h1>
|
|
|
|
|
return <h1>{b.text}</h1>;
|
|
|
|
|
case 2:
|
|
|
|
|
return <h2>{b.text}</h2>
|
|
|
|
|
return <h2>{b.text}</h2>;
|
|
|
|
|
case 3:
|
|
|
|
|
return <h3>{b.text}</h3>
|
|
|
|
|
return <h3>{b.text}</h3>;
|
|
|
|
|
default:
|
|
|
|
|
return <h2>{b.text}</h2>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "QUOTE":
|
|
|
|
|
return <div className="flex flex-col gap-2 border-l-2 border-muted-foreground pl-4">
|
|
|
|
|
<p>{b.text}</p>
|
|
|
|
|
<h5 className="text-sm text-muted-foreground">{b.author}</h5>
|
|
|
|
|
</div>
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-2 border-l-2 border-muted-foreground pl-4">
|
|
|
|
|
<p className="italic">{b.text}</p>
|
|
|
|
|
{b.author && (
|
|
|
|
|
<h5 className="text-sm text-muted-foreground">
|
|
|
|
|
— {b.author}
|
|
|
|
|
</h5>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "CALLOUT":
|
|
|
|
|
return <Alert>
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
<AlertTitle>{b.title}</AlertTitle>
|
|
|
|
|
<AlertDescription>{b.text}</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
return (
|
|
|
|
|
<Alert className="w-max">
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
<AlertTitle>{b.title}</AlertTitle>
|
|
|
|
|
<AlertDescription>{b.text}</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "IMAGE":
|
|
|
|
|
return (
|
|
|
|
|
<figure className="flex flex-col gap-2">
|
|
|
|
|
<Image
|
|
|
|
|
src={b.url}
|
|
|
|
|
alt={b.caption || "Image"}
|
|
|
|
|
width={1200}
|
|
|
|
|
height={800}
|
|
|
|
|
className="rounded-md border max-w-200 h-auto object-contain"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{b.caption && (
|
|
|
|
|
<figcaption className="text-sm text-muted-foreground">
|
|
|
|
|
{b.caption}
|
|
|
|
|
</figcaption>
|
|
|
|
|
)}
|
|
|
|
|
</figure>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "LIST":
|
|
|
|
|
return b.style === "ORDERED" ? (
|
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
{b.items.map((item: string, index: number) => (
|
|
|
|
|
<p className="flex flex-row gap-1 items-center" key={index}><span className="text-muted-foreground">{index+1}.</span> {item}</p>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
{b.items.map((item: string, index: number) => (
|
|
|
|
|
<p className="flex flex-row gap-1 items-center" key={index}><DotIcon className="text-muted-foreground" /> {item}</p>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "TABLE":
|
|
|
|
|
return (
|
|
|
|
|
<div className="overflow-x-auto">
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
{b.headers.map((header: string, index: number) => (
|
|
|
|
|
<TableHead key={index}>{header}</TableHead>
|
|
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
|
|
|
|
|
<TableBody>
|
|
|
|
|
{b.rows.map((row: string[], rowIndex: number) => (
|
|
|
|
|
<TableRow key={rowIndex}>
|
|
|
|
|
{row.map((cell: string, cellIndex: number) => (
|
|
|
|
|
<TableCell key={cellIndex}>{cell}</TableCell>
|
|
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
))}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case "DIVIDER":
|
|
|
|
|
return <Separator />
|
|
|
|
|
return <Separator />;
|
|
|
|
|
|
|
|
|
|
case "LINK":
|
|
|
|
|
return <Link href={b.href} target="_blank">
|
|
|
|
|
<Button variant="secondary" className="w-max">{b.label}</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -55,37 +142,56 @@ export default async function Page({ params }: { params: Promise<{ type: string;
|
|
|
|
|
|
|
|
|
|
const page = await getPageBySlug(slug);
|
|
|
|
|
if (!page || (!user?.isAdmin && page.status == "ARCHIVED")) notFound();
|
|
|
|
|
|
|
|
|
|
const navlink = await getNavLinkByPageId(page.id);
|
|
|
|
|
|
|
|
|
|
const blocks = page ? await getBlocksByPageId(page.id) : [];
|
|
|
|
|
|
|
|
|
|
const createdBy = await getUser(page?.createdBy);
|
|
|
|
|
const updatedBy = await getUser(page?.updatedBy);
|
|
|
|
|
|
|
|
|
|
const isNews = page.type === "NEWS";
|
|
|
|
|
const isArchived = page.status === "ARCHIVED";
|
|
|
|
|
const wasUpdated = formatDate(page.publishedAt) !== formatDate(page.updatedAt);
|
|
|
|
|
const location = (page.meta as PageMeta)?.location;
|
|
|
|
|
const wasUpdatedByOther = page.updatedBy && page.createdBy !== page.updatedBy;
|
|
|
|
|
|
|
|
|
|
const meta = {
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Header />
|
|
|
|
|
<div className="flex flex-col p-16 gap-16">
|
|
|
|
|
<div className="flex flex-col gap-4 items-center justify-center">
|
|
|
|
|
<div className="flex flex-col p-16 gap-12">
|
|
|
|
|
<div className={cn("flex flex-col gap-4 justify-center", isNews && "items-center")}>
|
|
|
|
|
<div className="flex flex-row items-center gap-6">
|
|
|
|
|
<h1 className="underline underline-offset-8 decoration-2 text-center">{page?.title}</h1>
|
|
|
|
|
<div className="flex flex-row gap-2 items-center">
|
|
|
|
|
<Link href={`/news/${page.slug}/edit`}>
|
|
|
|
|
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
|
|
|
|
|
</Link>
|
|
|
|
|
{page.status != "ARCHIVED" && <ArchiveButton pageId={page.id} />}
|
|
|
|
|
</div>
|
|
|
|
|
<h1 className="underline underline-offset-8 decoration-2">{page?.title}</h1>
|
|
|
|
|
{user?.isAdmin && (
|
|
|
|
|
<div className="flex flex-row gap-2 items-center">
|
|
|
|
|
<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 label={page.title} pageId={page.id} isPinned={!!navlink} />}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-row gap-6 items-center">
|
|
|
|
|
<p className="flex gap-1.5 items-center"><CalendarIcon size={16} />{formatDate(page?.publishedAt)}</p>
|
|
|
|
|
{formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) && <p className="flex gap-2 items-center"><CalendarIcon size={16} />Updated on {formatDate(page?.updatedAt)}</p>}
|
|
|
|
|
{(page?.meta as PageMeta)?.location && <p className="flex gap-1.5 items-center"><Globe2Icon size={16} />{(page?.meta as PageMeta)?.location}</p>}
|
|
|
|
|
{user?.isAdmin && <p className="flex gap-1.5 items-center"><UserIcon size={16} />{`${createdBy?.firstName} ${createdBy?.secondName}`}</p>}
|
|
|
|
|
{user?.isAdmin && page.updatedBy && page.createdBy !== page.updatedBy && <p className="flex gap-2 items-center"><CalendarIcon size={18} />Last update by {updatedBy?.firstName} ${updatedBy?.secondName}</p>}
|
|
|
|
|
{meta.publishedAt && <p className="flex gap-1.5 items-center"><CalendarIcon size={16} />{meta.publishedAt}</p>}
|
|
|
|
|
{meta.updatedAt && <p className="flex gap-1.5 items-center"><CalendarIcon size={16} />Updated on {meta.updatedAt}</p>}
|
|
|
|
|
{meta.location && <p className="flex gap-1.5 items-center"><Globe2Icon size={16} />{meta.location}</p>}
|
|
|
|
|
{meta.author && <p className="flex gap-1.5 items-center"><UserIcon size={16} />{meta.author}</p>}
|
|
|
|
|
{meta.updatedBy && <p className="flex gap-1.5 items-center"><UserIcon size={16} />Last update by {meta.updatedBy}</p>}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-8">
|
|
|
|
|
{page.status == "ARCHIVED" && (
|
|
|
|
|
<Alert>
|
|
|
|
|
<div className="flex flex-col gap-6">
|
|
|
|
|
{isArchived && (
|
|
|
|
|
<Alert className="w-max">
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
<AlertTitle>This page is archived</AlertTitle>
|
|
|
|
|
<AlertDescription>It can be seen only by admins. Make any edits to make it visible again.</AlertDescription>
|
|
|
|
|