mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
@@ -1,44 +0,0 @@
|
|||||||
document.addEventListener("DOMContentLoaded", () => {
|
|
||||||
const applyBtn = document.getElementById("applyBtn") as HTMLButtonElement | null;
|
|
||||||
|
|
||||||
if (!applyBtn) return;
|
|
||||||
|
|
||||||
const eventId = getEventIdFromURL();
|
|
||||||
|
|
||||||
if (!eventId) {
|
|
||||||
console.error("Event ID not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
applyBtn.addEventListener("click", async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/api/events/join/${eventId}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const result: {
|
|
||||||
success: boolean;
|
|
||||||
error_msg?: string;
|
|
||||||
} = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
applyBtn.disabled = true;
|
|
||||||
applyBtn.textContent = "Applied Succesfully";
|
|
||||||
} else {
|
|
||||||
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to apply:", error);
|
|
||||||
alert("Failed to apply due to a network or server error.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function getEventIdFromURL(): number | null {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
const idParam = params.get("event");
|
|
||||||
return idParam ? parseInt(idParam, 10) : null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
|
||||||
const applyBtn = document.getElementById("applyBtn");
|
|
||||||
if (!applyBtn)
|
|
||||||
return;
|
|
||||||
const eventId = getEventIdFromURL();
|
|
||||||
if (!eventId) {
|
|
||||||
console.error("Event ID not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
applyBtn.addEventListener("click", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
||||||
var _a;
|
|
||||||
try {
|
|
||||||
const response = yield fetch(`/api/events/join/${eventId}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const result = yield response.json();
|
|
||||||
if (result.success) {
|
|
||||||
applyBtn.disabled = true;
|
|
||||||
applyBtn.textContent = "Applied Succesfully";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alert(`Error: ${(_a = result.error_msg) !== null && _a !== void 0 ? _a : "Unknown error occurred."}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error("Failed to apply:", error);
|
|
||||||
alert("Failed to apply due to a network or server error.");
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
function getEventIdFromURL() {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
const idParam = params.get("event");
|
|
||||||
return idParam ? parseInt(idParam, 10) : null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -72,7 +72,6 @@
|
|||||||
<script type="module" src="/js/eventView.js"></script>
|
<script type="module" src="/js/eventView.js"></script>
|
||||||
<script type="module" src="/js/generalUseHelpers.js"></script>
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
<script type="module" src="/js/auth.js"></script>
|
<script type="module" src="/js/auth.js"></script>
|
||||||
<script type="module" src="js/applyToEvent.js"></script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user