chore(toasts): refactor and test flash to toast logic
This commit is contained in:
16
client/utils/flash-to-toast.js
Normal file
16
client/utils/flash-to-toast.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { makeToast } from '../../common/app/toasts/redux/actions';
|
||||
|
||||
export default function flashToToast(flash) {
|
||||
return Object.keys(flash)
|
||||
.map(key => {
|
||||
const messages = flash[key];
|
||||
return messages.map(message => ({
|
||||
message: message.msg,
|
||||
type: key,
|
||||
timeout: 5000
|
||||
}));
|
||||
})
|
||||
.reduce((toasts, messages) => toasts.concat(messages), [])
|
||||
.map(makeToast)
|
||||
.map(({ payload }) => payload);
|
||||
}
|
Reference in New Issue
Block a user