sharing logic

This commit is contained in:
Ishaan Dey
2024-05-01 01:53:49 -04:00
parent 66a76eb0f9
commit 5ba1c03030
8 changed files with 90 additions and 38 deletions

View File

@ -44,18 +44,19 @@ export async function deleteSandbox(id: string) {
}
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 }),
})
const res = await fetch("http://localhost:8787/api/sandbox/share", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ sandboxId, email }),
})
const text = await res.text()
revalidatePath(`/code/${sandboxId}`)
return true
} catch (err) {
return false
if (res.status !== 200) {
return { success: false, message: text }
}
revalidatePath(`/code/${sandboxId}`)
return { success: true, message: "Shared successfully." }
}

View File

@ -5,6 +5,7 @@ export type User = {
name: string
email: string
sandbox: Sandbox[]
usersToSandboxes: UsersToSandboxes[]
}
export type Sandbox = {
@ -13,6 +14,12 @@ export type Sandbox = {
type: "react" | "node"
visibility: "public" | "private"
userId: string
usersToSandboxes: UsersToSandboxes[]
}
export type UsersToSandboxes = {
userId: string
sandboxId: string
}
export type R2Files = {