Rev 1506 | Rev 2311 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import { v4 as uuid } from 'uuid'
import { notificationActionTypes } from './notification.types'
const NotificationInitialState = {
notifications: []
}
const notificationReducer = (
state = NotificationInitialState,
{ type, payload }
) => {
switch (type) {
case notificationActionTypes.ADD_NOTIFICATION: {
const newNotification = { ...payload, id: uuid() }
return {
...state,
notifications: [newNotification, ...state.notifications]
}
}
case notificationActionTypes.REMOVE_NOTIFICATION: {
const idToFilter = payload
return {
...state,
notifications: state.notifications.filter(
(element) => element.id !== idToFilter
)
}
}
default:
return state
}
}
export default notificationReducer