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

22 lines (21 loc) 956 B
var _a; import { makeRandomNumberString } from '@open-tender/utils'; import { createSlice } from '@reduxjs/toolkit'; import { ReducerType } from './types'; var initialState = []; var notificationsSlice = createSlice({ name: ReducerType.Notifications, initialState: initialState, reducers: { showNotification: function (state, action) { state.push({ message: action.payload, id: 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); } } }); export var showNotification = (_a = notificationsSlice.actions, _a.showNotification), hideNotification = _a.hideNotification; export var selectNotifications = function (state) { return state.notifications; }; export var notificationsReducer = notificationsSlice.reducer;