Files
hermes/WebApp/ts/eventDelete.ts
Witkopawel 470ce72b6a Wersja probna
powinno cos dzialac
2025-04-30 12:40:59 +02:00

26 lines
720 B
TypeScript

document.addEventListener("DOMContentLoaded", () => {
document.body.addEventListener("click", async (e) => {
const target = e.target as HTMLElement;
if (!target.matches(".delete-btn")) return;
const id = target.getAttribute("data-id");
if (!id) return;
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
if (!confirmed) return;
const response = await fetch(`/api/events/${id}`, {
method: "DELETE"
});
if (response.ok) {
const card = target.closest(".col");
if (card) card.remove();
} else {
alert("Nie udało się usunąć wydarzenia.");
}
});
});