36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
// Maps Livewire `toast` events → window.toastra.notify()
|
|
const TYPE_MAP = {
|
|
done: 'success',
|
|
warn: 'warning',
|
|
warning: 'warning',
|
|
error: 'error',
|
|
info: 'info',
|
|
default: 'default',
|
|
update: 'update',
|
|
};
|
|
|
|
function dispatchToast(detail) {
|
|
if (!window.toastra) return;
|
|
|
|
const { type = 'info', badge, title, text, duration } = detail || {};
|
|
|
|
window.toastra.notify({
|
|
type: TYPE_MAP[type] ?? 'info',
|
|
badge: badge ?? '',
|
|
title: title ?? '',
|
|
text: text ?? '',
|
|
duration: duration !== undefined ? duration : 4000,
|
|
close: true,
|
|
progressbar: true,
|
|
icon: true,
|
|
});
|
|
}
|
|
|
|
document.addEventListener('livewire:init', () => {
|
|
window.addEventListener('toast', (e) => dispatchToast(e?.detail || {}));
|
|
window.addEventListener('toast.clear', () => { /* Toastra hat kein clear-API */ });
|
|
window.addEventListener('toast.reload',(e) => setTimeout(() => window.location.reload(), e?.detail?.delay || 0));
|
|
});
|
|
|
|
window.showToast = dispatchToast;
|