<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('.pure-form');
const emailInput = document.querySelector('#field-customer-email');
const submitButton = document.querySelector('.button');
// select data-widget-id="internal-core_panes"
const panes = document.querySelector('[data-widget-id="internal-core_panes"]');
const firstPane = panes.children[0];
const secondPane = panes.children[1];
submitButton.addEventListener('click', function(event) {
// make API call to legacy Taxaroo API
fetch('https://app.taxaroo.com/login', {
method: 'POST',
body: JSON.stringify({ email: emailInput.value, password: '' }),
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(data => {
if (data?.pageErrors?.[0]?.msg === 'Incorrect password') { // if user exists
// if the API indicates the email is already in use, show an error message
firstPane.classList.add('checkout-pane-active');
secondPane.classList.remove('checkout-pane-active');
alert('This email is already in use. Please contact support@taxaroo.com for support.');
}
})
.catch(error => {
console.error('Error:', error);
});
// make API call to beta Taxaroo API
const betaAPIURL = 'https://3v3qd22r2u.us-east-1.awsapprunner.com/account/validEmail'; // prod
// const betaAPIURL = 'https://38vmkghmhd.us-east-1.awsapprunner.com'; // develop
fetch(betaAPIURL, {
method: 'POST',
body: JSON.stringify({ email: emailInput.value }),
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(data => {
console.log('data:', data)
if (!data) { // if user exists
// if the API indicates the email is already in use, show an error message
firstPane.classList.add('checkout-pane-active');
secondPane.classList.remove('checkout-pane-active');
alert('This email is already in use. Please login at https://beta.taxaroo.com.');
}
})
.catch(error => {
console.error('Error:', error);
});
});
});
</script>