shared user restrictions + cleanup console logs

This commit is contained in:
Ishaan Dey
2024-05-07 22:40:59 -07:00
parent 9d288f580d
commit 12e8051673
12 changed files with 194 additions and 174 deletions

View File

@ -1,4 +1,4 @@
"use client"
"use client";
import {
Dialog,
@ -7,10 +7,10 @@ import {
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { z } from "zod"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
} from "@/components/ui/dialog";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import {
Form,
@ -20,41 +20,41 @@ import {
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { Loader2 } from "lucide-react"
import { useState } from "react"
import { Sandbox } from "@/lib/types"
import { Button } from "@/components/ui/button"
import { deleteSandbox, updateSandbox } from "@/lib/actions"
import { useRouter } from "next/navigation"
import { toast } from "sonner"
} from "@/components/ui/select";
import { Loader2 } from "lucide-react";
import { useState } from "react";
import { Sandbox } from "@/lib/types";
import { Button } from "@/components/ui/button";
import { deleteSandbox, updateSandbox } from "@/lib/actions";
import { useRouter } from "next/navigation";
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
open: boolean;
setOpen: (open: boolean) => void;
data: Sandbox;
}) {
const [loading, setLoading] = useState(false)
const [loadingDelete, setLoadingDelete] = useState(false)
const [loading, setLoading] = useState(false);
const [loadingDelete, setLoadingDelete] = useState(false);
const router = useRouter()
const router = useRouter();
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@ -62,24 +62,22 @@ export default function EditSandboxModal({
name: data.name,
visibility: data.visibility,
},
})
});
async function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values)
setLoading(true);
await updateSandbox({ id: data.id, ...values });
setLoading(true)
await updateSandbox({ id: data.id, ...values })
toast.success("Sandbox updated successfully");
toast.success("Sandbox updated successfully")
setLoading(false)
setLoading(false);
}
async function onDelete() {
setLoadingDelete(true)
await deleteSandbox(data.id)
setLoadingDelete(true);
await deleteSandbox(data.id);
router.push("/dashboard")
router.push("/dashboard");
}
return (
@ -155,5 +153,5 @@ export default function EditSandboxModal({
</Button>
</DialogContent>
</Dialog>
)
);
}