From 8c3d4e4e33a78edf0c8e3e475f289aa0b5ac7106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Mon, 31 Aug 2026 19:31:16 +0200 Subject: [PATCH] Add a delete button on the session detail view Same confirm-dialog delete UX as the sessions table, next to Replay in the header. Deleting redirects back to /sessions since the session no longer exists. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01WzyfRyA7h5rs5SCAahLAWd --- app/(app)/sessions/[id]/page.tsx | 2 + components/sessions/SessionDeleteButton.tsx | 63 +++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 components/sessions/SessionDeleteButton.tsx diff --git a/app/(app)/sessions/[id]/page.tsx b/app/(app)/sessions/[id]/page.tsx index f2163a7..dfad216 100644 --- a/app/(app)/sessions/[id]/page.tsx +++ b/app/(app)/sessions/[id]/page.tsx @@ -7,6 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { SessionTimelineChart } from "@/components/sessions/SessionTimelineChart"; import { SessionTitleEditor } from "@/components/sessions/SessionTitleEditor"; import { SessionDescriptionEditor } from "@/components/sessions/SessionDescriptionEditor"; +import { SessionDeleteButton } from "@/components/sessions/SessionDeleteButton"; import { STATUS_VARIANT } from "@/components/sessions/session-status"; import { getSessionDetail, getSessionName } from "@/lib/db/queries/sessions"; import { getSessionTimeline } from "@/lib/db/queries/stats"; @@ -65,6 +66,7 @@ export default async function SessionDetailPage({ params }: { params: Promise<{ )} + diff --git a/components/sessions/SessionDeleteButton.tsx b/components/sessions/SessionDeleteButton.tsx new file mode 100644 index 0000000..0540082 --- /dev/null +++ b/components/sessions/SessionDeleteButton.tsx @@ -0,0 +1,63 @@ +"use client"; + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Trash2 } from "lucide-react"; +import { toast } from "sonner"; + +export function SessionDeleteButton({ sessionId, sessionName }: { sessionId: number; sessionName: string | null }) { + const router = useRouter(); + const [open, setOpen] = useState(false); + const [deleting, setDeleting] = useState(false); + + async function handleDelete() { + setDeleting(true); + const res = await fetch(`/api/sessions/${sessionId}`, { method: "DELETE" }); + setDeleting(false); + if (res.ok) { + toast.success("Session deleted"); + router.push("/sessions"); + router.refresh(); + } else { + toast.error("Could not delete session"); + } + } + + return ( + <> + + + + + + Delete session? + + This permanently deletes{" "} + {sessionName ?? `Session #${sessionId}`} and all + of its recorded events. This can't be undone. + + + + + + + + + + ); +}