Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1506 | Rev 2311 | 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) {
1668 stevensc 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
      }
1668 stevensc 19
    }
20
    case notificationActionTypes.REMOVE_NOTIFICATION: {
5 stevensc 21
      const idToFilter = payload
22
      return {
23
        ...state,
24
        notifications: state.notifications.filter(
25
          (element) => element.id !== idToFilter
26
        )
27
      }
1668 stevensc 28
    }
5 stevensc 29
 
30
    default:
31
      return state
32
  }
33
}
34
 
35
export default notificationReducer