"use client" import { updateArtwork } from "@/actions/artworks/updateArtwork"; import { Button } from "@/components/ui/button"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import MultipleSelector from "@/components/ui/multiselect"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import type { Tag } from "@/generated/prisma/client"; import { artworkSchema } from "@/schemas/artworks/imageSchema"; import type { ArtworkWithRelations, CategoryWithTags } from "@/types/Artwork"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import type { z } from "zod/v4"; export default function EditArtworkForm({ artwork, categories, tags }: { artwork: ArtworkWithRelations, categories: CategoryWithTags[] tags: Tag[] }) { const router = useRouter(); const form = useForm>({ resolver: zodResolver(artworkSchema), defaultValues: { name: artwork.name, needsWork: artwork.needsWork ?? true, nsfw: artwork.nsfw ?? false, published: artwork.published ?? false, setAsHeader: artwork.setAsHeader ?? false, altText: artwork.altText || "", description: artwork.description || "", notes: artwork.notes || "", month: artwork.month || undefined, year: artwork.year || undefined, creationDate: artwork.creationDate ? new Date(artwork.creationDate) : undefined, categoryIds: artwork.categories?.map(cat => cat.id) ?? [], tagIds: artwork.tagsV2?.map(tag => tag.id) ?? [], newCategoryNames: [], newTagNames: [] } }) async function onSubmit(values: z.infer) { const updatedArtwork = await updateArtwork(values, artwork.id) if (updatedArtwork) { toast.success("Artwork updated") router.push(`/artworks`) } } return (
{/* String */} ( Image name )} /> ( Alt Text