"use client" import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { z } from "zod" import { Button } from "@/components/ui/button" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { deleteSandbox, updateSandbox } from "@/lib/actions" import { Sandbox } from "@/lib/types" import { Loader2 } from "lucide-react" import { useRouter } from "next/navigation" import { useState } from "react" import { toast } from "sonner" const formSchema = z.object({ name: z.string().min(1).max(16), visibility: z.enum(["public", "private"]), }) export default function EditSandboxModal({ open, setOpen, data, }: { open: boolean setOpen: (open: boolean) => void data: Sandbox }) { const [loading, setLoading] = useState(false) const [loadingDelete, setLoadingDelete] = useState(false) const router = useRouter() const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { name: data.name, visibility: data.visibility, }, }) async function onSubmit(values: z.infer) { setLoading(true) await updateSandbox({ id: data.id, ...values }) toast.success("Sandbox updated successfully") setLoading(false) } async function onDelete() { setLoadingDelete(true) await deleteSandbox(data.id) router.push("/dashboard") } return ( Edit Sandbox Info
( Name )} /> ( Visibility )} />
) }