Files
eu/lib/navlinks/actions.ts
T
2026-07-11 21:20:57 +03:00

25 lines
767 B
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { addNavLink, deleteNavLinkByPageId } from "./repository";
import { prisma } from "../prisma";
import { requireAdmin } from "../user/require";
import { runAction } from "../run-action";
import type { ActionResult } from "../action-result";
export async function togglePinAction(pageId: string, isPinned: boolean): Promise<ActionResult> {
return runAction(async () => {
await requireAdmin();
if (isPinned) {
await deleteNavLinkByPageId(pageId);
} else {
const page = await prisma.page.findUnique({ where: { id: pageId } });
if (!page) throw new Error(`Page not found: ${pageId}`);
await addNavLink({ pageId });
}
revalidatePath("/", "layout");
});
}