Skip to content

Commit

Permalink
no pembroke no pickup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomConner committed Nov 22, 2023
1 parent 8f01f3d commit d1db7e7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions generator/content/register/stripe-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,23 @@ document.addEventListener('DOMContentLoaded', async () => {
// on address input, save address in localStorage
addressElement.on('change', (event) => {
console.debug(event);//TODO REMOVE
if (event.complete){
if (event.error) {
validateAddress(event);
} else if (event.complete) {
// Extract potentially complete address
const address = event.value;
console.debug("address complete");
console.debug(address);
setLocalItem("address", JSON.stringify(address));
validateAddress();
}
if (event.error) {
showAddressMessage(event.error.message);
} else {
clearAddressMessage();
validateAddress(null);
}
});

function validateAddress() {
function validateAddress(event) {
const address = JSON.parse(getLocalItem("address"));
if (!(address.address.city.toLowerCase() === "Pembroke".toLowerCase())) {
if (event && event.error) {
showAddressMessage(event.error.message);
} else if (!(address.address.city.toLowerCase() === "Pembroke".toLowerCase())) {
showAddressMessage("Sorry, we can only pick up trees from Pembroke.");
return false;
}
Expand All @@ -151,7 +150,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const buttonRegister = document.getElementById('button-register');
buttonRegister.addEventListener('click', async (e) => {
e.preventDefault();
if (!validateAddress()) {
if (!validateAddress(null)) {
return;
}
const address = JSON.parse(getLocalItem("address"));
Expand Down

0 comments on commit d1db7e7

Please sign in to comment.