mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
przejscie na api
przed rozwaleniem
This commit is contained in:
24
WebApp/ts/eventDelete.ts
Normal file
24
WebApp/ts/eventDelete.ts
Normal 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.");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user