From da3d7319a6bd27b31eb4efbe02a95f8bcf9290fc Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 May 2026 14:40:38 +0200 Subject: [PATCH] feat: delete pair button in EditPairForm with confirmation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two-step: "Pair löschen" → confirm "Wirklich löschen" before DELETE /pairs/:id. On success closes the form and reloads the pairs list. Co-Authored-By: Claude Sonnet 4.6 --- src/pages/ContentCreation.jsx | 47 +++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/pages/ContentCreation.jsx b/src/pages/ContentCreation.jsx index b1621fd..31d8297 100644 --- a/src/pages/ContentCreation.jsx +++ b/src/pages/ContentCreation.jsx @@ -1,6 +1,6 @@ import { useEffect, useState, useRef, useCallback, useMemo } from 'react'; import Layout from '../components/Layout'; -import { apiFetch, apiPost, apiPatch, apiLink, apiUnlink, getUserLang } from '../lib/api'; +import { apiFetch, apiPost, apiPatch, apiLink, apiUnlink, apiDelete, getUserLang } from '../lib/api'; import { STATUS_COLORS } from '../lib/tables'; // ─── Word / placeholder helpers ─────────────────────────────────────────────── @@ -425,7 +425,7 @@ function PairForm({ objectId, allObjects, onPairSaved }) { // ─── EditPairForm ───────────────────────────────────────────────────────────── -function EditPairForm({ pair, allObjects, onSaved, onCancel }) { +function EditPairForm({ pair, allObjects, onSaved, onCancel, onDeleted }) { const lang = getUserLang(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); @@ -441,9 +441,20 @@ function EditPairForm({ pair, allObjects, onSaved, onCancel }) { const [selection, setSelection] = useState(''); const [wordInput, setWordInput] = useState(''); const [creatingWord, setCreatingWord] = useState(false); + const [confirmDelete, setConfirmDelete] = useState(false); + const [deleting, setDeleting] = useState(false); useEffect(() => { setWordInput(selection); }, [selection]); + async function handleDelete() { + setDeleting(true); + try { + await apiDelete('/pairs', pair.id); + onDeleted(pair.id); + } catch (e) { alert('Fehler beim Löschen: ' + e.message); } + finally { setDeleting(false); } + } + useEffect(() => { async function load() { try { @@ -675,11 +686,30 @@ function EditPairForm({ pair, allObjects, onSaved, onCancel }) { )} -
- - +
+
+ + +
+ {!confirmDelete ? ( + + ) : ( +
+ + +
+ )}
); @@ -848,7 +878,8 @@ function PairsPanel({ selectedObject, allObjects, objectPairs, loadingPairs, onP {editingId === pair.id ? ( { setEditingId(null); onPairsReload(); }} - onCancel={() => setEditingId(null)} /> + onCancel={() => setEditingId(null)} + onDeleted={id => { setEditingId(null); onPairsReload(); }} /> ) : (