wireui / wireui

TallStack UI components
https://v1.wireui.dev
MIT License
1.37k stars 166 forks source link

Add Notifications data to a redirect and show the notification on the destination page #542

Open Ameen10100 opened 1 year ago

Ameen10100 commented 1 year ago

If it's possible to add the feature where you can pass the notification to a redirect like the one displayed by livewire using session flash in this link https://laravel-livewire.com/docs/2.x/flash-messages

ibnIrshad commented 9 months ago

This can be achieved by adding this code snippet after <x-notifications/> in your main template. If someone can contribute this code snippet to the component itself


<x-notifications position="top-center"
                 z-index="z-[100]"/>

@foreach ($errors->all() as $error)
    <script>
        document.addEventListener("DOMContentLoaded", () => {
            window.$wireui.notify({title: '{{ $error }}', icon: 'error'});
        });
    </script>
@endforeach

@if (session('success'))
    <script>
        document.addEventListener("DOMContentLoaded", () => {
            window.$wireui.notify({title: '{{ session('success') }}', icon: 'success'});
        });
    </script>
@endif

</body>
</html>
farhanfarhan9 commented 3 months ago

I have the same issue, tried the code above but the notification is not trigger. One thing that works is with the wireui hooks

` @if (session('success'))

@endif

`

but the problem is even though the session is already missing the notification is still showing after click back to the the destination page @Ameen10100 @ibnIrshad @PH7-Jack