Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3583 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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