mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Lekkie zmiany
Trzeba dodać logowanie tak jak reszte(nie wiem gdzie było logowanie ale zaraz się znajdzie)
This commit is contained in:
@@ -1,25 +1,32 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Obsługuje kliknięcie na przycisk "Usuń"
|
||||
document.body.addEventListener("click", async (e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
|
||||
if (!target.matches(".delete-btn")) return;
|
||||
if (!target.matches(".delete-btn")) return; // Sprawdza, czy kliknięto przycisk "Usuń"
|
||||
|
||||
const id = target.getAttribute("data-id");
|
||||
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
||||
if (!id) return;
|
||||
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?");
|
||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
||||
if (!confirmed) return;
|
||||
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
try {
|
||||
// Wysyła żądanie DELETE do API
|
||||
const response = await fetch(`/api/events/${id}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
|
||||
method: "DELETE"
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const card = target.closest(".col");
|
||||
if (card) card.remove();
|
||||
} else {
|
||||
alert("Nie udało się usunąć wydarzenia.");
|
||||
if (response.ok) {
|
||||
// Usuwa kartę z DOM (bez przeładowania strony)
|
||||
const card = target.closest(".event-card");
|
||||
if (card) card.remove();
|
||||
} else {
|
||||
alert("Błąd podczas usuwania wydarzenia.");
|
||||
}
|
||||
} catch (err) {
|
||||
alert("Błąd połączenia z serwerem.");
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user