feat: news
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRef, useTransition } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import Editor, { EditorData } from "@/components/editor";
|
||||||
|
import { savePageAction } from "@/lib/pages/actions";
|
||||||
|
import { Block, Page, PageMeta, PageType } from "@/lib/pages/types";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
page: Page | null;
|
||||||
|
pageType: PageType;
|
||||||
|
initialBlocks?: Block[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function EditPageClient({ page, pageType, initialBlocks = [] }: Props) {
|
||||||
|
const router = useRouter();
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
|
||||||
|
const dataRef = useRef<EditorData>({
|
||||||
|
title: page?.title ?? "",
|
||||||
|
type: page?.type ?? "",
|
||||||
|
slug: page?.slug ?? "",
|
||||||
|
location: (page?.meta as PageMeta)?.location ?? "",
|
||||||
|
tags: (page?.meta as PageMeta)?.tags ?? [],
|
||||||
|
blocks: initialBlocks,
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleSave(status: "DRAFT" | "PUBLISHED") {
|
||||||
|
startTransition(async () => {
|
||||||
|
const data = dataRef.current;
|
||||||
|
await savePageAction({
|
||||||
|
id: page?.id ?? null,
|
||||||
|
slug: data.slug || data.title.toLowerCase().replace(/\s+/g, "-"),
|
||||||
|
title: data.title,
|
||||||
|
type: pageType,
|
||||||
|
status,
|
||||||
|
blocks: data.blocks,
|
||||||
|
meta: { location: data.location, tags: data.tags },
|
||||||
|
});
|
||||||
|
const basePath = pageType === "NEWS" ? "news" : "pages";
|
||||||
|
router.push(`/${basePath}/${data.slug}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col p-16 gap-12">
|
||||||
|
<div className="flex flex-row items-center justify-between">
|
||||||
|
<h1 className="underline underline-offset-8 decoration-2">
|
||||||
|
{page ? "Edit page" : "Create page"}
|
||||||
|
</h1>
|
||||||
|
<div className="flex flex-row gap-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={() => handleSave("DRAFT")}
|
||||||
|
>
|
||||||
|
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
|
||||||
|
Save as draft
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={() => handleSave("PUBLISHED")}
|
||||||
|
>
|
||||||
|
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
|
||||||
|
Publish
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Editor
|
||||||
|
page={page}
|
||||||
|
type={pageType}
|
||||||
|
initialBlocks={initialBlocks}
|
||||||
|
onChange={(data) => {
|
||||||
|
dataRef.current = data;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import Header from "@/components/header";
|
||||||
|
import Footer from "@/components/footer";
|
||||||
|
import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository";
|
||||||
|
import { getCurrentUser } from "@/lib/user";
|
||||||
|
import { redirect, notFound } from "next/navigation";
|
||||||
|
import { PAGE_TYPES, PageType } from "@/lib/pages/types";
|
||||||
|
import EditPageClient from "./client";
|
||||||
|
|
||||||
|
export default async function EditPage({ params }: { params: Promise<{ type: string; slug: string }> }) {
|
||||||
|
const user = await getCurrentUser();
|
||||||
|
if (!user?.isAdmin) redirect("/");
|
||||||
|
|
||||||
|
const { type, slug } = await params;
|
||||||
|
|
||||||
|
const pageType = type.toUpperCase() as PageType;
|
||||||
|
if (!PAGE_TYPES.includes(pageType)) notFound();
|
||||||
|
|
||||||
|
const page = await getPageBySlug(slug);
|
||||||
|
const blocks = page ? await getBlocksByPageId(page.id) : [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header />
|
||||||
|
<EditPageClient page={page ?? null} pageType={pageType} initialBlocks={blocks} />
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import Header from "@/components/header";
|
||||||
|
import Footer from "@/components/footer";
|
||||||
|
import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository";
|
||||||
|
import { getCurrentUser } 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 { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
|
||||||
|
function BlockRenderer({ block }: {block: Block }) {
|
||||||
|
const b = block.content
|
||||||
|
switch (b.type) {
|
||||||
|
case "PARAGRAPH":
|
||||||
|
return <h4>{b.text}</h4>
|
||||||
|
case "HEADING":
|
||||||
|
switch (b.level) {
|
||||||
|
case 1:
|
||||||
|
return <h1>{b.text}</h1>
|
||||||
|
case 2:
|
||||||
|
return <h2>{b.text}</h2>
|
||||||
|
case 3:
|
||||||
|
return <h3>{b.text}</h3>
|
||||||
|
}
|
||||||
|
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>
|
||||||
|
case "CALLOUT":
|
||||||
|
return <Alert>
|
||||||
|
<InfoIcon />
|
||||||
|
<AlertTitle>{b.title}</AlertTitle>
|
||||||
|
<AlertDescription>{b.text}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
case "DIVIDER":
|
||||||
|
return <Separator />
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function Page({ params }: { params: Promise<{ type: string; slug: string }> }) {
|
||||||
|
const user = await getCurrentUser();
|
||||||
|
|
||||||
|
const { type, slug } = await params;
|
||||||
|
|
||||||
|
const pageType = type.toUpperCase() as PageType;
|
||||||
|
if (!PAGE_TYPES.includes(pageType)) notFound();
|
||||||
|
|
||||||
|
const page = await getPageBySlug(slug);
|
||||||
|
if (!page) notFound();
|
||||||
|
|
||||||
|
const blocks = page ? await getBlocksByPageId(page.id) : [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header />
|
||||||
|
<div className="flex flex-col p-16 gap-16">
|
||||||
|
<div className="flex flex-col gap-4 items-center justify-center">
|
||||||
|
<h1 className="underline underline-offset-8 decoration-2 text-center">{page?.title}</h1>
|
||||||
|
<div className="flex flex-row gap-4 items-center">
|
||||||
|
<h3 className="flex gap-2 items-baseline"><CalendarIcon size={18} />{formatDate(page?.publishedAt)}</h3>
|
||||||
|
{formatDate(page?.publishedAt) !== formatDate(page?.updatedAt) && <h3 className="flex gap-2 items-baseline"><CalendarIcon size={18} />Updated on {formatDate(page?.updatedAt)}</h3>}
|
||||||
|
{<h3 className="flex gap-2 items-baseline"><Globe2Icon size={18} />{(page?.meta as PageMeta)?.location}</h3>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-8">
|
||||||
|
{blocks.map((block) => (
|
||||||
|
<BlockRenderer key={block.id} block={block} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRef, useTransition } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import Editor, { EditorData } from "@/components/editor";
|
||||||
|
import { savePageAction } from "@/lib/pages/actions";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
|
||||||
|
export default function CreatePageClient() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
const dataRef = useRef<EditorData>({
|
||||||
|
title: "",
|
||||||
|
type: "NEWS",
|
||||||
|
slug: "",
|
||||||
|
location: "",
|
||||||
|
tags: [],
|
||||||
|
blocks: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleSave(status: "DRAFT" | "PUBLISHED") {
|
||||||
|
startTransition(async () => {
|
||||||
|
const data = dataRef.current;
|
||||||
|
await savePageAction({
|
||||||
|
id: null,
|
||||||
|
slug: data.slug || data.title.toLowerCase().replace(/\s+/g, "-"),
|
||||||
|
title: data.title,
|
||||||
|
type: data.type,
|
||||||
|
status,
|
||||||
|
blocks: data.blocks,
|
||||||
|
meta: { location: data.location, tags: data.tags },
|
||||||
|
});
|
||||||
|
router.push("/news");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col p-16 gap-12">
|
||||||
|
<div className="flex flex-row items-center justify-between">
|
||||||
|
<h1 className="underline underline-offset-8 decoration-2">Create page</h1>
|
||||||
|
<div className="flex flex-row gap-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={() => handleSave("DRAFT")}
|
||||||
|
>
|
||||||
|
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
|
||||||
|
Save as draft
|
||||||
|
</Button>
|
||||||
|
<Button disabled={isPending} onClick={() => handleSave("PUBLISHED")}>
|
||||||
|
{isPending && <Loader2 size={14} className="animate-spin mr-1" />}
|
||||||
|
Publish
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Editor onChange={(data) => { dataRef.current = data; }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import Header from "@/components/header";
|
||||||
|
import Footer from "@/components/footer";
|
||||||
|
import { getCurrentUser } from "@/lib/user";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import CreatePageClient from "./client";
|
||||||
|
|
||||||
|
export default async function CreatePage() {
|
||||||
|
const user = await getCurrentUser();
|
||||||
|
if (!user?.isAdmin) redirect("/");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header />
|
||||||
|
<CreatePageClient />
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -142,4 +142,20 @@ h2 {
|
|||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
@apply text-xl tracking-tight
|
@apply text-xl tracking-tight
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
@apply text-lg tracking-tight
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
@apply text-base tracking-tight
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
@apply text-sm tracking-tight
|
||||||
|
}
|
||||||
|
|
||||||
|
h6 {
|
||||||
|
@apply text-xs tracking-tight
|
||||||
}
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import Header from "@/components/header";
|
|
||||||
import Footer from "@/components/footer";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { getPageBySlug } from "@/lib/pages/repository";
|
|
||||||
import { getCurrentUser } from "@/lib/user";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import Editor from "@/components/editor";
|
|
||||||
|
|
||||||
export default async function EditPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
||||||
const user = await getCurrentUser();
|
|
||||||
if (!user?.isAdmin) redirect("/");
|
|
||||||
|
|
||||||
const { slug } = await params;
|
|
||||||
const page = slug === "create" ? null : await getPageBySlug(slug);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Header />
|
|
||||||
<div className="flex flex-col p-16 gap-16">
|
|
||||||
<div className="flex flex-row items-center justify-between">
|
|
||||||
<h1 className="underline underline-offset-8 decoration-2">
|
|
||||||
{page ? "Edit page" : "Create page"}
|
|
||||||
</h1>
|
|
||||||
<div className="flex flex-row gap-4">
|
|
||||||
<Button variant="outline">Save as draft</Button>
|
|
||||||
<Button>Publish</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Editor page={page} />
|
|
||||||
</div>
|
|
||||||
<Footer />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+8
-5
@@ -6,6 +6,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { getPages } from "@/lib/pages/repository";
|
import { getPages } from "@/lib/pages/repository";
|
||||||
import { PageMeta } from "@/lib/pages/types";
|
import { PageMeta } from "@/lib/pages/types";
|
||||||
import { getCurrentUser } from "@/lib/user";
|
import { getCurrentUser } from "@/lib/user";
|
||||||
|
import { formatDate } from "@/lib/utils";
|
||||||
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
@@ -22,19 +23,20 @@ export default async function News() {
|
|||||||
<h1 className="underline underline-offset-8 decoration-2">News</h1>
|
<h1 className="underline underline-offset-8 decoration-2">News</h1>
|
||||||
<div className="flex flex-row items-center gap-4">
|
<div className="flex flex-row items-center gap-4">
|
||||||
<DraftsDialog drafts={drafts} />
|
<DraftsDialog drafts={drafts} />
|
||||||
{user?.isAdmin && (<Link href="/news/create/edit"><Button variant="secondary">Create a news page</Button></Link>)}
|
{user?.isAdmin && (<Link href="/create/"><Button variant="secondary">Create a new page</Button></Link>)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
{
|
{
|
||||||
news.length > 0 ? news.map((n) => (
|
news.length > 0 ? news.map((n) => (
|
||||||
<div className="flex flex-col gap-2" key={n.id}>
|
<div className="flex flex-col gap-2" key={n.id}>
|
||||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2>
|
<Link href={`/news/${n.slug}`}><h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2></Link>
|
||||||
<div className="flex flex-row gap-8 items-center">
|
<div className="flex flex-row gap-8 items-center">
|
||||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{(n.publishedAt)?.toString()}</h3>
|
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{formatDate(n.publishedAt)}</h3>
|
||||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
||||||
<div className="flex flex-row gap-4">
|
<div className="flex flex-row gap-4">
|
||||||
{((n.meta as PageMeta)?.tags)?.map((i, tag) => (
|
{((n.meta as PageMeta)?.tags)?.map((tag) => (
|
||||||
<Badge key={i}>{tag}</Badge>
|
<Badge key={tag}>{tag}</Badge>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -43,6 +45,7 @@ export default async function News() {
|
|||||||
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
||||||
)) : <h2>There are no news yet...</h2>
|
)) : <h2>There are no news yet...</h2>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</>
|
</>
|
||||||
|
|||||||
+19
-16
@@ -3,7 +3,9 @@ import Header from "@/components/header";
|
|||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { getPages } from "@/lib/pages/repository";
|
import { getPages } from "@/lib/pages/repository";
|
||||||
import { PageMeta } from "@/lib/pages/types";
|
import { PageMeta } from "@/lib/pages/types";
|
||||||
|
import { formatDate } from "@/lib/utils";
|
||||||
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
import { ArrowRight, Calendar, Globe2 } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
export default async function Home() {
|
export default async function Home() {
|
||||||
const news = await getPages("NEWS", "PUBLISHED", 5);
|
const news = await getPages("NEWS", "PUBLISHED", 5);
|
||||||
@@ -36,24 +38,25 @@ export default async function Home() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-8 mt-8">
|
<div className="flex flex-col gap-8 mt-8">
|
||||||
<h1 className="underline underline-offset-8 decoration-2">Recent news</h1>
|
<h1 className="underline underline-offset-8 decoration-2">Recent news</h1>
|
||||||
{
|
<div className="flex flex-col gap-6">
|
||||||
news.length > 0 ? news.map((n) => (
|
{
|
||||||
<div className="flex flex-col gap-2" key={n.id}>
|
news.length > 0 ? news.map((n) => (
|
||||||
<h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2>
|
<div className="flex flex-col gap-2" key={n.id}>
|
||||||
<div className="flex flex-row gap-8 items-center">
|
<Link href={`/news/${n.slug}`}><h2 className="w-max hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">{n.title}</h2></Link>
|
||||||
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{(n.publishedAt)?.toString()}</h3>
|
<div className="flex flex-row gap-8 items-center">
|
||||||
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
<h3 className="flex gap-2 items-baseline"><Calendar size={18} />{formatDate(n.publishedAt)}</h3>
|
||||||
<div className="flex flex-row gap-4">
|
<h3 className="flex gap-2 items-baseline"><Globe2 size={18} />{(n.meta as PageMeta)?.location}</h3>
|
||||||
{((n.meta as PageMeta)?.tags)?.map((i, tag) => (
|
<div className="flex flex-row gap-4">
|
||||||
<Badge key={i}>{tag}</Badge>
|
{((n.meta as PageMeta)?.tags)?.map((tag) => (
|
||||||
))}
|
<Badge key={tag}>{tag}</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)) : <h2>There are no news yet...</h2>
|
||||||
), (
|
}
|
||||||
<h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2>
|
</div>
|
||||||
)) : <h2>There are no news yet...</h2>
|
<Link href="/news"><h2 className="w-max flex flex-row items-center gap-2 hover:gap-4 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer">See all news<ArrowRight size={32} /></h2></Link>
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
|
|||||||
<DialogTitle>Drafts</DialogTitle>
|
<DialogTitle>Drafts</DialogTitle>
|
||||||
<DialogDescription>Here are drafts of your pages</DialogDescription>
|
<DialogDescription>Here are drafts of your pages</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="flex flex-col items-center gap-2">
|
|
||||||
{drafts.length > 0 ? (
|
{drafts.length > 0 ? (
|
||||||
drafts.map((draft) => (
|
<div className="flex flex-col items-center gap-2">
|
||||||
|
{drafts.map((draft) => (
|
||||||
<div className="w-full flex flex-row items-center justify-between" key={draft.id}>
|
<div className="w-full flex flex-row items-center justify-between" key={draft.id}>
|
||||||
<h3 className="w-64 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer truncate">
|
<h3 className="w-64 hover:underline underline-offset-8 decoration-2 duration-200 cursor-pointer truncate">
|
||||||
{draft.title}
|
{draft.title}
|
||||||
@@ -57,11 +58,11 @@ export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
))}
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<h3>There are no drafts yet...</h3>
|
<h4>There are no drafts yet...</h4>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
)
|
||||||
|
|||||||
+173
-86
@@ -1,7 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useTransition } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -17,34 +16,50 @@ import {
|
|||||||
InputGroupInput,
|
InputGroupInput,
|
||||||
} from "@/components/ui/input-group";
|
} from "@/components/ui/input-group";
|
||||||
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
|
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
|
||||||
import { savePageAction } from "@/lib/pages/actions";
|
import { Globe2, Plus, Trash2, X } from "lucide-react";
|
||||||
import { Globe2, Loader2, Plus, Trash2, X } from "lucide-react";
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
||||||
|
|
||||||
export default function Editor({ page, type, initialBlocks = [] }: { page: Page | null; type: PageType; initialBlocks?: Block[] }) {
|
export type EditorData = {
|
||||||
|
title: string;
|
||||||
|
type: PageType;
|
||||||
|
slug: string;
|
||||||
|
location: string;
|
||||||
|
tags: string[];
|
||||||
|
blocks: Block[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type EditorProps = {
|
||||||
|
page?: Page | null;
|
||||||
|
type?: PageType;
|
||||||
|
initialBlocks?: Block[];
|
||||||
|
onChange: (data: EditorData) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Editor({
|
||||||
|
page,
|
||||||
|
initialBlocks = [],
|
||||||
|
onChange,
|
||||||
|
}: EditorProps) {
|
||||||
const meta = (page?.meta as PageMeta) ?? {};
|
const meta = (page?.meta as PageMeta) ?? {};
|
||||||
const router = useRouter();
|
|
||||||
const [isPending, startTransition] = useTransition();
|
|
||||||
|
|
||||||
const [title, setTitle] = useState(page?.title ?? "");
|
const [title, setTitle] = useState(page?.title ?? "");
|
||||||
|
const [type, setType] = useState(page?.type ?? "NEWS");
|
||||||
const [slug, setSlug] = useState(page?.slug ?? "");
|
const [slug, setSlug] = useState(page?.slug ?? "");
|
||||||
const [location, setLocation] = useState(meta.location ?? "");
|
const [location, setLocation] = useState(meta.location ?? "");
|
||||||
const [tags, setTags] = useState<string[]>(meta.tags ?? []);
|
const [tags, setTags] = useState<string[]>(meta.tags ?? []);
|
||||||
const [tagInput, setTagInput] = useState("");
|
const [tagInput, setTagInput] = useState("");
|
||||||
const [blocks, setBlocks] = useState<Block[]>(initialBlocks);
|
const [blocks, setBlocks] = useState<Block[]>(initialBlocks);
|
||||||
|
|
||||||
function handleSave(status: "DRAFT" | "PUBLISHED") {
|
useEffect(() => {
|
||||||
startTransition(async () => {
|
onChange({
|
||||||
await savePageAction({
|
title,
|
||||||
id: page?.id ?? null,
|
type,
|
||||||
slug: slug || title.toLowerCase().replace(/\s+/g, "-"),
|
slug: slug || title.toLowerCase().replace(/\s+/g, "-"),
|
||||||
title,
|
location,
|
||||||
type: "NEWS",
|
tags,
|
||||||
status,
|
blocks,
|
||||||
blocks,
|
|
||||||
meta: { location, tags },
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}, [title, slug, location, tags, blocks]);
|
||||||
|
|
||||||
function addTag() {
|
function addTag() {
|
||||||
const trimmed = tagInput.trim();
|
const trimmed = tagInput.trim();
|
||||||
@@ -58,14 +73,17 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addBlock(type: BlockType) {
|
function addBlock(type: BlockType) {
|
||||||
setBlocks([...blocks, {
|
setBlocks([
|
||||||
id: crypto.randomUUID(),
|
...blocks,
|
||||||
pageId: page?.id ?? "",
|
{
|
||||||
parentId: null,
|
id: crypto.randomUUID(),
|
||||||
type,
|
pageId: page?.id ?? "",
|
||||||
position: blocks.length,
|
parentId: null,
|
||||||
content: getDefaultContent(type),
|
type,
|
||||||
}]);
|
position: blocks.length,
|
||||||
|
content: getDefaultContent(type),
|
||||||
|
},
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeBlock(id: string) {
|
function removeBlock(id: string) {
|
||||||
@@ -77,7 +95,7 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-8">
|
<div className="flex flex-col gap-10">
|
||||||
<FieldSet>
|
<FieldSet>
|
||||||
<h2 className="underline underline-offset-8 decoration-2 mb-4">Meta</h2>
|
<h2 className="underline underline-offset-8 decoration-2 mb-4">Meta</h2>
|
||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
@@ -90,13 +108,29 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setTitle(e.target.value);
|
setTitle(e.target.value);
|
||||||
if (!page) {
|
if (!page) {
|
||||||
setSlug(e.target.value.toLowerCase().replace(/\s+/g, "-"));
|
setSlug(
|
||||||
|
e.target.value.toLowerCase().replace(/\s+/g, "-")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
placeholder="Enter the page title"
|
placeholder="Enter page title"
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel htmlFor="type">Page type</FieldLabel>
|
||||||
|
<Select defaultValue={type} onValueChange={(e) => setType(e)}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Type" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectItem value="PAGE">Page</SelectItem>
|
||||||
|
<SelectItem value="NEWS">News</SelectItem>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel htmlFor="slug">Slug</FieldLabel>
|
<FieldLabel htmlFor="slug">Slug</FieldLabel>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
@@ -111,15 +145,15 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
<Field>
|
<Field>
|
||||||
<FieldLabel htmlFor="location">Location</FieldLabel>
|
<FieldLabel htmlFor="location">Location</FieldLabel>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
|
<InputGroupAddon align="inline-start">
|
||||||
|
<Globe2 size={14} className="text-muted-foreground" />
|
||||||
|
</InputGroupAddon>
|
||||||
<InputGroupInput
|
<InputGroupInput
|
||||||
id="location"
|
id="location"
|
||||||
value={location}
|
value={location}
|
||||||
onChange={(e) => setLocation(e.target.value)}
|
onChange={(e) => setLocation(e.target.value)}
|
||||||
placeholder="Liberty City, European Federation"
|
placeholder="Liberty City, European Federation"
|
||||||
/>
|
/>
|
||||||
<InputGroupAddon align="inline-start">
|
|
||||||
<Globe2 size={16} className="text-muted-foreground" />
|
|
||||||
</InputGroupAddon>
|
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</Field>
|
</Field>
|
||||||
<Field>
|
<Field>
|
||||||
@@ -130,22 +164,23 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
value={tagInput}
|
value={tagInput}
|
||||||
onChange={(e) => setTagInput(e.target.value)}
|
onChange={(e) => setTagInput(e.target.value)}
|
||||||
onKeyDown={(e) => e.key === "Enter" && addTag()}
|
onKeyDown={(e) => e.key === "Enter" && addTag()}
|
||||||
placeholder="Add a tag"
|
placeholder="Add a tag and press Enter"
|
||||||
/>
|
/>
|
||||||
<InputGroupAddon align="inline-end">
|
<InputGroupAddon align="inline-end">
|
||||||
<InputGroupButton onClick={addTag}>Add</InputGroupButton>
|
<InputGroupButton onClick={addTag}>Add</InputGroupButton>
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
{tags.length > 0 && (
|
{tags.length > 0 && (
|
||||||
<div className="flex flex-row gap-2 flex-wrap mt-2">
|
<div className="flex flex-row gap-2 flex-wrap mt-3">
|
||||||
{tags.map((tag) => (
|
{tags.map((tag) => (
|
||||||
<Badge
|
<Badge
|
||||||
key={tag}
|
key={tag}
|
||||||
|
variant="secondary"
|
||||||
className="flex gap-1 items-center cursor-pointer"
|
className="flex gap-1 items-center cursor-pointer"
|
||||||
onClick={() => removeTag(tag)}
|
onClick={() => removeTag(tag)}
|
||||||
>
|
>
|
||||||
{tag}
|
{tag}
|
||||||
<X size={12} />
|
<X size={11} />
|
||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -153,11 +188,14 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
</Field>
|
</Field>
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</FieldSet>
|
</FieldSet>
|
||||||
|
|
||||||
<FieldSet>
|
<FieldSet>
|
||||||
<h2 className="underline underline-offset-8 decoration-2 mb-4">Content</h2>
|
<h2 className="underline underline-offset-8 decoration-2 mb-4">Content</h2>
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-3">
|
||||||
{blocks.length === 0 && (
|
{blocks.length === 0 && (
|
||||||
<p className="text-muted-foreground">No blocks yet</p>
|
<p className="text-sm text-muted-foreground">
|
||||||
|
No blocks yet. Add one below.
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
{blocks.map((block) => (
|
{blocks.map((block) => (
|
||||||
<BlockEditor
|
<BlockEditor
|
||||||
@@ -168,113 +206,162 @@ export default function Editor({ page, type, initialBlocks = [] }: { page: Page
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row gap-4 flex-wrap mt-8">
|
<div className="flex flex-row gap-2 flex-wrap mt-6">
|
||||||
{(["PARAGRAPH", "HEADING", "IMAGE", "QUOTE", "CALLOUT", "DIVIDER", "LIST", "TABLE"] as BlockType[]).map((t) => (
|
{(
|
||||||
<Button key={t} variant="outline" onClick={() => addBlock(t)}>
|
[
|
||||||
<Plus size={14} />{t.toLowerCase()}
|
"PARAGRAPH",
|
||||||
|
"HEADING",
|
||||||
|
"IMAGE",
|
||||||
|
"QUOTE",
|
||||||
|
"CALLOUT",
|
||||||
|
"DIVIDER",
|
||||||
|
"LIST",
|
||||||
|
"TABLE",
|
||||||
|
] as BlockType[]
|
||||||
|
).map((t) => (
|
||||||
|
<Button
|
||||||
|
key={t}
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => addBlock(t)}
|
||||||
|
>
|
||||||
|
<Plus size={12} />
|
||||||
|
{t.charAt(0) + t.slice(1).toLowerCase()}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</FieldSet>
|
</FieldSet>
|
||||||
<div className="flex flex-row gap-4">
|
|
||||||
<Button variant="outline" disabled={isPending} onClick={() => handleSave("DRAFT")}>
|
|
||||||
{isPending ? <Loader2 size={14} className="animate-spin" /> : null}
|
|
||||||
Save as draft
|
|
||||||
</Button>
|
|
||||||
<Button disabled={isPending} onClick={() => handleSave("PUBLISHED")}>
|
|
||||||
{isPending ? <Loader2 size={14} className="animate-spin" /> : null}
|
|
||||||
Publish
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlockEditor({ block, onChange, onRemove }: { block: Block; onChange: (content: Block["content"]) => void; onRemove: () => void }) {
|
function BlockEditor({ block, onChange, onRemove }: { block: Block; onChange: (content: Block["content"]) => void; onRemove: () => void }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row gap-4 items-start group">
|
<div className="flex flex-row gap-3 items-start group">
|
||||||
<div className="flex-1 rounded-lg border p-4">
|
<div className="flex-1 rounded-md border bg-background p-4">
|
||||||
<BlockInput block={block} onChange={onChange} />
|
<BlockInput block={block} onChange={onChange} />
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost" size="icon" onClick={onRemove} className="opacity-0 group-hover:opacity-100 duration-200">
|
<Button
|
||||||
<Trash2 size={16} />
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={onRemove}
|
||||||
|
className="opacity-0 group-hover:opacity-100 transition-opacity mt-1 shrink-0"
|
||||||
|
>
|
||||||
|
<Trash2 size={14} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlockInput({ block, onChange }: {
|
function BlockInput({ block, onChange }: { block: Block; onChange: (c: Block["content"]) => void }) {
|
||||||
block: Block;
|
|
||||||
onChange: (c: Block["content"]) => void;
|
|
||||||
}) {
|
|
||||||
switch (block.type) {
|
switch (block.type) {
|
||||||
case "PARAGRAPH":
|
case "PARAGRAPH":
|
||||||
return (
|
return (
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full bg-transparent resize-none outline-none text-sm"
|
className="w-full bg-transparent resize-none outline-none text-sm leading-relaxed"
|
||||||
rows={3}
|
rows={3}
|
||||||
placeholder="Paragraph text..."
|
placeholder="Start writing..."
|
||||||
value={(block.content as any).text ?? ""}
|
value={(block.content as any).text ?? ""}
|
||||||
onChange={(e) => onChange({ type: "PARAGRAPH", text: e.target.value })}
|
onChange={(e) =>
|
||||||
|
onChange({ type: "PARAGRAPH", text: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "HEADING":
|
case "HEADING":
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
className="w-full bg-transparent outline-none text-xl font-semibold tracking-tight"
|
className="w-full bg-transparent outline-none text-lg tracking-tight"
|
||||||
placeholder="Heading..."
|
placeholder="Heading"
|
||||||
value={(block.content as any).text ?? ""}
|
value={(block.content as any).text ?? ""}
|
||||||
onChange={(e) => onChange({ type: "HEADING", text: e.target.value, level: 2 })}
|
onChange={(e) =>
|
||||||
|
onChange({ type: "HEADING", text: e.target.value, level: 2 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case "QUOTE":
|
case "QUOTE":
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-2 border-l-2 pl-4">
|
<div className="flex flex-col gap-2 border-l-2 pl-4">
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full bg-transparent resize-none outline-none text-sm"
|
className="w-full bg-transparent resize-none outline-none text-sm italic leading-relaxed"
|
||||||
rows={2}
|
rows={2}
|
||||||
placeholder="Quote text..."
|
placeholder="Quote text..."
|
||||||
value={(block.content as any).text ?? ""}
|
value={(block.content as any).text ?? ""}
|
||||||
onChange={(e) => onChange({ type: "QUOTE", text: e.target.value, author: (block.content as any).author })}
|
onChange={(e) =>
|
||||||
|
onChange({
|
||||||
|
type: "QUOTE",
|
||||||
|
text: e.target.value,
|
||||||
|
author: (block.content as any).author,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
className="w-full bg-transparent outline-none text-sm text-muted-foreground"
|
className="w-full bg-transparent outline-none text-xs text-muted-foreground"
|
||||||
placeholder="Author..."
|
placeholder="Author"
|
||||||
value={(block.content as any).author ?? ""}
|
value={(block.content as any).author ?? ""}
|
||||||
onChange={(e) => onChange({ type: "QUOTE", text: (block.content as any).text, author: e.target.value })}
|
onChange={(e) =>
|
||||||
|
onChange({
|
||||||
|
type: "QUOTE",
|
||||||
|
text: (block.content as any).text,
|
||||||
|
author: e.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
case "DIVIDER":
|
case "DIVIDER":
|
||||||
return <hr />;
|
return <hr className="border-border" />;
|
||||||
case "CALLOUT":
|
case "CALLOUT":
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row gap-2 items-start bg-muted rounded-lg p-4">
|
<div className="flex flex-row gap-3 items-start rounded-md bg-muted p-3">
|
||||||
<span>⚠️</span>
|
<span className="text-base leading-none mt-0.5">⚠️</span>
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full bg-transparent resize-none outline-none text-sm"
|
className="w-full bg-transparent resize-none outline-none text-sm leading-relaxed"
|
||||||
rows={2}
|
rows={2}
|
||||||
placeholder="Callout text..."
|
placeholder="Callout text..."
|
||||||
value={(block.content as any).text ?? ""}
|
value={(block.content as any).text ?? ""}
|
||||||
onChange={(e) => onChange({ type: "CALLOUT", text: e.target.value })}
|
onChange={(e) =>
|
||||||
|
onChange({ type: "CALLOUT", text: e.target.value })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
case "IMAGE":
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
className="w-full bg-transparent outline-none text-sm text-muted-foreground"
|
||||||
|
placeholder="https://example.com/image.jpg"
|
||||||
|
value={(block.content as any).url ?? ""}
|
||||||
|
onChange={(e) => onChange({ type: "IMAGE", url: e.target.value })}
|
||||||
|
/>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return <p className="text-muted-foreground text-sm">{block.type} — editor coming soon</p>;
|
return (
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
{block.type} — editor coming soon
|
||||||
|
</p>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDefaultContent(type: BlockType): Block["content"] {
|
function getDefaultContent(type: BlockType): Block["content"] {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "PARAGRAPH": return { type: "PARAGRAPH", text: "" };
|
case "PARAGRAPH":
|
||||||
case "HEADING": return { type: "HEADING", text: "", level: 2 };
|
return { type: "PARAGRAPH", text: "" };
|
||||||
case "QUOTE": return { type: "QUOTE", text: "" };
|
case "HEADING":
|
||||||
case "CALLOUT": return { type: "CALLOUT", text: "" };
|
return { type: "HEADING", text: "", level: 2 };
|
||||||
case "DIVIDER": return { type: "DIVIDER" };
|
case "QUOTE":
|
||||||
case "LIST": return { type: "LIST", style: "BULLET", items: [] };
|
return { type: "QUOTE", text: "" };
|
||||||
case "TABLE": return { type: "TABLE", headers: [], rows: [] };
|
case "CALLOUT":
|
||||||
case "IMAGE": return { type: "IMAGE", url: "" };
|
return { type: "CALLOUT", text: "" };
|
||||||
default: return { type: "PARAGRAPH", text: "" };
|
case "DIVIDER":
|
||||||
|
return { type: "DIVIDER" };
|
||||||
|
case "LIST":
|
||||||
|
return { type: "LIST", style: "BULLET", items: [] };
|
||||||
|
case "TABLE":
|
||||||
|
return { type: "TABLE", headers: [], rows: [] };
|
||||||
|
case "IMAGE":
|
||||||
|
return { type: "IMAGE", url: "" };
|
||||||
|
default:
|
||||||
|
return { type: "PARAGRAPH", text: "" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import { Button } from "./ui/button";
|
|||||||
import login from "@/app/actions/login";
|
import login from "@/app/actions/login";
|
||||||
import { getCurrentUser } from "@/lib/user";
|
import { getCurrentUser } from "@/lib/user";
|
||||||
import logout from "@/app/actions/logout";
|
import logout from "@/app/actions/logout";
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
export default async function Header() {
|
export default async function Header() {
|
||||||
const user = await getCurrentUser();
|
const user = await getCurrentUser();
|
||||||
@@ -10,7 +11,7 @@ export default async function Header() {
|
|||||||
return (
|
return (
|
||||||
<header className="relative flex items-center justify-between w-full h-16 px-8 bg-gray-100">
|
<header className="relative flex items-center justify-between w-full h-16 px-8 bg-gray-100">
|
||||||
<div />
|
<div />
|
||||||
<div className="absolute left-1/2 -translate-x-1/2 flex items-center gap-4">
|
<Link href="/" className="absolute left-1/2 -translate-x-1/2 flex items-center gap-4">
|
||||||
<Image
|
<Image
|
||||||
src="/emblem.png"
|
src="/emblem.png"
|
||||||
width={28}
|
width={28}
|
||||||
@@ -18,7 +19,7 @@ export default async function Header() {
|
|||||||
alt="Emblem of the European Federation"
|
alt="Emblem of the European Federation"
|
||||||
/>
|
/>
|
||||||
<h3>European Federation</h3>
|
<h3>European Federation</h3>
|
||||||
</div>
|
</Link>
|
||||||
{
|
{
|
||||||
user ? (
|
user ? (
|
||||||
<form action={logout}>
|
<form action={logout}>
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const alertVariants = cva(
|
||||||
|
"group/alert relative grid w-full gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-card text-card-foreground",
|
||||||
|
destructive:
|
||||||
|
"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function Alert({
|
||||||
|
className,
|
||||||
|
variant,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert"
|
||||||
|
role="alert"
|
||||||
|
className={cn(alertVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert-title"
|
||||||
|
className={cn(
|
||||||
|
"font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert-description"
|
||||||
|
className={cn(
|
||||||
|
"text-sm text-balance text-muted-foreground md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="alert-action"
|
||||||
|
className={cn("absolute top-2 right-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Alert, AlertTitle, AlertDescription, AlertAction }
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||||
|
import { Select as SelectPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Select({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectGroup({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Group
|
||||||
|
data-slot="select-group"
|
||||||
|
className={cn("scroll-my-1 p-1", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectValue({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectTrigger({
|
||||||
|
className,
|
||||||
|
size = "default",
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||||
|
size?: "sm" | "default"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
data-slot="select-trigger"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
position = "item-aligned",
|
||||||
|
align = "center",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
data-slot="select-content"
|
||||||
|
data-align-trigger={position === "item-aligned"}
|
||||||
|
className={cn("relative z-50 max-h-(--radix-select-content-available-height) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", position ==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className )}
|
||||||
|
position={position}
|
||||||
|
align={align}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
data-position={position}
|
||||||
|
className={cn(
|
||||||
|
"data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)",
|
||||||
|
position === "popper" && ""
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
data-slot="select-label"
|
||||||
|
className={cn("px-1.5 py-1 text-xs text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
data-slot="select-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center">
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="pointer-events-none" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
data-slot="select-separator"
|
||||||
|
className={cn("pointer-events-none -mx-1 my-1 h-px bg-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollUpButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
data-slot="select-scroll-up-button"
|
||||||
|
className={cn(
|
||||||
|
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUpIcon />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollDownButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
data-slot="select-scroll-down-button"
|
||||||
|
className={cn(
|
||||||
|
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="table-container"
|
||||||
|
className="relative w-full overflow-x-auto"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
data-slot="table"
|
||||||
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||||
|
return (
|
||||||
|
<thead
|
||||||
|
data-slot="table-header"
|
||||||
|
className={cn("[&_tr]:border-b", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||||
|
return (
|
||||||
|
<tbody
|
||||||
|
data-slot="table-body"
|
||||||
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||||
|
return (
|
||||||
|
<tfoot
|
||||||
|
data-slot="table-footer"
|
||||||
|
className={cn(
|
||||||
|
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
data-slot="table-row"
|
||||||
|
className={cn(
|
||||||
|
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
data-slot="table-head"
|
||||||
|
className={cn(
|
||||||
|
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
data-slot="table-cell"
|
||||||
|
className={cn(
|
||||||
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableCaption({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"caption">) {
|
||||||
|
return (
|
||||||
|
<caption
|
||||||
|
data-slot="table-caption"
|
||||||
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableBody,
|
||||||
|
TableFooter,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
TableCaption,
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ export async function savePageAction(params: {
|
|||||||
meta?: PageMeta
|
meta?: PageMeta
|
||||||
}) {
|
}) {
|
||||||
if (params.id) {
|
if (params.id) {
|
||||||
await updatePage(params.id, params.title, params.status, params.blocks, params.meta);
|
await updatePage(params.id, params.title, params.type, params.status, params.blocks, params.meta);
|
||||||
revalidatePath(`/${params.slug}`);
|
revalidatePath(`/${params.slug}`);
|
||||||
revalidatePath("/news");
|
revalidatePath("/news");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+3
-8
@@ -1,4 +1,4 @@
|
|||||||
export const PAGE_TYPES = ["NEWS"] as const;
|
export const PAGE_TYPES = ["NEWS", "PAGE"] as const;
|
||||||
export type PageType = typeof PAGE_TYPES[number];
|
export type PageType = typeof PAGE_TYPES[number];
|
||||||
|
|
||||||
export const PAGE_STATUSES = ["DRAFT", "PUBLISHED", "ARCHIVED"] as const;
|
export const PAGE_STATUSES = ["DRAFT", "PUBLISHED", "ARCHIVED"] as const;
|
||||||
@@ -22,20 +22,15 @@ export type Page = {
|
|||||||
createdBy: string;
|
createdBy: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BLOCK_TYPES = ["PARAGRAPH", "HEADING", "IMAGE", "FILE", "QUOTE", "DIVIDER", "TABLE", "CALLOUT", "LIST", "LINK"] as const;
|
export const BLOCK_TYPES = ["PARAGRAPH", "HEADING", "QUOTE", "DIVIDER", "CALLOUT"] as const;
|
||||||
export type BlockType = typeof BLOCK_TYPES[number];
|
export type BlockType = typeof BLOCK_TYPES[number];
|
||||||
|
|
||||||
export type BlockContent =
|
export type BlockContent =
|
||||||
| { type: "PARAGRAPH"; text: string }
|
| { type: "PARAGRAPH"; text: string }
|
||||||
| { type: "HEADING"; text: string; level: 1 | 2 | 3 }
|
| { type: "HEADING"; text: string; level: 1 | 2 | 3 }
|
||||||
| { type: "IMAGE"; url: string; caption?: string }
|
|
||||||
| { type: "FILE"; url: string; name: string }
|
|
||||||
| { type: "QUOTE"; text: string; author?: string }
|
| { type: "QUOTE"; text: string; author?: string }
|
||||||
| { type: "DIVIDER" }
|
| { type: "DIVIDER" }
|
||||||
| { type: "TABLE"; headers: string[]; rows: string[][] }
|
| { type: "CALLOUT"; title: string; text: string }
|
||||||
| { type: "CALLOUT"; text: string; icon?: string; color?: string }
|
|
||||||
| { type: "LIST"; style: "BULLET" | "NUMBERED"; items: string[] }
|
|
||||||
| { type: "LINK"; text?: string; url: string };
|
|
||||||
|
|
||||||
export type Block = {
|
export type Block = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -3,4 +3,13 @@ import { twMerge } from "tailwind-merge"
|
|||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(date: Date | string | null | undefined): string {
|
||||||
|
if (!date) return "";
|
||||||
|
return new Intl.DateTimeFormat("en-GB", {
|
||||||
|
day: "numeric",
|
||||||
|
month: "long",
|
||||||
|
year: "numeric",
|
||||||
|
}).format(new Date(date));
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
- PageVersion { id, pageId, title, blocks (Json snapshot), createdAt, createdBy }
|
- PageVersion { id, pageId, title, blocks (Json snapshot), createdAt, createdBy }
|
||||||
|
|
||||||
TypeScript типы:
|
TypeScript типы:
|
||||||
- PageType = "NEWS" | "LAW" | "DEPARTMENT" | "FAQ" | "STATIC"
|
- PageType = "NEWS"
|
||||||
- PageStatus = "DRAFT" | "PUBLISHED" | "ARCHIVED"
|
- PageStatus = "DRAFT" | "PUBLISHED" | "ARCHIVED"
|
||||||
- BlockContent = discriminated union по type
|
- BlockContent = discriminated union по type
|
||||||
- PageMeta = { description?, ogImage?, location?, tags?, coverUrl?, lawNumber?, signedAt? }
|
- PageMeta = { description?, ogImage?, location?, tags?, coverUrl?, lawNumber?, signedAt? }
|
||||||
|
|||||||
Reference in New Issue
Block a user