No messages to display.
`;
+ return;
+ }
+
+ messages.forEach((msg: any) => {
+ const card = createMessageCard(msg);
+ container.appendChild(card);
+ });
+
+ // Attach delete handlers
+ container.querySelectorAll('.delete-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const idStr = btn.getAttribute('data-id');
+ if (idStr) deleteMessage(parseInt(idStr));
+ });
+ });
+
+ } catch (err) {
+ container.innerHTML = `Failed to load messages.
`;
+ console.error(err);
+ }
+}
+
+document.addEventListener('DOMContentLoaded', () => {
+ loadMessages();
+});
diff --git a/WebApp/ts/userSkills.ts b/WebApp/ts/userSkills.ts
index 98d6057..d5c4053 100644
--- a/WebApp/ts/userSkills.ts
+++ b/WebApp/ts/userSkills.ts
@@ -1,10 +1,10 @@
import { getEvent, getMyAccount, unhideElementById, getMyRegisteredEventIds } from './generalUseHelpers.js';
-var redirected = false;
+var redirected = false;
document.addEventListener("DOMContentLoaded", async () => {
- var container = document.getElementById("mainContainer");
+ var container = document.getElementById("mainContainer");
const modifyBtn = document.getElementById("editBtn");
const removeBtn = document.getElementById("removeBtn");
const applyBtn = document.getElementById("applyBtn");
@@ -28,7 +28,7 @@ document.addEventListener("DOMContentLoaded", async () => {
} else {
unhideElementById(document, "orgno");
}
- } catch {
+ } catch (e) {
window.location.href = "login.html";
}
@@ -40,15 +40,15 @@ document.addEventListener("DOMContentLoaded", async () => {
if (container !== null) container.innerHTML = `
-
+
Chats
diff --git a/WebApp/wwwroot/js/eventList.js b/WebApp/wwwroot/js/eventList.js
index 3e823bb..9394220 100644
--- a/WebApp/wwwroot/js/eventList.js
+++ b/WebApp/wwwroot/js/eventList.js
@@ -39,7 +39,6 @@ function getEvents(titleOrDescription, fDate, tDate) {
titleOrDescription = searchbar.value;
}
if (optionsVisibility) {
- // Opcje widoczne
var payload_visible = {
titleOrDescription,
eventDateFrom,
@@ -69,6 +68,32 @@ function getEvents(titleOrDescription, fDate, tDate) {
return events;
});
}
+function sendMessageForEvent(eventId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ const messageContent = `Help me with
this event`;
+ try {
+ const response = yield fetch('/api/messages/sendFromOrgToVolunteers', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ eventId, content: messageContent })
+ });
+ if (response.ok) {
+ alert('Message sent successfully to all volunteers!');
+ }
+ else {
+ let error = yield response.text();
+ if (!error)
+ error = `Status code: ${response.status}`;
+ alert('Failed to send message: ' + error);
+ console.error('Send message failed', response.status, error);
+ }
+ }
+ catch (error) {
+ alert('Error sending message: ' + error);
+ console.error('Fetch error:', error);
+ }
+ });
+}
function loadEvents(org_id, evs) {
return __awaiter(this, void 0, void 0, function* () {
const container = document.getElementById("eventList");
@@ -86,10 +111,7 @@ function loadEvents(org_id, evs) {
container.innerHTML = "
No events to display at this moment.
";
return;
}
- // Wyczyść kontener przed dodaniem nowych
container.innerHTML = '';
- const styleDefault = "color: #2898BD";
- const styleHighlighted = "#2393BD";
for (const ev of events) {
const card = document.createElement("div");
card.className = "event-card filled";
@@ -97,23 +119,39 @@ function loadEvents(org_id, evs) {
weekday: 'long',
year: 'numeric',
month: 'long',
- day: 'numeric' // "1"
+ day: 'numeric'
}).format(new Date(ev.eventDate));
- card.innerHTML = `
-
- ${ev.title}
- 👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}
- `;
+ const eventInfoSpan = document.createElement("span");
+ eventInfoSpan.innerHTML = `
+
${ev.title}
+
👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}
+ `;
+ card.appendChild(eventInfoSpan);
if (org_id == ev.organisationId) {
- card.innerHTML += `
-
`;
+ const buttonsDiv = document.createElement("div");
+ buttonsDiv.className = "d-flex gap-2 mt-2";
+ const editBtn = document.createElement("button");
+ editBtn.className = "edit-btn mod-btn";
+ editBtn.setAttribute("data-id", ev.eventId);
+ editBtn.title = "Edit event";
+ editBtn.innerHTML = `
`;
+ const removeBtn = document.createElement("button");
+ removeBtn.className = "remove-btn mod-btn";
+ removeBtn.setAttribute("data-id", ev.eventId);
+ removeBtn.title = "Remove event";
+ removeBtn.innerHTML = `
`;
+ const sendMsgBtn = document.createElement("button");
+ sendMsgBtn.className = "btn btn-sm btn-info";
+ sendMsgBtn.textContent = "Send Message";
+ sendMsgBtn.setAttribute("data-id", ev.eventId);
+ sendMsgBtn.title = "Send message about this event";
+ sendMsgBtn.addEventListener("click", () => __awaiter(this, void 0, void 0, function* () {
+ yield sendMessageForEvent(ev.eventId);
+ }));
+ buttonsDiv.appendChild(editBtn);
+ buttonsDiv.appendChild(removeBtn);
+ buttonsDiv.appendChild(sendMsgBtn);
+ card.appendChild(buttonsDiv);
}
container.appendChild(card);
}
@@ -138,12 +176,10 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
}
}
catch (_a) {
- // console.log("User not signed in. Failing gracefully.");
unhideElementById(document, "joinnow-btn");
unhideElementById(document, "signin-btn");
}
loadEvents(org_id);
- // listen for clicks
const listSortToggleButton = document.getElementById("list-sort-btn");
if (listSortToggleButton) {
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
@@ -152,11 +188,9 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
if (optionsToggleButton) {
optionsToggleButton.addEventListener("click", () => toggleOptionsVisibility());
}
- // and for enter in search bar
const searchBar = document.getElementById('searchbar');
searchBar.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
- // console.log('Enter key pressed!');
var searchResults = getEvents(searchBar.value);
loadEvents(org_id, searchResults);
}
diff --git a/WebApp/wwwroot/js/messages.js b/WebApp/wwwroot/js/messages.js
new file mode 100644
index 0000000..0ca5521
--- /dev/null
+++ b/WebApp/wwwroot/js/messages.js
@@ -0,0 +1,97 @@
+"use strict";
+// messages.ts
+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());
+ });
+};
+function getMyMessages() {
+ return __awaiter(this, void 0, void 0, function* () {
+ const res = yield fetch('/api/messages/my', {
+ method: 'GET',
+ headers: { 'Content-Type': 'application/json' }
+ });
+ if (!res.ok)
+ throw new Error('Failed to load messages');
+ return yield res.json();
+ });
+}
+function formatDate(dateStr) {
+ const date = new Date(dateStr);
+ return date.toLocaleString(undefined, {
+ year: 'numeric', month: 'short', day: 'numeric',
+ hour: '2-digit', minute: '2-digit'
+ });
+}
+function createMessageCard(msg) {
+ var _a;
+ const card = document.createElement('div');
+ card.className = 'messages-card';
+ const sender = msg.isMsgFromVolunteer
+ ? `Volunteer #${msg.volunteerId}`
+ : `Organization #${msg.organizationId}`;
+ // Safely inject content as HTML because it contains links
+ const contentHtml = (_a = msg.content) !== null && _a !== void 0 ? _a : '';
+ card.innerHTML = `
+
+
+
${formatDate(msg.isoDate)}
+
${contentHtml}
+
Regarding Event #${msg.eventType}
+ `;
+ return card;
+}
+function deleteMessage(messageId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (!confirm('Are you sure you want to delete this message?'))
+ return;
+ const res = yield fetch(`/api/messages/${messageId}`, {
+ method: 'DELETE',
+ headers: { 'Content-Type': 'application/json' }
+ });
+ if (!res.ok) {
+ alert('Failed to delete message.');
+ return;
+ }
+ // Reload messages after delete
+ loadMessages();
+ });
+}
+function loadMessages() {
+ return __awaiter(this, void 0, void 0, function* () {
+ const container = document.getElementById('messagesContainer');
+ if (!container)
+ return;
+ try {
+ const messages = yield getMyMessages();
+ container.innerHTML = '';
+ if (messages.length === 0) {
+ container.innerHTML = `
No messages to display.
`;
+ return;
+ }
+ messages.forEach((msg) => {
+ const card = createMessageCard(msg);
+ container.appendChild(card);
+ });
+ // Attach delete handlers
+ container.querySelectorAll('.delete-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const idStr = btn.getAttribute('data-id');
+ if (idStr)
+ deleteMessage(parseInt(idStr));
+ });
+ });
+ }
+ catch (err) {
+ container.innerHTML = `
Failed to load messages.
`;
+ console.error(err);
+ }
+ });
+}
+document.addEventListener('DOMContentLoaded', () => {
+ loadMessages();
+});
diff --git a/WebApp/wwwroot/js/userSkills.js b/WebApp/wwwroot/js/userSkills.js
index d227ad0..a06859e 100644
--- a/WebApp/wwwroot/js/userSkills.js
+++ b/WebApp/wwwroot/js/userSkills.js
@@ -35,7 +35,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
unhideElementById(document, "orgno");
}
}
- catch (_a) {
+ catch (e) {
window.location.href = "login.html";
}
var thisAccount = null;
@@ -63,7 +63,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
try {
const registeredIds = yield getMyRegisteredEventIds();
}
- catch (_b) {
+ catch (e) {
}
}
unhideElementById(document, "mainContainer");
@@ -76,7 +76,7 @@ window.onload = () => {
const skillName = dropdown.options[dropdown.selectedIndex].text;
const skillId = dropdown.options[dropdown.selectedIndex].value;
if (skillName) {
- addSkill(skillName, skillId, false);
+ addSkill(skillName, Number(skillId), false);
dropdown.value = ''; // Reset dropdown
}
});
diff --git a/WebApp/wwwroot/login.html b/WebApp/wwwroot/login.html
index 71c3a34..f3f7e82 100644
--- a/WebApp/wwwroot/login.html
+++ b/WebApp/wwwroot/login.html
@@ -37,7 +37,7 @@