54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const status = urlParams.get('status');
|
|
|
|
if (status) {
|
|
let message = '';
|
|
let type = 'success';
|
|
let title = 'Success!';
|
|
|
|
if (status === 'success') {
|
|
message = 'Your message has been sent successfully. We will get back to you shortly.';
|
|
} else if (status === 'error') {
|
|
message = 'There was an error sending your message. Please try again.';
|
|
type = 'danger';
|
|
title = 'Error!';
|
|
} else if (status === 'validation_error') {
|
|
message = 'Please fill out all fields correctly.';
|
|
type = 'warning';
|
|
title = 'Validation Error';
|
|
}
|
|
|
|
if (message) {
|
|
showToast(title, message, type);
|
|
// Clean the URL
|
|
window.history.replaceState({}, document.title, window.location.pathname);
|
|
}
|
|
}
|
|
});
|
|
|
|
function showToast(title, message, type = 'success') {
|
|
const toastContainer = document.getElementById('toast-container');
|
|
if (!toastContainer) return;
|
|
|
|
const toastId = 'toast-' + Date.now();
|
|
const toastHTML = `
|
|
<div id="${toastId}" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="toast-header bg-${type} text-white">
|
|
<strong class="me-auto">${title}</strong>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
<div class="toast-body">
|
|
${message}
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
toastContainer.insertAdjacentHTML('beforeend', toastHTML);
|
|
const toastElement = document.getElementById(toastId);
|
|
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
|
|
toast.show();
|
|
toastElement.addEventListener('hidden.bs.toast', () => {
|
|
toastElement.remove();
|
|
});
|
|
} |