@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
90 lines (89 loc) • 3.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.offlineAuthsReducer = exports.selectOfflineAuths = exports.resetOfflineAuths = exports.processOfflineAuths = exports.fetchOfflineAuths = exports.OfflineAuthsActionType = void 0;
var tslib_1 = require("tslib");
var toolkit_1 = require("@reduxjs/toolkit");
var types_1 = require("./types");
var initialState = {
entities: [],
loading: 'idle',
error: null,
result: null
};
var OfflineAuthsActionType;
(function (OfflineAuthsActionType) {
OfflineAuthsActionType["FetchOfflineAuths"] = "offlineAuths/getOfflineAuths";
OfflineAuthsActionType["ProcessOfflineAuths"] = "offlineAuths/processOfflineAuths";
})(OfflineAuthsActionType || (exports.OfflineAuthsActionType = OfflineAuthsActionType = {}));
exports.fetchOfflineAuths = (0, toolkit_1.createAsyncThunk)(OfflineAuthsActionType.FetchOfflineAuths, function (_1, _a) { return tslib_1.__awaiter(void 0, [_1, _a], void 0, function (_, _b) {
var api, err_1;
var getState = _b.getState, rejectWithValue = _b.rejectWithValue;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2, , 3]);
api = getState().config.api;
return [4 /*yield*/, api.getOfflineAuths()];
case 1: return [2 /*return*/, _c.sent()];
case 2:
err_1 = _c.sent();
return [2 /*return*/, rejectWithValue(err_1)];
case 3: return [2 /*return*/];
}
});
}); });
exports.processOfflineAuths = (0, toolkit_1.createAsyncThunk)(OfflineAuthsActionType.ProcessOfflineAuths, function (_1, _a) { return tslib_1.__awaiter(void 0, [_1, _a], void 0, function (_, _b) {
var api, err_2;
var getState = _b.getState, rejectWithValue = _b.rejectWithValue;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2, , 3]);
api = getState().config.api;
return [4 /*yield*/, api.postOfflineAuths()];
case 1: return [2 /*return*/, _c.sent()];
case 2:
err_2 = _c.sent();
return [2 /*return*/, rejectWithValue(err_2)];
case 3: return [2 /*return*/];
}
});
}); });
var offlineAuthsSlice = (0, toolkit_1.createSlice)({
name: types_1.ReducerType.OfflineAuths,
initialState: initialState,
reducers: {
resetOfflineAuths: function () { return initialState; }
},
extraReducers: function (builder) {
builder
.addCase(exports.fetchOfflineAuths.fulfilled, function (state, action) {
state.entities = action.payload || [];
state.loading = 'idle';
state.error = null;
})
.addCase(exports.fetchOfflineAuths.pending, function (state) {
state.loading = 'pending';
})
.addCase(exports.fetchOfflineAuths.rejected, function (state, action) {
state.error = action.payload;
state.loading = 'idle';
})
.addCase(exports.processOfflineAuths.fulfilled, function (state, action) {
state.result = action.payload;
state.loading = 'idle';
state.error = null;
})
.addCase(exports.processOfflineAuths.pending, function (state) {
state.loading = 'pending';
})
.addCase(exports.processOfflineAuths.rejected, function (state, action) {
state.error = action.payload;
state.loading = 'idle';
});
}
});
exports.resetOfflineAuths = offlineAuthsSlice.actions.resetOfflineAuths;
var selectOfflineAuths = function (state) { return state.offlineAuths; };
exports.selectOfflineAuths = selectOfflineAuths;
exports.offlineAuthsReducer = offlineAuthsSlice.reducer;