"use client" import { updateImage } from "@/actions/portfolio/images/updateImage"; import { Button } from "@/components/ui/button"; import { Calendar } from "@/components/ui/calendar"; 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 { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { Color, ImageColor, ImageMetadata, ImageVariant, PortfolioCategory, PortfolioImage, PortfolioTag, PortfolioType } from "@/generated/prisma"; import { cn } from "@/lib/utils"; import { imageSchema } from "@/schemas/portfolio/imageSchema"; import { zodResolver } from "@hookform/resolvers/zod"; import { format } from "date-fns"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod/v4"; type ImageWithItems = PortfolioImage & { metadata: ImageMetadata | null, colors: ( ImageColor & { color: Color } )[], variants: ImageVariant[], categories: PortfolioCategory[], tags: PortfolioTag[], type: PortfolioType | null, }; export default function EditImageForm({ image, categories, tags, types }: { image: ImageWithItems, categories: PortfolioCategory[] tags: PortfolioTag[], types: PortfolioType[] }) { const router = useRouter(); const form = useForm>({ resolver: zodResolver(imageSchema), defaultValues: { fileKey: image.fileKey, originalFile: image.originalFile, nsfw: image.nsfw ?? false, published: image.nsfw ?? false, setAsHeader: image.setAsHeader ?? false, name: image.name, altText: image.altText || "", description: image.description || "", fileType: image.fileType || "", layoutGroup: image.layoutGroup || "", fileSize: image.fileSize || undefined, layoutOrder: image.layoutOrder || undefined, month: image.month || undefined, year: image.year || undefined, creationDate: image.creationDate ? new Date(image.creationDate) : undefined, typeId: image.typeId ?? undefined, tagIds: image.tags?.map(tag => tag.id) ?? [], categoryIds: image.categories?.map(cat => cat.id) ?? [], } }) async function onSubmit(values: z.infer) { const updatedImage = await updateImage(values, image.id) if (updatedImage) { toast.success("Image updated") router.push(`/portfolio`) } } return (
{/* String */} ( Image name )} /> ( Alt Text )} /> ( Description