"use client" import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { z } from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { Form, FormControl, FormField, FormItem, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Loader2, UserPlus, X } from "lucide-react" import { useState } from "react" import { Sandbox } from "@/lib/types" import { Button } from "@/components/ui/button" import { shareSandbox } from "@/lib/actions" import { toast } from "sonner" import SharedUser from "./sharedUser" import { DialogDescription } from "@radix-ui/react-dialog" const formSchema = z.object({ email: z.string().email(), }) export default function ShareSandboxModal({ open, setOpen, data, shared, }: { open: boolean setOpen: (open: boolean) => void data: Sandbox shared: { id: string name: string }[] }) { const [loading, setLoading] = useState(false) const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { email: "", }, }) async function onSubmit(values: z.infer) { setLoading(true) const res = await shareSandbox(data.id, values.email) if (!res.success) { toast.error(res.message) } else { toast.success("Shared successfully.") } setLoading(false) } return (
0 ? "pb-3" : null} space-y-6`}> Share Sandbox {data.visibility === "private" ? ( This sandbox is private. Making it public will allow shared users to view and collaborate. ) : null}
( )} />
{shared.length > 0 ? ( <>
Manage Access
{shared.map((user) => ( ))}
) : null}
) }