2

I want to add server response message in CRUD response toaster. For Example when we do an update, we will get 'Element updated' toaster message. Instead of it I want to show some dynamic (not static) server responded message.

2 Answers2

1

This is only supported for error messages currently. If this is really important, please open a feature request and we'll consider it.

Gildas Garcia
  • 6,966
  • 3
  • 15
  • 29
1

A slightly long winded way to do this. But definitely possible.

1) Write a custom restWrapper or RestClient https://marmelab.com/admin-on-rest/RestClients.html

2) Handle the request and response from it like below.

function handleRequestAndResponse(url, options={}, showAlert={}) {
  return fetchUtils.fetchJson(url, options)
    .then((response) => {
      const {headers, json} = response;
      //admin on rest needs the {data} key
      const data = {data: json}
      if (headers.get('x-total-count')) {
        data.total = parseInt(headers.get('x-total-count').split('/').pop(), 10)
      }
      // handle get_list responses
      if (!isNaN(parseInt(headers.get('x-total-count'), 10))) {
        return {data: json,
                total: parseInt(headers.get('x-total-count').split('/').pop(), 10)}
      } else {
        return data
      }
  })
}

3) you now have a place in your code where you can intercept the data from the server. In above code you can define and shoot actions containing your data whenever you need. Create a reducer that takes the data from your action and populates a field in the state you can call it notification.

4) Use the redux-saga select method How to get something from the state / store inside a redux-saga function?

You can now access the notification data from the store and show custom toaster messages to your heart's content :)

kunal pareek
  • 1,285
  • 10
  • 21