Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 5 | Rev 1668 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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