Once your order is completed, you will receive an email with TRACKING NUMBER and purchase DETAILS -how-to track
your order within 3 – 5 business days.
To track your order please enter your Order ID in the box below and press the “Track” button. This was given to
you on your receipt and in the confirmation email you should have received.
// Function to display events
function displayEvents(trackings) {
// Sample event data
const container = document.getElementById('eventsContainer');
container.innerHTML = '';
trackings.forEach(tracking => {
const trackingSubContainer = document.createElement('div');
trackingSubContainer.innerHTML = '';
trackingSubContainer.className = 'tracking-sub-container';
const trackingNumber = document.createElement('div')
trackingNumber.innerHTML = 'Track Number #' + tracking.tracking_number;
trackingNumber.className = 'tracking-number';
trackingSubContainer.appendChild(trackingNumber);
const checkpoints = tracking.checkpoints;
checkpoints.reverse().forEach(event => {
const eventDiv = document.createElement('div');
// Parse checkpoint_time to a Date object
const checkpointTime = new Date(event.checkpoint_time);
const dateOptions = { month: 'long', day: 'numeric' };
const timeOptions = { hour: '2-digit', minute: '2-digit', hour12: true };
const date = checkpointTime.toLocaleDateString(undefined, dateOptions);
const time = checkpointTime.toLocaleTimeString(undefined, timeOptions);
eventDiv.className = 'event';
eventDiv.innerHTML = `
${date}
${time}
${event.subtag_message ?? ''}
${event.location ?? ''}
`;
trackingSubContainer.appendChild(eventDiv);
console.log('Well')
});
container.appendChild(trackingSubContainer);
});
const backButton = document.createElement('div');
backButton.innerHTML = `
`;
container.appendChild(backButton);
container.style.display = 'block'; // Make the events container visible
const description = document.getElementById('formDescription');
const formContainer = document.getElementById('formContainer');
description.style.display = 'none';
formContainer.style.display = 'none';
}
function returnToForm() {
const container = document.getElementById('eventsContainer');
container.style.display = 'none';
const description = document.getElementById('formDescription');
const formContainer = document.getElementById('formContainer');
description.style.display = 'block';
formContainer.style.display = 'block';
}
async function trackOrder() {
const orderID = document.getElementById('orderID').value;
const email = document.getElementById('email').value;
if (!orderID) {
alert('Please enter order ID.');
return;
}
if (!validateEmail(email)) {
alert('Please enter a valid email address.');
return; // Stop the function if the email is not valid
}
console.log('Order ID:', orderID);
console.log('Email:', email);
// Create a spinner and add it to the button
// Get the button and change its content to the spinner
const trackButton = document.getElementById('trackButton');
const originalButtonContent = trackButton.innerHTML;
trackButton.innerHTML = '
';
try {
const body = {
orderId: orderID,
email,
};
// Call the API and wait for the response
const response = await fetch('https://trackorder-hivr7mqcmq-uc.a.run.app',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}
);
// Check if the request was successful
if (!response.ok) {
alert('Error: ' + response.statusText);
return;
}
// Parse the response body as JSON
const data = await response.json();
if (data) {
displayEvents(data);
}
else {
alert('No tracking information found.');
}
} catch (error) {
console.error('Error:', error);
} finally {
// Remove the spinner
trackButton.innerHTML = originalButtonContent;
}
}
function validateEmail(email) {
const pattern = /^[^s@]+@[^s@]+.[^s@]+$/;
return pattern.test(email);
}