"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { toast } from "sonner" import { Settings } from "lucide-react" import { useForm } from "react-hook-form" import { z } from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Checkbox } from "@/components/ui/checkbox" import { updatePlan } from "@/app/actions/plan" const formSchema = z.object({ webhookUrl: z.string().optional().or(z.literal("")), instructions: z.string().optional().or(z.literal("")), notifyAll: z.boolean(), }) type FormValues = z.infer type PlanSettingsProps = { planId: string initialWebhookUrl?: string | null initialInstructions?: string | null initialNotifyAll?: boolean } export function PlanSettings({ planId, initialWebhookUrl, initialInstructions, initialNotifyAll = true }: PlanSettingsProps) { const [open, setOpen] = useState(false) const router = useRouter() const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { webhookUrl: initialWebhookUrl || "", instructions: initialInstructions || "", notifyAll: initialNotifyAll, }, }) async function onSubmit(values: FormValues) { try { await updatePlan(planId, { webhookUrl: values.webhookUrl || "", instructions: values.instructions || "", notifyAll: values.notifyAll, }) toast.success("Settings updated") setOpen(false) router.refresh() } catch { toast.error("Failed to update settings") } } return ( Plan Settings Configure notification webhooks and cat care instructions.
( Cat Instructions