Files
portal-api/resources/views/administrator/layout/partials/toast.blade.php
T
2026-02-07 18:27:18 +07:00

74 lines
2.1 KiB
PHP

<!-- Notyf Dependencies -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css">
<script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
<!-- Toast Logic -->
<script type="text/javascript">
var notyf;
// Initialize Notyf
document.addEventListener('DOMContentLoaded', function () {
notyf = new Notyf({
duration: 5000,
position: {
x: 'right',
y: 'top',
},
types: [
{
type: 'success',
background: '#10b981',
dismissible: true
},
{
type: 'error',
background: '#ef4444',
dismissible: true
}
]
});
// Show alerts from session
setTimeout(function () {
showAlerts();
}, 100);
});
// Function to safely show toast notifications
function showToast(message, type = 'error', title = '') {
if (!notyf) {
console.warn('Notyf not initialized yet');
return false;
}
try {
if (type === 'success') {
notyf.success(message);
} else {
notyf.error(message);
}
return true;
} catch (e) {
console.error('Notyf failed:', e);
return false;
}
}
// Function to show alerts from Laravel session
function showAlerts() {
@if ($errors->any() || session()->has('success'))
@foreach ($errors->all() as $item)
showToast('{{ addslashes($item) }}', 'error');
@endforeach
@if (session()->has('success'))
showToast('{{ addslashes(session()->get('success')) }}', 'success');
@endif
@endif
}
// Compatibility layer with old FuiToast calls
window.FuiToast = {
success: function (message) { return showToast(message, 'success'); },
error: function (message) { return showToast(message, 'error'); }
};
</script>