diff --git a/client/login.html b/client/login.html new file mode 100644 index 0000000..cc41333 --- /dev/null +++ b/client/login.html @@ -0,0 +1,19 @@ + + + + + + +

Collin and Lucy's Wedding

+
+ + + + + + + +
+ + + \ No newline at end of file diff --git a/client/login.js b/client/login.js new file mode 100644 index 0000000..7e457bb --- /dev/null +++ b/client/login.js @@ -0,0 +1,7 @@ +function login() { + const usernameInput = document.getElementById('username'); + const passwordInput = document.getElementById('password'); + + const token = btoa(`${usernameInput.textContent}:${passwordInput.textContent}`); + document.cookie = `token=${String(token)}; path=/`; +} \ No newline at end of file diff --git a/client/rsvps_list.js b/client/rsvps_list.js index 93aeae6..6a7b4c5 100644 --- a/client/rsvps_list.js +++ b/client/rsvps_list.js @@ -1,11 +1,42 @@ function createRsvpEntry(rsvp) { + const table = document.getElementById('rsvpsTable'); + const tbody = table.children.item(0) + + const { attending, partyMembers } = rsvp; + for (const member of partyMembers) { + const newRow = document.createElement('tr'); + + const attendingColumn = document.createElement('td'); + attendingColumn.innerText = attending ? '✅' : '❌'; + + const nameColumn = document.createElement('td'); + nameColumn.innerText = member.name; + + const childColumn = document.createElement('td'); + childColumn.innerText = member.child ? '👶' : '🧓'; + + const dietaryPreferencesColumn = document.createElement('td'); + dietaryPreferencesColumn.innerText = member.dietaryPreferences.length > 0 ? member.dietaryPreferences : 'n/a'; + + newRow.appendChild(attendingColumn); + newRow.appendChild(nameColumn); + newRow.appendChild(childColumn); + newRow.appendChild(dietaryPreferencesColumn); + + tbody.appendChild(newRow); + } } async function getRsvps() { - // token is test:test for now - const resp = await fetch('/api/rsvps', { headers: { 'Authorization': 'Basic dGVzdDp0ZXN0'} }) - JSON.parse(resp.body) + const token = Object.fromEntries( + document.cookie.split(";").map((x) => x.trim().split("=")) + )['token'] + const resp = await fetch('/api/rsvps', { headers: { 'Authorization': `Basic ${token}`} }); + const rsvps = await resp.json() + for (const rsvp of rsvps) { + createRsvpEntry(rsvp); + } } window.onload = async function () {