przejscie na api

przed rozwaleniem
This commit is contained in:
Witkopawel
2025-04-30 11:01:40 +02:00
parent 04f99d666f
commit 74b69f045d
11 changed files with 807 additions and 1 deletions

24
WebApp/ts/eventDelete.ts Normal file
View File

@@ -0,0 +1,24 @@
document.addEventListener("DOMContentLoaded", () => {
const deleteButtons = document.querySelectorAll(".delete-btn");
deleteButtons.forEach(button => {
button.addEventListener("click", async () => {
const id = (button as HTMLButtonElement).dataset.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 row = button.closest("tr");
if (row) row.remove();
} else {
alert("Nie udało się usunąć wydarzenia.");
}
});
});
});