sql schema update + start share logic

This commit is contained in:
Ishaan Dey
2024-05-01 01:29:16 -04:00
parent c171cb580e
commit 66a76eb0f9
13 changed files with 294 additions and 82 deletions

View File

@ -31,6 +31,7 @@ export default async function AppAuthLayout({
console.log(res)
} else {
// user already exists in db
console.log("user exists already.", dbUserJSON)
}
return <>{children}</>

View File

@ -30,10 +30,12 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Loader2, UserPlus, X } from "lucide-react"
import { useState } from "react"
import { useState, useTransition } from "react"
import { Sandbox } from "@/lib/types"
import { Button } from "@/components/ui/button"
import Avatar from "@/components/ui/avatar"
import { shareSandbox } from "@/lib/actions"
import { toast } from "sonner"
const formSchema = z.object({
email: z.string().email(),
@ -64,6 +66,14 @@ export default function ShareSandboxModal({
// const id = await createSandbox(sandboxData)
console.log(values)
setLoading(true)
const res = await shareSandbox(data.id, values.email)
if (!res) {
toast.error("Failed to share.")
}
setLoading(false)
}
return (

View File

@ -42,3 +42,20 @@ export async function deleteSandbox(id: string) {
revalidatePath("/dashboard")
}
export async function shareSandbox(sandboxId: string, email: string) {
try {
const res = await fetch("http://localhost:8787/api/sandbox/share", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ sandboxId, email }),
})
revalidatePath(`/code/${sandboxId}`)
return true
} catch (err) {
return false
}
}