feat: basic pages system
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"use server";
|
||||
|
||||
import { redirect } from "next/navigation";
|
||||
import { Block, PageMeta, PageStatus, PageType } from "./types";
|
||||
import { createPage, deletePage, updatePage } from "./repository";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function savePageAction(params: {
|
||||
id: string | null,
|
||||
slug: string,
|
||||
title: string,
|
||||
type: PageType,
|
||||
status: PageStatus,
|
||||
blocks: Block[],
|
||||
meta?: PageMeta
|
||||
}) {
|
||||
if (params.id) {
|
||||
await updatePage(params.id, params.title, params.status, params.blocks, params.meta);
|
||||
revalidatePath(`/${params.slug}`);
|
||||
revalidatePath("/news");
|
||||
} else {
|
||||
const page = await createPage(params.slug, params.title, params.type, params.status, params.blocks, params.meta);
|
||||
revalidatePath("/news");
|
||||
redirect(`/news/${page.slug}/edit`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePageAction(id: string) {
|
||||
await deletePage(id);
|
||||
revalidatePath("/news");
|
||||
}
|
||||
Reference in New Issue
Block a user