"use client" import { z } from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { Button } from "@/components/ui/button" import { toast } from "@/components/ui/use-toast" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Calendar } from "@/components/ui/calendar" import { CalendarIcon } from "@radix-ui/react-icons" import { cn } from "@/lib/utils" import { format } from "date-fns" import { Form, FormItem, FormLabel, FormField, FormControl, FormDescription, FormMessage } from "@/components/ui/form" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { useState } from "react" import { createSub } from "app/lib/create" import { subSchema } from "./schemas" import { updateSub } from "app/lib/update" export type SubForm = z.infer export default function EditSubmissionForm({ stories, pubs, responses, defaults }) { const form = useForm>({ resolver: zodResolver(subSchema), defaultValues: { responseId: responses[0].id, ...defaults } }) const [isSubCalendarOpen, setIsSubCalendarOpen] = useState(false); const [isRespCalendarOpen, setIsRespCalendarOpen] = useState(false); const storiesSelectItems = stories.map(e => ( {e.title} )) const pubsSelectItems = pubs.map(e => ( {e.title} )) const reponsesSelectItems = responses.map(e => ( {e.response} )) // 2. Define a submit handler. async function onSubmit(values: z.infer) { try { const res = await updateSub(values) if (res === undefined) throw new Error("something went wrong") toast({ title: "Successfully created new submission!" }) window.location.reload() } catch (error) { toast({ title: "UH-OH", description: error.message }) } } function onErrors(errors) { toast({ title: "You have errors", description: (
					{JSON.stringify(errors, null, 2)}
				
), }) console.log(JSON.stringify(errors)) } return (
( Story The piece you submitted )} /> ( Publication The market you sent it to )} /> ( Date of submission { field.onChange(e); setIsSubCalendarOpen(false); }} disabled={(date) => date > new Date() || date < new Date("1900-01-01") } initialFocus /> The date you sent it )} /> ( Date of response { field.onChange(e); setIsRespCalendarOpen(false); }} disabled={(date) => date > new Date() || date < new Date("1900-01-01") } initialFocus /> The date they wrote back )} /> ( Response The market you sent it to )} /> ) }