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

26 lines
667 B
TypeScript
Raw Normal View History

import { getGenres } from "app/lib/get";
2024-06-11 17:14:30 +00:00
import StoryForm from "app/ui/forms/story";
2024-06-17 11:12:55 +00:00
import prisma from "app/lib/db";
export default async function Page() {
const genres = await getGenres()
2024-06-17 11:12:55 +00:00
async function createStory(data) {
"use server"
const genresArray = data.genres.map(e => { return { id: e } })
const res = await prisma.story.create({
data: {
title: data.title,
word_count: data.word_count,
}
})
console.log(res)
const genresRes = await prisma.story.update({
where: { id: res.id },
data: {
genres: { set: genresArray }
}
})
console.log(genresRes)
}
return <StoryForm genres={genres} createStory={createStory} />
2024-06-11 17:14:30 +00:00
}