updating logic
This commit is contained in:
parent
e23b38875e
commit
d3698b9a50
@ -49,7 +49,8 @@ export default {
|
|||||||
const params = url.searchParams;
|
const params = url.searchParams;
|
||||||
if (params.has("id")) {
|
if (params.has("id")) {
|
||||||
const id = params.get("id") as string;
|
const id = params.get("id") as string;
|
||||||
const res = await db.delete(sandbox).where(eq(sandbox.id, id)).get();
|
await db.delete(usersToSandboxes).where(eq(usersToSandboxes.sandboxId, id));
|
||||||
|
await db.delete(sandbox).where(eq(sandbox.id, id));
|
||||||
return success;
|
return success;
|
||||||
} else {
|
} else {
|
||||||
return invalidRequest;
|
return invalidRequest;
|
||||||
|
@ -33,6 +33,8 @@ import { Loader2 } from "lucide-react"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Sandbox } from "@/lib/types"
|
import { Sandbox } from "@/lib/types"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { deleteSandbox, updateSandbox } from "@/lib/actions"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
name: z.string().min(1).max(16),
|
name: z.string().min(1).max(16),
|
||||||
@ -49,6 +51,9 @@ export default function EditSandboxModal({
|
|||||||
data: Sandbox
|
data: Sandbox
|
||||||
}) {
|
}) {
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [loadingDelete, setLoadingDelete] = useState(false)
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
@ -59,12 +64,19 @@ export default function EditSandboxModal({
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function onSubmit(values: z.infer<typeof formSchema>) {
|
async function onSubmit(values: z.infer<typeof formSchema>) {
|
||||||
// if (!user.isSignedIn) return
|
|
||||||
// const sandboxData = { type: selected, userId: user.user.id, ...values }
|
|
||||||
// setLoading(true)
|
|
||||||
// const id = await createSandbox(sandboxData)
|
|
||||||
|
|
||||||
console.log(values)
|
console.log(values)
|
||||||
|
|
||||||
|
setLoading(true)
|
||||||
|
await updateSandbox({ id: data.id, ...values })
|
||||||
|
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onDelete() {
|
||||||
|
setLoadingDelete(true)
|
||||||
|
await deleteSandbox(data.id)
|
||||||
|
|
||||||
|
router.push("/dashboard")
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -119,11 +131,25 @@ export default function EditSandboxModal({
|
|||||||
<Loader2 className="animate-spin mr-2 h-4 w-4" /> Loading...
|
<Loader2 className="animate-spin mr-2 h-4 w-4" /> Loading...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
"Submit"
|
"Update Sandbox"
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
<Button
|
||||||
|
disabled={loadingDelete}
|
||||||
|
onClick={onDelete}
|
||||||
|
className="w-full"
|
||||||
|
variant="destructive"
|
||||||
|
>
|
||||||
|
{loadingDelete ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="animate-spin mr-2 h-4 w-4" /> Loading...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
"Delete Sandbox"
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,7 @@ const buttonVariants = cva(
|
|||||||
default:
|
default:
|
||||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||||
destructive:
|
destructive:
|
||||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
"border border-destructive bg-background shadow-sm hover:bg-destructive/20 text-destructive",
|
||||||
outline:
|
outline:
|
||||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||||
secondary:
|
secondary:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user