UNPKG

@open-tender/store

Version:

A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API

26 lines (25 loc) 1.21 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.notificationsReducer = exports.selectNotifications = exports.hideNotification = exports.showNotification = void 0; var utils_1 = require("@open-tender/utils"); var toolkit_1 = require("@reduxjs/toolkit"); var types_1 = require("./types"); var initialState = []; var notificationsSlice = (0, toolkit_1.createSlice)({ name: types_1.ReducerType.Notifications, initialState: initialState, reducers: { showNotification: function (state, action) { state.push({ message: action.payload, id: (0, utils_1.makeRandomNumberString)() }); }, hideNotification: function (state, action) { // state = state.filter(i => i.id !== action.payload) state.splice(state.findIndex(function (i) { return i.id === action.payload; }), 1); } } }); exports.showNotification = (_a = notificationsSlice.actions, _a.showNotification), exports.hideNotification = _a.hideNotification; var selectNotifications = function (state) { return state.notifications; }; exports.selectNotifications = selectNotifications; exports.notificationsReducer = notificationsSlice.reducer;