mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
26 lines
720 B
TypeScript
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.");
|
|
}
|
|
});
|
|
});
|