From 83789dd12efe82b645445fbb46d98bcb2a003b57 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 7 Dec 2025 18:03:04 +0900 Subject: feat(client): add delete deck modal with confirmation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add DeleteDeckModal component that prompts users for confirmation before deleting a deck. Includes warning about permanent deletion and all associated cards. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/client/components/DeleteDeckModal.tsx | 159 ++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 src/client/components/DeleteDeckModal.tsx (limited to 'src/client/components/DeleteDeckModal.tsx') diff --git a/src/client/components/DeleteDeckModal.tsx b/src/client/components/DeleteDeckModal.tsx new file mode 100644 index 0000000..307451c --- /dev/null +++ b/src/client/components/DeleteDeckModal.tsx @@ -0,0 +1,159 @@ +import { useState } from "react"; +import { ApiClientError, apiClient } from "../api"; + +interface Deck { + id: string; + name: string; +} + +interface DeleteDeckModalProps { + isOpen: boolean; + deck: Deck | null; + onClose: () => void; + onDeckDeleted: () => void; +} + +export function DeleteDeckModal({ + isOpen, + deck, + onClose, + onDeckDeleted, +}: DeleteDeckModalProps) { + const [error, setError] = useState(null); + const [isDeleting, setIsDeleting] = useState(false); + + const handleClose = () => { + setError(null); + onClose(); + }; + + const handleDelete = async () => { + if (!deck) return; + + setError(null); + setIsDeleting(true); + + try { + const authHeader = apiClient.getAuthHeader(); + if (!authHeader) { + throw new ApiClientError("Not authenticated", 401); + } + + const res = await fetch(`/api/decks/${deck.id}`, { + method: "DELETE", + headers: authHeader, + }); + + if (!res.ok) { + const errorBody = await res.json().catch(() => ({})); + throw new ApiClientError( + (errorBody as { error?: string }).error || + `Request failed with status ${res.status}`, + res.status, + ); + } + + onDeckDeleted(); + onClose(); + } catch (err) { + if (err instanceof ApiClientError) { + setError(err.message); + } else { + setError("Failed to delete deck. Please try again."); + } + } finally { + setIsDeleting(false); + } + }; + + if (!isOpen || !deck) { + return null; + } + + return ( +
{ + if (e.target === e.currentTarget) { + handleClose(); + } + }} + onKeyDown={(e) => { + if (e.key === "Escape") { + handleClose(); + } + }} + > +
+

+ Delete Deck +

+ + {error && ( +
+ {error} +
+ )} + +

+ Are you sure you want to delete {deck.name}? +

+

+ This action cannot be undone. All cards in this deck will also be + deleted. +

+ +
+ + +
+
+
+ ); +} -- cgit v1.2.3-70-g09d2