From 15337f768d29aac6086c0a489c6c1bcaa29445f3 Mon Sep 17 00:00:00 2001 From: Matthias Hochmeister Date: Sat, 28 Mar 2026 18:17:32 +0100 Subject: [PATCH] feat: add inline editing for checklist vorlage items --- frontend/src/pages/Checklisten.tsx | 51 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/Checklisten.tsx b/frontend/src/pages/Checklisten.tsx index 6f1d56a..f356dba 100644 --- a/frontend/src/pages/Checklisten.tsx +++ b/frontend/src/pages/Checklisten.tsx @@ -623,6 +623,8 @@ function VorlageItemsSection({ vorlageId, queryClient, showSuccess, showError }: }); const [newItem, setNewItem] = useState({ bezeichnung: '', pflicht: false, sort_order: 0 }); + const [editingId, setEditingId] = useState(null); + const [editForm, setEditForm] = useState<{ bezeichnung: string; pflicht: boolean }>({ bezeichnung: '', pflicht: false }); const addMutation = useMutation({ mutationFn: (data: CreateVorlageItemPayload) => checklistenApi.addVorlageItem(vorlageId, data), @@ -630,23 +632,62 @@ function VorlageItemsSection({ vorlageId, queryClient, showSuccess, showError }: onError: () => showError('Fehler beim Hinzufügen'), }); + const updateMutation = useMutation({ + mutationFn: ({ id, data }: { id: number; data: { bezeichnung: string; pflicht: boolean } }) => checklistenApi.updateVorlageItem(id, data), + onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['checklisten-vorlage-items', vorlageId] }); setEditingId(null); showSuccess('Item aktualisiert'); }, + onError: () => showError('Fehler beim Aktualisieren'), + }); + const deleteMutation = useMutation({ mutationFn: (id: number) => checklistenApi.deleteVorlageItem(id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['checklisten-vorlage-items', vorlageId] }); showSuccess('Item entfernt'); }, onError: () => showError('Fehler beim Entfernen'), }); + const startEdit = (item: ChecklistVorlageItem) => { + setEditingId(item.id); + setEditForm({ bezeichnung: item.bezeichnung, pflicht: item.pflicht }); + }; + if (isLoading) return ; return ( Checklisten-Items {items.map((item) => ( - - - {item.bezeichnung} {item.pflicht && } - - deleteMutation.mutate(item.id)}> + + {editingId === item.id ? ( + + setEditForm((f) => ({ ...f, bezeichnung: e.target.value }))} + sx={{ flexGrow: 1 }} + autoFocus + /> + setEditForm((f) => ({ ...f, pflicht: e.target.checked }))} />} + label="Pflicht" + /> + + + + ) : ( + + + {item.bezeichnung} {item.pflicht && } + + startEdit(item)}> + deleteMutation.mutate(item.id)}> + + )} ))}