diff --git a/src/admin/GalleryManager.tsx b/src/admin/GalleryManager.tsx index 105736252..75890982b 100644 --- a/src/admin/GalleryManager.tsx +++ b/src/admin/GalleryManager.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { toast } from "sonner"; +import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; const apiBase = import.meta.env.VITE_API_URL; @@ -13,6 +15,8 @@ type GalleryImage = { const GalleryManager = () => { const [images, setImages] = useState([]); const [uploading, setUploading] = useState(false); + const [selectedImage, setSelectedImage] = useState(null); + const [dialogOpen, setDialogOpen] = useState(false); const fetchImages = async () => { try { @@ -52,11 +56,11 @@ const GalleryManager = () => { } }; - const handleDelete = async (id: number) => { - if (!confirm("Bist du sicher, dass du dieses Bild löschen willst?")) return; + const handleDelete = async () => { + if (selectedImage === null) return; try { - const res = await fetch(`${apiBase}/api/gallery/${id}`, { + const res = await fetch(`${apiBase}/api/gallery/${selectedImage}`, { method: "DELETE", }); @@ -65,6 +69,9 @@ const GalleryManager = () => { await fetchImages(); } catch (err) { toast.error("Fehler beim Löschen des Bildes"); + } finally { + setDialogOpen(false); + setSelectedImage(null); } }; @@ -72,11 +79,22 @@ const GalleryManager = () => {

Galerie verwalten

+ {/* Upload Button */}
- + + {uploading &&

Bild wird hochgeladen...

}
+ {/* Bilder */}
{images.map((img) => ( @@ -89,7 +107,10 @@ const GalleryManager = () => { @@ -97,6 +118,20 @@ const GalleryManager = () => { ))}
+ + {/* Dialog zur Bestätigung */} + + + + Bild wirklich löschen? + +

Diese Aktion kann nicht rückgängig gemacht werden.

+ + + + +
+
); };