feat: improved news

This commit is contained in:
Ivan Rezchikov
2026-06-21 13:35:32 +03:00
parent 95fd6ae716
commit 48656b562a
13 changed files with 154 additions and 147 deletions
+18 -7
View File
@@ -2,7 +2,7 @@
import { redirect } from "next/navigation";
import { Block, PageMeta, PageStatus, PageType } from "./types";
import { createPage, deletePage, updatePage } from "./repository";
import { archivePage, createPage, deletePage, updatePage } from "./repository";
import { revalidatePath } from "next/cache";
export async function savePageAction(params: {
@@ -14,18 +14,29 @@ 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(`/${params.slug}`);
revalidatePath("/news");
revalidatePath(`/${basePath}/${params.slug}`);
revalidatePath(`/${basePath}`);
} else {
const page = await createPage(params.slug, params.title, params.type, params.status, params.blocks, params.meta);
revalidatePath("/news");
redirect(`/news/${page.slug}/edit`);
revalidatePath(`/${basePath}`);
redirect(`/${basePath}/${page.slug}/edit`);
}
}
export async function deletePageAction(id: string) {
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}`);
}
export async function deletePageAction(id: string, type: PageType) {
await deletePage(id);
revalidatePath("/news");
const basePath = type === "NEWS" ? "news" : "pages";
revalidatePath(`/${basePath}`);
}