Add loading spinner to buttons during Stripe redirect
This commit is contained in:
@@ -174,7 +174,8 @@
|
|||||||
selectedDonation = 'custom';
|
selectedDonation = 'custom';
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('donate-btn').addEventListener('click', async () => {
|
const donateBtn = document.getElementById('donate-btn');
|
||||||
|
donateBtn.addEventListener('click', async () => {
|
||||||
let donationCents = 0;
|
let donationCents = 0;
|
||||||
if (selectedDonation === 'custom') {
|
if (selectedDonation === 'custom') {
|
||||||
donationCents = (parseInt(document.getElementById('custom-amount').value) || 0) * 100;
|
donationCents = (parseInt(document.getElementById('custom-amount').value) || 0) * 100;
|
||||||
@@ -187,9 +188,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
donateBtn.loading = true;
|
||||||
|
donateBtn.disabled = true;
|
||||||
const data = await api('POST', `/api/donate/${eventId}`, { donationCents });
|
const data = await api('POST', `/api/donate/${eventId}`, { donationCents });
|
||||||
if (data.url) {
|
if (data.url) {
|
||||||
location.href = data.url;
|
location.href = data.url;
|
||||||
|
} else {
|
||||||
|
donateBtn.loading = false;
|
||||||
|
donateBtn.disabled = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -291,7 +291,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('rsvp-btn').addEventListener('click', async () => {
|
const rsvpBtn = document.getElementById('rsvp-btn');
|
||||||
|
rsvpBtn.addEventListener('click', async () => {
|
||||||
let donationCents = 0;
|
let donationCents = 0;
|
||||||
if (selectedDonation === 'custom') {
|
if (selectedDonation === 'custom') {
|
||||||
donationCents = (parseInt(document.getElementById('custom-amount').value) || 0) * 100;
|
donationCents = (parseInt(document.getElementById('custom-amount').value) || 0) * 100;
|
||||||
@@ -299,10 +300,16 @@
|
|||||||
donationCents = selectedDonation * 100;
|
donationCents = selectedDonation * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (donationCents > 0) {
|
||||||
|
rsvpBtn.loading = true;
|
||||||
|
rsvpBtn.disabled = true;
|
||||||
|
}
|
||||||
const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople: selectedNumPeople, donationCents });
|
const data = await api('POST', `/api/rsvp/${eventId}`, { numPeople: selectedNumPeople, donationCents });
|
||||||
if (data.url) {
|
if (data.url) {
|
||||||
location.href = data.url;
|
location.href = data.url;
|
||||||
} else {
|
} else {
|
||||||
|
rsvpBtn.loading = false;
|
||||||
|
rsvpBtn.disabled = false;
|
||||||
updateUI(data);
|
updateUI(data);
|
||||||
showConfirmation(data.numPeople, null);
|
showConfirmation(data.numPeople, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user