import { useForm } from "react-hook-form"; import { NOTE_COLORS } from "@/lib/constants"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; import { Checkbox } from "@/components/ui/checkbox"; const noteSchema = z.object({ title: z.string().min(1, "Title is required").max(200, "Title too long"), content: z.string().optional(), is_pinned: z.boolean().default(false), tags: z.string().optional(), // Comma separated for now color: z.string().default("DEFAULT"), }); type NoteFormValues = z.infer; interface NoteFormProps { defaultValues?: Partial; onSubmit: (data: NoteFormValues) => void; isLoading?: boolean; submitLabel?: string; } export function NoteForm({ defaultValues, onSubmit, isLoading, submitLabel = "Save" }: NoteFormProps) { const form = useForm({ resolver: zodResolver(noteSchema), defaultValues: { title: "", content: "", is_pinned: false, tags: "", color: "DEFAULT", ...defaultValues, }, }); return (
( Title )} /> ( Content