Compare commits

..

3 Commits

Author SHA1 Message Date
andrzej 8822a5449c style story form 2024-09-27 11:18:12 +02:00
andrzej 6862f4114a style genre picker 2024-09-27 11:11:03 +02:00
andrzej d7ee4a4a8b fix: show genres in edit story dialog 2024-09-27 11:05:29 +02:00
3 changed files with 4 additions and 4 deletions

View File

@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button";
import { ComponentProps, useState } from "react"; import { ComponentProps, useState } from "react";
import { Genre, Story } from "@prisma/client"; import { Genre, Story } from "@prisma/client";
import StoryForm from "app/ui/forms/story"; import StoryForm from "app/ui/forms/story";
import { Plus } from "lucide-react";
export default function EditStoryDialog({ genres, closeDialog, defaults }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: Story }) { export default function EditStoryDialog({ genres, closeDialog, defaults }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: Story }) {

View File

@ -21,7 +21,7 @@ export default function GenrePicker({ genres, form }: ComponentProps<"div"> & {
<Button <Button
variant={"outline"} variant={"outline"}
className={cn( className={cn(
"min-w-fit max-w-full w-fit pl-3 text-left font-normal flex-wrap gap-y-1 h-fit min-h-10", "min-w-fit max-w-60 pl-3 text-left font-normal flex-wrap gap-y-1 h-fit min-h-10",
!field.value && "text-muted-foreground" !field.value && "text-muted-foreground"
)} )}
> >

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)