+
Make an additional donation?
-
+
+ $25
+ $50
+ $100
+ Other
+
+
$
- Donate
+ Donate
@@ -163,11 +185,48 @@
history.replaceState({}, '', location.pathname);
}
- document.querySelectorAll('input[name="donation"]').forEach(radio => {
- radio.addEventListener('change', () => {
- document.getElementById('custom-amount-row').style.display =
- radio.value === 'custom' && radio.checked ? 'flex' : 'none';
+ let selectedNumPeople = 1;
+ let selectedDonation = 25;
+
+ function setupButtonGroup(groupId, onChange) {
+ const group = document.getElementById(groupId);
+ group.querySelectorAll('wa-button').forEach(btn => {
+ btn.addEventListener('click', () => {
+ group.querySelectorAll('wa-button').forEach(b => b.variant = 'neutral');
+ btn.variant = 'brand';
+ onChange(btn.dataset.value);
+ });
});
+ }
+
+ setupButtonGroup('num-people-group', val => {
+ selectedNumPeople = parseInt(val);
+ });
+
+ setupButtonGroup('donation-group', val => {
+ selectedDonation = val === 'custom' ? 'custom' : (val === '0' ? 0 : parseInt(val));
+ document.getElementById('custom-amount-row').style.display = val === 'custom' ? 'flex' : 'none';
+ });
+
+ setupButtonGroup('num-people-update-group', async val => {
+ const numPeople = parseInt(val);
+ const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople });
+ updateUI(data);
+ });
+
+ setupButtonGroup('additional-donation-group', async val => {
+ if (val === 'custom') {
+ document.getElementById('additional-custom-row').style.display = 'flex';
+ } else {
+ await startDonation(parseInt(val));
+ }
+ });
+
+ document.getElementById('additional-custom-btn').addEventListener('click', async () => {
+ const amount = parseInt(document.getElementById('additional-amount').value) || 0;
+ if (amount > 0) {
+ await startDonation(amount);
+ }
});
async function loadRSVP() {
@@ -181,7 +240,6 @@
document.getElementById('rsvp-status').style.display = 'block';
const word = data.numPeople === 1 ? 'person' : 'people';
document.getElementById('rsvp-message').textContent = `You're RSVPed for ${data.numPeople} ${word}.`;
- document.getElementById('num-people-update').value = data.numPeople;
if (data.donation > 0) {
document.getElementById('donation-status').textContent = `You've donated $${data.donation.toFixed(2)}. Thank you!`;
} else {
@@ -193,44 +251,24 @@
}
}
- function getSelectedDonation() {
- const selected = document.querySelector('input[name="donation"]:checked');
- if (!selected || selected.value === '0') return 0;
- if (selected.value === 'custom') {
- return parseInt(document.getElementById('custom-amount').value) || 0;
- }
- return parseInt(selected.value);
- }
-
async function startDonation(amount) {
const data = await api('POST', `/api/donate/${eventId}`, { amount: amount * 100 });
location.href = data.url;
}
document.getElementById('rsvp-btn').addEventListener('click', async () => {
- const numPeople = parseInt(document.getElementById('num-people').value) || 1;
- const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople });
+ const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople: selectedNumPeople });
updateUI(data);
- const donationAmount = getSelectedDonation();
+ let donationAmount = selectedDonation;
+ if (donationAmount === 'custom') {
+ donationAmount = parseInt(document.getElementById('custom-amount').value) || 0;
+ }
if (donationAmount > 0) {
await startDonation(donationAmount);
}
});
- document.getElementById('update-btn').addEventListener('click', async () => {
- const numPeople = parseInt(document.getElementById('num-people-update').value) || 0;
- const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople });
- updateUI(data);
- });
-
- document.getElementById('donate-btn').addEventListener('click', async () => {
- const amount = parseInt(document.getElementById('additional-amount').value) || 0;
- if (amount > 0) {
- await startDonation(amount);
- }
- });
-
await loadRSVP();
await customElements.whenDefined('wa-card');