2025-11-13 13:38:11 +00:00

49 lines
1.7 KiB
JavaScript

window.addEventListener('DOMContentLoaded', (event) => {
const params = new URLSearchParams(window.location.search);
const status = params.get('status');
if (status) {
let message = '';
let type = '';
if (status === 'success') {
message = 'Thank you for joining the friends list!';
type = 'success';
} else if (status === 'error') {
message = 'There was an error with your submission. Please try again.';
type = 'danger';
}
if (message) {
showToast(message, type);
// Clean URL
window.history.replaceState({}, document.title, window.location.pathname);
}
}
});
function showToast(message, type = 'success') {
const toastContainer = document.getElementById('toast-container');
if (!toastContainer) return;
const toastId = 'toast-' + Date.now();
const toastHTML = `
<div id="${toastId}" class="toast align-items-center text-white bg-${type} border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
${message}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</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();
});
}