implement server actions for sandbox data mutation

This commit is contained in:
Ishaan Dey
2024-04-27 21:24:20 -04:00
parent c4e1a894c3
commit 7b7bd6f430
7 changed files with 276 additions and 7 deletions

View File

@ -1,5 +1,7 @@
"use server"
import { revalidatePath } from "next/cache"
export async function createSandbox(body: {
type: string
name: string
@ -16,3 +18,27 @@ export async function createSandbox(body: {
return await res.text()
}
export async function updateSandbox(body: {
id: string
name?: string
visibility?: "public" | "private"
}) {
const res = await fetch("http://localhost:8787/api/sandbox", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
})
revalidatePath("/dashboard")
}
export async function deleteSandbox(id: string) {
const res = await fetch(`http://localhost:8787/api/sandbox?id=${id}`, {
method: "DELETE",
})
revalidatePath("/dashboard")
}