sharing logic
This commit is contained in:
@ -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." }
|
||||
}
|
||||
|
@ -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 = {
|
||||
|
Reference in New Issue
Block a user