diff --git a/app/[type]/[slug]/archiveButton.tsx b/app/[type]/[slug]/archiveButton.tsx new file mode 100644 index 0000000..6e53c92 --- /dev/null +++ b/app/[type]/[slug]/archiveButton.tsx @@ -0,0 +1,22 @@ +"use client"; + +import { useTransition } from "react"; +import { Button } from "@/components/ui/button"; +import { ArchiveIcon } from "lucide-react"; +import { Spinner } from "@/components/ui/spinner"; +import { archivePageAction } from "@/lib/pages/actions"; + +export function ArchiveButton({ pageId }: { pageId: string }) { + const [isPending, startTransition] = useTransition(); + + return ( + + ); +} \ No newline at end of file diff --git a/app/[type]/[slug]/edit/client.tsx b/app/[type]/[slug]/edit/client.tsx index 3fca849..8ed41ac 100644 --- a/app/[type]/[slug]/edit/client.tsx +++ b/app/[type]/[slug]/edit/client.tsx @@ -47,24 +47,14 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P return (
-

- {page ? "Edit page" : "Create page"} -

+

Edit page

-
diff --git a/app/[type]/[slug]/page.tsx b/app/[type]/[slug]/page.tsx index 9578dc4..a3d4481 100644 --- a/app/[type]/[slug]/page.tsx +++ b/app/[type]/[slug]/page.tsx @@ -1,13 +1,17 @@ import Header from "@/components/header"; import Footer from "@/components/footer"; import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository"; -import { getCurrentUser } from "@/lib/user"; +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 { CalendarIcon, Globe2Icon, InfoIcon } from "lucide-react"; +import { ArchiveIcon, CalendarIcon, 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"; function BlockRenderer({ block }: {block: Block }) { const b = block.content @@ -50,23 +54,43 @@ export default async function Page({ params }: { params: Promise<{ type: string; if (!PAGE_TYPES.includes(pageType)) notFound(); const page = await getPageBySlug(slug); - if (!page) notFound(); + if (!page || (!user?.isAdmin && page.status == "ARCHIVED")) notFound(); const blocks = page ? await getBlocksByPageId(page.id) : []; + + const createdBy = await getUser(page?.createdBy); + const updatedBy = await getUser(page?.updatedBy); return ( <>
-

{page?.title}

-
-

{formatDate(page?.publishedAt)}

- {formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) &&

Updated on {formatDate(page?.updatedAt)}

} - {

{(page?.meta as PageMeta)?.location}

} +
+

{page?.title}

+
+ + + + {page.status != "ARCHIVED" && } +
+
+
+

{formatDate(page?.publishedAt)}

+ {formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) &&

Updated on {formatDate(page?.updatedAt)}

} + {(page?.meta as PageMeta)?.location &&

{(page?.meta as PageMeta)?.location}

} + {user?.isAdmin &&

{`${createdBy?.firstName} ${createdBy?.secondName}`}

} + {user?.isAdmin && page.updatedBy && page.createdBy !== page.updatedBy &&

Last update by {updatedBy?.firstName} ${updatedBy?.secondName}

}
+ {page.status == "ARCHIVED" && ( + + + This page is archived + It can be seen only by admins. Make any edits to make it visible again. + + )} {blocks.map((block) => ( ))} diff --git a/app/news/page.tsx b/app/news/page.tsx index ab29821..25266db 100644 --- a/app/news/page.tsx +++ b/app/news/page.tsx @@ -1,13 +1,10 @@ import DraftsDialog from "@/components/drafts"; import Footer from "@/components/footer"; import Header from "@/components/header"; -import { Badge } from "@/components/ui/badge" +import { NewsCard } from "@/components/newsCard"; import { Button } from "@/components/ui/button"; import { getPages } from "@/lib/pages/repository"; -import { PageMeta } from "@/lib/pages/types"; import { getCurrentUser } from "@/lib/user"; -import { formatDate } from "@/lib/utils"; -import { ArrowRight, Calendar, Globe2 } from "lucide-react"; import Link from "next/link"; export default async function News() { @@ -22,28 +19,19 @@ export default async function News() {

News

- - {user?.isAdmin && ()} + {user?.isAdmin && ( +
+ + +
+ )}
{ news.length > 0 ? news.map((n) => ( -
-

{n.title}

-
-

{formatDate(n.publishedAt)}

-

{(n.meta as PageMeta)?.location}

-
- {((n.meta as PageMeta)?.tags)?.map((tag) => ( - {tag} - ))} -
-
-
- ), ( -

See all news

- )) :

There are no news yet...

+ + )) :

There are no news yet...

}
diff --git a/app/page.tsx b/app/page.tsx index 0035114..ca1eb44 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,10 +1,11 @@ import Footer from "@/components/footer"; import Header from "@/components/header"; +import { NewsCard } from "@/components/newsCard"; import { Badge } from "@/components/ui/badge" import { getPages } from "@/lib/pages/repository"; import { PageMeta } from "@/lib/pages/types"; import { formatDate } from "@/lib/utils"; -import { ArrowRight, Calendar, Globe2 } from "lucide-react"; +import { ArrowRightIcon, CalendarIcon, Globe2Icon } from "lucide-react"; import Link from "next/link"; export default async function Home() { @@ -17,7 +18,7 @@ export default async function Home() {

Welcome to the European Federation!

-

Become a citizen

+

Become a citizen

@@ -41,22 +42,11 @@ export default async function Home() {
{ news.length > 0 ? news.map((n) => ( -
-

{n.title}

-
-

{formatDate(n.publishedAt)}

-

{(n.meta as PageMeta)?.location}

-
- {((n.meta as PageMeta)?.tags)?.map((tag) => ( - {tag} - ))} -
-
-
- )) :

There are no news yet...

+ + )) :

There are no news yet...

}
-

See all news

+

See all news