@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
33 lines (32 loc) • 1.42 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.alertsReducer = exports.selectAlerts = exports.dismissAlert = exports.addAlert = exports.clearAlerts = void 0;
var tslib_1 = require("tslib");
var utils_1 = require("@open-tender/utils");
var toolkit_1 = require("@reduxjs/toolkit");
var types_1 = require("./types");
var initialState = [];
var alertsSlice = (0, toolkit_1.createSlice)({
name: types_1.ReducerType.Alerts,
initialState: initialState,
reducers: {
clearAlerts: function () { return initialState; },
addAlert: function (state, action) {
return tslib_1.__spreadArray(tslib_1.__spreadArray([], state.reverse().slice(0, 4).reverse(), true), [
{ message: action.payload, id: (0, utils_1.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
// )
}
}
});
exports.clearAlerts = (_a = alertsSlice.actions, _a.clearAlerts), exports.addAlert = _a.addAlert, exports.dismissAlert = _a.dismissAlert;
var selectAlerts = function (state) { return state.alerts; };
exports.selectAlerts = selectAlerts;
exports.alertsReducer = alertsSlice.reducer;