-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
44 lines (38 loc) · 1.66 KB
/
users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function addToDashboard(opportunity) {
const userToken = localStorage.getItem("userToken");
if (!userToken) {
console.error("User token is missing. Authenticate the user first.");
return;
}
if (!initialized) {
fetch("http://localhost:3000/volunteer-opportunities/my-bookings", {
method: "GET",
headers: {
Authorization: `Bearer ${userToken}`,
},
})
.then((response) => {
if (!response.ok) {
throw new Error(HTTP`error! Status: ${response.status}`);
}
return response.json();
})
.then((opportunities) => {
const dashboardTable = document
.getElementById("dashboard-table")
.querySelector("tbody");
const row = dashboardTable.insertRow();
opportunities.forEach((opportunity) => {
const row = dashboardTable.insertRow(); // Move inside the loop
row.innerHTML = `
<td>${opportunity.title}</td>
<td>${opportunity.date}</td>
<td>${opportunity.location}</td>
<td><button class="unbook-button" onclick="unbookOpportunity('${opportunity._id}', this)">Unbook</button></td>
`;
});
initialized = true;
})
throw new Error(`HTTP error! Status: ${response.status}`);
}
}