feat: pages
This commit is contained in:
+9
-11
@@ -4,6 +4,7 @@ import { redirect } from "next/navigation";
|
||||
import { Block, PageMeta, PageStatus, PageType } from "./types";
|
||||
import { archivePage, createPage, deletePage, updatePage } from "./repository";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { deleteNavLinkByPageId } from "../navlinks/repository";
|
||||
|
||||
export async function savePageAction(params: {
|
||||
id: string | null,
|
||||
@@ -14,29 +15,26 @@ export async function savePageAction(params: {
|
||||
blocks: Block[],
|
||||
meta?: PageMeta
|
||||
}) {
|
||||
const basePath = params.type === "NEWS" ? "news" : "pages";
|
||||
|
||||
if (params.id) {
|
||||
await updatePage(params.id, params.title, params.type, params.status, params.blocks, params.meta);
|
||||
revalidatePath(`/${basePath}/${params.slug}`);
|
||||
revalidatePath(`/${basePath}`);
|
||||
revalidatePath(`/${params.type.toLowerCase()}/${params.slug}`);
|
||||
revalidatePath(`/${params.type.toLowerCase()}`);
|
||||
} else {
|
||||
const page = await createPage(params.slug, params.title, params.type, params.status, params.blocks, params.meta);
|
||||
revalidatePath(`/${basePath}`);
|
||||
redirect(`/${basePath}/${page.slug}/edit`);
|
||||
revalidatePath(`/${params.type.toLowerCase()}`);
|
||||
redirect(`/${params.type.toLowerCase()}/${page.slug}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function archivePageAction(id: string, slug: string, type: PageType) {
|
||||
await archivePage(id);
|
||||
const basePath = type === "NEWS" ? "news" : "pages";
|
||||
revalidatePath(`/${basePath}/${slug}`);
|
||||
revalidatePath(`/${basePath}`);
|
||||
redirect(`/${basePath}`);
|
||||
await deleteNavLinkByPageId(id);
|
||||
revalidatePath(`/${type.toLowerCase()}/${slug}`);
|
||||
revalidatePath(`/${type.toLowerCase()}`);
|
||||
}
|
||||
|
||||
export async function deletePageAction(id: string, type: PageType) {
|
||||
await deletePage(id);
|
||||
const basePath = type === "NEWS" ? "news" : "pages";
|
||||
revalidatePath(`/${basePath}`);
|
||||
revalidatePath(`/${type.toLowerCase()}`);
|
||||
}
|
||||
+7
-2
@@ -17,12 +17,13 @@ export type Page = {
|
||||
status: PageStatus;
|
||||
meta: PageMeta;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
updatedAt: Date | null;
|
||||
publishedAt: Date | null;
|
||||
createdBy: string;
|
||||
updatedBy: string | null;
|
||||
}
|
||||
|
||||
export const BLOCK_TYPES = ["PARAGRAPH", "HEADING", "QUOTE", "DIVIDER", "CALLOUT"] as const;
|
||||
export const BLOCK_TYPES = ["PARAGRAPH", "HEADING", "QUOTE", "DIVIDER", "CALLOUT", "IMAGE", "LIST", "TABLE", "LINK"] as const;
|
||||
export type BlockType = typeof BLOCK_TYPES[number];
|
||||
|
||||
export type BlockContent =
|
||||
@@ -31,6 +32,10 @@ export type BlockContent =
|
||||
| { type: "QUOTE"; text: string; author?: string }
|
||||
| { type: "DIVIDER" }
|
||||
| { type: "CALLOUT"; title: string; text: string }
|
||||
| { type: "IMAGE"; url: string; caption?: string }
|
||||
| { type: "LIST"; style: "BULLET" | "ORDERED"; items: string[] }
|
||||
| { type: "TABLE"; headers: string[]; rows: string[][] }
|
||||
| { type: "LINK"; label: string; href: string }
|
||||
|
||||
export type Block = {
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user