sulu

How to show an error message in a custom view in Sulu admin frontend?


I have added a custom view to a Sulu admin frontend, where I do some very custom things. Now, I want to be able to show an error message at the top of the site.

It should look like this:

enter image description here

But I do not know how to access the toolbar to add a Snackbar.

I am exporting my React component already with this addition:

export default withToolbar(MemberListUpload, function () {
    return {...};
});

So I am asking for a hint, how to add an error message to the toolbar at the top of the page.


Solution

  • You can just import the snackbarStore and push a message to it e.g.

    import snackbarStore from 'sulu-admin-bundle/stores/snackbarStore/snackbarStore';
    
    const message = {
        icon: 'su-ban', // https://jsdocs.sulu.io/2.5/#icon
        text: 'Text',
        type: 'error', // 'success' | 'error' | 'warning' | 'info'
    }
    
    snackbarStore.add(message, 2500);