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

29 lines (28 loc) 1.16 kB
var _a; import { __spreadArray } from "tslib"; import { makeRandomNumberString } from '@open-tender/utils'; import { createSlice } from '@reduxjs/toolkit'; import { ReducerType } from './types'; var initialState = []; var alertsSlice = createSlice({ name: ReducerType.Alerts, initialState: initialState, reducers: { clearAlerts: function () { return initialState; }, addAlert: function (state, action) { return __spreadArray(__spreadArray([], state.reverse().slice(0, 4).reverse(), true), [ { message: action.payload, id: makeRandomNumberString() } ], false); }, dismissAlert: function (state, action) { return state.filter(function (i) { return i.id !== action.payload; }); // state.splice( // state.findIndex(i => i.id === action.payload), // 1 // ) } } }); export var clearAlerts = (_a = alertsSlice.actions, _a.clearAlerts), addAlert = _a.addAlert, dismissAlert = _a.dismissAlert; export var selectAlerts = function (state) { return state.alerts; }; export var alertsReducer = alertsSlice.reducer;