Finishing rsvps_list js and adding page to "login"
This commit is contained in:
parent
7e3b7d3f21
commit
2b6449f61b
3 changed files with 60 additions and 3 deletions
19
client/login.html
Normal file
19
client/login.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="title fontXL textCenter backgroundLightGreen colorWhite">Collin and Lucy's Wedding</h1>
|
||||
<div class="contents fontM">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" name="username" id="username">
|
||||
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password">
|
||||
|
||||
<button onclick="login">Login</button>
|
||||
</div>
|
||||
<script src="/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
7
client/login.js
Normal file
7
client/login.js
Normal file
|
|
@ -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=/`;
|
||||
}
|
||||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue