feat: improved news
This commit is contained in:
+18
-7
@@ -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}`);
|
||||
}
|
||||
Reference in New Issue
Block a user