Add enhanced toast notifications for moderation actions

- Add color-coded toast notifications for different actions
- Use appropriate icons for each action type
- Improve toast positioning and z-index
- Add smooth transitions for better UX
- Remove duplicate toast implementation
This commit is contained in:
pacnpal
2024-11-13 22:02:59 +00:00
parent 8265348a83
commit edc9d66849

View File

@@ -103,30 +103,71 @@
</div> </div>
</div> </div>
<div id="toast-success" <div id="toast-container"
class="fixed flex items-center w-full max-w-xs p-4 mb-4 text-gray-400 transition-all duration-300 transform translate-y-full bg-gray-800 rounded-lg shadow opacity-0 bottom-4 right-4" x-data="{
role="alert" show: false,
x-data="{ show: false }" message: '',
x-show="show" icon: 'check',
x-init="$watch('show', value => { color: 'green',
if (value) { showToast(msg, icn = 'check', clr = 'green') {
setTimeout(() => show = false, 3000); this.message = msg;
} this.icon = icn;
})" this.color = clr;
@htmx:afterOnLoad="show = true" this.show = true;
x-transition:enter="ease-out duration-300" setTimeout(() => this.show = false, 3000);
x-transition:enter-start="opacity-0 translate-y-full" }
x-transition:enter-end="opacity-100 translate-y-0" }"
x-transition:leave="ease-in duration-200" @submission-approved.window="showToast('Submission approved successfully', 'check', 'green')"
x-transition:leave-start="opacity-100 translate-y-0" @submission-rejected.window="showToast('Submission rejected', 'times', 'red')"
x-transition:leave-end="opacity-0 translate-y-full"> @submission-escalated.window="showToast('Submission escalated', 'exclamation-triangle', 'yellow')"
<div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-green-400 rounded-lg bg-green-900/40"> @submission-updated.window="showToast('Changes saved successfully', 'check', 'blue')"
<i class="fas fa-check"></i> class="fixed z-50 bottom-4 right-4">
<div x-show="show"
x-transition:enter="ease-out duration-300"
x-transition:enter-start="opacity-0 translate-y-full"
x-transition:enter-end="opacity-100 translate-y-0"
x-transition:leave="ease-in duration-200"
x-transition:leave-start="opacity-100 translate-y-0"
x-transition:leave-end="opacity-0 translate-y-full"
class="flex items-center w-full max-w-xs p-4 text-gray-400 bg-gray-800 rounded-lg shadow">
<div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 rounded-lg"
:class="{
'text-green-400 bg-green-900/40': color === 'green',
'text-red-400 bg-red-900/40': color === 'red',
'text-yellow-400 bg-yellow-900/40': color === 'yellow',
'text-blue-400 bg-blue-900/40': color === 'blue'
}">
<i class="fas" :class="'fa-' + icon"></i>
</div>
<div class="ml-3 text-sm font-normal" x-text="message"></div>
<button type="button"
class="ml-auto -mx-1.5 -my-1.5 text-gray-400 hover:text-gray-300 rounded-lg p-1.5 inline-flex h-8 w-8"
@click="show = false">
<i class="fas fa-times"></i>
</button>
</div> </div>
<div class="ml-3 text-sm font-normal" id="toast-message">Status updated successfully</div>
<button type="button"
class="ml-auto -mx-1.5 -my-1.5 text-gray-400 hover:text-gray-300 rounded-lg p-1.5 inline-flex h-8 w-8"
@click="show = false">
<i class="fas fa-times"></i>
</button>
</div> </div>
<script>
document.body.addEventListener('htmx:afterRequest', function(evt) {
if (evt.detail.successful) {
const path = evt.detail.requestConfig.path;
let event;
if (path.includes('approve')) {
event = new CustomEvent('submission-approved');
} else if (path.includes('reject')) {
event = new CustomEvent('submission-rejected');
} else if (path.includes('escalate')) {
event = new CustomEvent('submission-escalated');
} else if (path.includes('edit')) {
event = new CustomEvent('submission-updated');
}
if (event) {
window.dispatchEvent(event);
}
}
});
</script>