40 lines
1.3 KiB
TypeScript
40 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";
|
|
import { deleteNavLinkByPageId } from "../navlinks/repository";
|
|
|
|
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.type, params.status, params.blocks, params.meta);
|
|
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(`/${params.type.toLowerCase()}`);
|
|
redirect(`/${params.type.toLowerCase()}/${page.slug}`);
|
|
}
|
|
}
|
|
|
|
export async function archivePageAction(id: string, slug: string, type: PageType) {
|
|
await archivePage(id);
|
|
await deleteNavLinkByPageId(id);
|
|
revalidatePath(`/${type.toLowerCase()}/${slug}`);
|
|
revalidatePath(`/${type.toLowerCase()}`);
|
|
}
|
|
|
|
export async function deletePageAction(id: string, type: PageType) {
|
|
await deletePage(id);
|
|
revalidatePath(`/${type.toLowerCase()}`);
|
|
} |