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()}`);
|
||||
}
|
||||
Reference in New Issue
Block a user