Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1668 | Rev 3582 | 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() }
2311 stevensc 15
 
16
      const alreadyExist = state.notifications.find(
17
        (notification) => notification.msg === newNotification.msg
18
      )
19
 
20
      if (alreadyExist) return state
21
 
5 stevensc 22
      return {
23
        ...state,
24
        notifications: [newNotification, ...state.notifications]
25
      }
1668 stevensc 26
    }
27
    case notificationActionTypes.REMOVE_NOTIFICATION: {
5 stevensc 28
      const idToFilter = payload
29
      return {
30
        ...state,
31
        notifications: state.notifications.filter(
32
          (element) => element.id !== idToFilter
33
        )
34
      }
1668 stevensc 35
    }
5 stevensc 36
 
37
    default:
38
      return state
39
  }
40
}
41
 
42
export default notificationReducer