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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzyfRyA7h5rs5SCAahLAWd
This commit is contained in:
@@ -7,6 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|||||||
import { SessionTimelineChart } from "@/components/sessions/SessionTimelineChart";
|
import { SessionTimelineChart } from "@/components/sessions/SessionTimelineChart";
|
||||||
import { SessionTitleEditor } from "@/components/sessions/SessionTitleEditor";
|
import { SessionTitleEditor } from "@/components/sessions/SessionTitleEditor";
|
||||||
import { SessionDescriptionEditor } from "@/components/sessions/SessionDescriptionEditor";
|
import { SessionDescriptionEditor } from "@/components/sessions/SessionDescriptionEditor";
|
||||||
|
import { SessionDeleteButton } from "@/components/sessions/SessionDeleteButton";
|
||||||
import { STATUS_VARIANT } from "@/components/sessions/session-status";
|
import { STATUS_VARIANT } from "@/components/sessions/session-status";
|
||||||
import { getSessionDetail, getSessionName } from "@/lib/db/queries/sessions";
|
import { getSessionDetail, getSessionName } from "@/lib/db/queries/sessions";
|
||||||
import { getSessionTimeline } from "@/lib/db/queries/stats";
|
import { getSessionTimeline } from "@/lib/db/queries/stats";
|
||||||
@@ -65,6 +66,7 @@ export default async function SessionDetailPage({ params }: { params: Promise<{
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
<SessionDeleteButton sessionId={detail.session.id} sessionName={detail.session.name} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<>
|
||||||
|
<Button variant="ghost" size="icon-sm" onClick={() => setOpen(true)} aria-label="Delete session">
|
||||||
|
<Trash2 className="size-4" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Delete session?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
This permanently deletes{" "}
|
||||||
|
<span className="font-medium text-foreground">{sessionName ?? `Session #${sessionId}`}</span> and all
|
||||||
|
of its recorded events. This can't be undone.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="ghost" onClick={() => setOpen(false)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button variant="destructive" onClick={() => void handleDelete()} disabled={deleting}>
|
||||||
|
{deleting ? "Deleting..." : "Delete"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user