subman-nextjs/src/app/publication/create/page.tsx

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-06-12 09:00:59 +00:00
import PubForm from "app/ui/forms/pub";
import { getGenres } from "app/lib/get";
2024-06-17 21:23:09 +00:00
import prisma from "app/lib/db";
2024-06-24 16:29:51 +00:00
import { CreateContainer, CreateContainerContent, CreateContainerDescription, CreateContainerHeader } from "app/ui/createContainer";
2024-06-25 09:18:30 +00:00
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
export default async function Page() {
2024-06-17 21:23:09 +00:00
async function createPub(data) {
"use server"
const genresArray = data.genres.map(e => { return { id: e } })
const res = await prisma.pub.create({
data: {
title: data.title,
link: data.link,
query_after_days: data.query_after_days
}
})
console.log(res)
const genresRes = await prisma.pub.update({
where: { id: res.id },
data:
{ genres: { set: genresArray } }
})
console.log(genresRes)
2024-06-25 09:18:30 +00:00
revalidatePath("/publication")
redirect("/publication")
2024-06-17 21:23:09 +00:00
}
const genres = await getGenres()
2024-06-24 16:29:51 +00:00
return (
<CreateContainer>
<CreateContainerHeader>Create Publication</CreateContainerHeader>
<CreateContainerContent>
<CreateContainerDescription>
Create a new entry for a publication i.e. a place you intend to submit to.
</CreateContainerDescription>
2024-06-24 21:15:48 +00:00
<PubForm genres={genres} createPub={createPub} className="mt-6" />
2024-06-24 16:29:51 +00:00
</CreateContainerContent>
</CreateContainer>
)
2024-06-12 09:00:59 +00:00
}