fix: show genres in edit story dialog

This commit is contained in:
andrzej 2024-09-27 11:05:29 +02:00
parent 6e501aa75f
commit a4f5467832
1 changed files with 3 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import { randomStoryTitle } from "app/lib/shortStoryTitleGenerator"
import GenrePicker from "./genrePicker" import GenrePicker from "./genrePicker"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { Ban, Cross } from "lucide-react" import { Ban, Cross } from "lucide-react"
import { StoryWithGenres } from "app/story/page"
export const formSchema = z.object({ export const formSchema = z.object({
id: z.number().optional(), id: z.number().optional(),
@ -29,13 +30,13 @@ export const formSchema = z.object({
genres: z.array(z.number()) genres: z.array(z.number())
}) })
export default function StoryForm({ genres, dbAction, className, closeDialog, defaults }: ComponentProps<"div"> & { genres: Array<Genre>, dbAction: (data: any) => Promise<{ success: string }>, className: string, closeDialog: () => void, defaults?: Story }) { export default function StoryForm({ genres, dbAction, className, closeDialog, defaults }: ComponentProps<"div"> & { genres: Array<Genre>, dbAction: (data: any) => Promise<{ success: string }>, className: string, closeDialog: () => void, defaults?: StoryWithGenres }) {
const form = useForm<z.infer<typeof formSchema>>({ const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema), resolver: zodResolver(formSchema),
defaultValues: { defaultValues: {
title: defaults?.title ?? "", title: defaults?.title ?? "",
word_count: defaults?.word_count ?? 500, word_count: defaults?.word_count ?? 500,
genres: [] genres: defaults?.genres.map(e => e.id) ?? []
}, },
}) })
console.log("DEFAULTS: " + defaults) console.log("DEFAULTS: " + defaults)