Proyectos de Subversion LeadersLinked - SPA

Rev

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

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