Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5309 stevensc 1
import { v1 } from 'uuid'
2
import { notificationActionTypes } from './notification.types'
1 www 3
 
4
const NotificationInitialState = {
5309 stevensc 5
  notifications: []
6
}
1 www 7
 
8
const notificationReducer = (
9
  state = NotificationInitialState,
10
  { type, payload }
11
) => {
12
  switch (type) {
13
    case notificationActionTypes.ADD_NOTIFICATION:
5309 stevensc 14
      const newNotification = { ...payload, id: v1() }
1 www 15
      return {
16
        ...state,
5309 stevensc 17
        notifications: [newNotification, ...state.notifications]
18
      }
1 www 19
    case notificationActionTypes.REMOVE_NOTIFICATION:
5309 stevensc 20
      const idToFilter = payload
1 www 21
      return {
22
        ...state,
23
        notifications: state.notifications.filter(
24
          (element) => element.id !== idToFilter
5309 stevensc 25
        )
26
      }
1 www 27
 
28
    default:
5309 stevensc 29
      return state
1 www 30
  }
5309 stevensc 31
}
1 www 32
 
5309 stevensc 33
export default notificationReducer