42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
"use server";
|
|
|
|
import { redirect } from "next/navigation";
|
|
import { Block, PageMeta, PageStatus, PageType } from "./types";
|
|
import { archivePage, 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
|
|
}) {
|
|
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}`);
|
|
} else {
|
|
const page = await createPage(params.slug, params.title, params.type, params.status, params.blocks, params.meta);
|
|
revalidatePath(`/${basePath}`);
|
|
redirect(`/${basePath}/${page.slug}/edit`);
|
|
}
|
|
}
|
|
|
|
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);
|
|
const basePath = type === "NEWS" ? "news" : "pages";
|
|
revalidatePath(`/${basePath}`);
|
|
} |