sql schema update + start share logic
This commit is contained in:
@ -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}</>
|
||||
|
@ -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 (
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user