Wersja probna

powinno cos dzialac
This commit is contained in:
Witkopawel
2025-04-30 12:40:59 +02:00
parent 74b69f045d
commit 470ce72b6a
12 changed files with 332 additions and 141 deletions

View File

@@ -1,24 +1,25 @@
document.addEventListener("DOMContentLoaded", () => {
const deleteButtons = document.querySelectorAll(".delete-btn");
document.body.addEventListener("click", async (e) => {
const target = e.target as HTMLElement;
deleteButtons.forEach(button => {
button.addEventListener("click", async () => {
const id = (button as HTMLButtonElement).dataset.id;
if (!id) return;
if (!target.matches(".delete-btn")) return;
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
if (!confirmed) return;
const id = target.getAttribute("data-id");
if (!id) return;
const response = await fetch(`/api/events/${id}`, {
method: "DELETE"
});
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
if (!confirmed) return;
if (response.ok) {
const row = button.closest("tr");
if (row) row.remove();
} else {
alert("Nie udało się usunąć wydarzenia.");
}
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.");
}
});
});