mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
add functionality to pin page && refactoring
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { z } from "zod";
|
||||
import prisma from "../../prisma/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { error } from "console";
|
||||
|
||||
export async function createCustomPage(prevState: any, fromData: FormData) {
|
||||
const schema = z.object({
|
||||
@@ -146,4 +147,42 @@ export async function deletePage(prevState: any, fromData: FormData) {
|
||||
message: "Page deleted",
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export async function pinPageToRoot(prevState: any, fromData: FormData) {
|
||||
const schema = z.object({
|
||||
uuid: z.string().uuid()
|
||||
});
|
||||
|
||||
const data = schema.safeParse({
|
||||
uuid: fromData.get("uuid")
|
||||
});
|
||||
|
||||
if (!data.success) {
|
||||
return {
|
||||
message: "Invalid data",
|
||||
error: data.error.flatten().fieldErrors,
|
||||
};
|
||||
}
|
||||
|
||||
await prisma.pinnedPage.upsert({
|
||||
where: {
|
||||
id: 1
|
||||
},
|
||||
update: {
|
||||
pageUuid: data.data.uuid
|
||||
},
|
||||
create: {
|
||||
id: 1,
|
||||
pageUuid: data.data.uuid
|
||||
}
|
||||
});
|
||||
|
||||
revalidatePath("/dash");
|
||||
revalidatePath("/");
|
||||
|
||||
return {
|
||||
message: "Page pinned",
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user