mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
console.log("TypeScript działa!");
|
|
|
|
async function createEvent() {
|
|
// Pobieranie danych z formularza
|
|
const title = (document.getElementById('title') as HTMLInputElement).value;
|
|
const location = (document.getElementById('location') as HTMLInputElement).value;
|
|
const description = (document.getElementById('description') as HTMLTextAreaElement).value;
|
|
const eventDateRaw = (document.getElementById('eventDate') as HTMLInputElement).value;
|
|
|
|
// Walidacja prostych pól
|
|
if (!title || !location || !eventDateRaw) {
|
|
alert("Uzupełnij wszystkie wymagane pola!");
|
|
return;
|
|
}
|
|
|
|
const eventDate = new Date(eventDateRaw).toISOString();
|
|
|
|
const payload = {
|
|
title,
|
|
location,
|
|
description,
|
|
eventDate,
|
|
};
|
|
|
|
try {
|
|
const response = await fetch('/api/events', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text();
|
|
throw new Error(errorText);
|
|
}
|
|
|
|
alert("Wydarzenie zostało utworzone!");
|
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
|
} catch (error) {
|
|
console.error("Błąd podczas tworzenia:", error);
|
|
alert("Nie udało się utworzyć wydarzenia: " + error);
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const saveBtn = document.getElementById("saveBtn");
|
|
if (saveBtn) {
|
|
saveBtn.addEventListener("click", (e) => {
|
|
e.preventDefault();
|
|
createEvent();
|
|
});
|
|
}
|
|
}); |