Rev 3583 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
import { generateUUID } from '@utils';import { notificationActionTypes } from './notification.types';const NotificationInitialState = {notifications: []};const notificationReducer = (state = NotificationInitialState, { type, payload }) => {switch (type) {case notificationActionTypes.ADD_NOTIFICATION: {const newNotification = { ...payload, id: generateUUID() };const alreadyExist = state.notifications.find((notification) => notification.msg === newNotification.msg);if (alreadyExist) return state;return {...state,notifications: [newNotification, ...state.notifications]};}case notificationActionTypes.REMOVE_NOTIFICATION: {const idToFilter = payload;return {...state,notifications: state.notifications.filter((element) => element.id !== idToFilter)};}default:return state;}};export default notificationReducer;