Compare commits
3 Commits
dc9b72f0e8
...
8822a5449c
Author | SHA1 | Date |
---|---|---|
|
8822a5449c | |
|
6862f4114a | |
|
d7ee4a4a8b |
|
@ -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 }) {
|
||||||
|
|
|
@ -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"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue