@open-tender/store 1.1.274 → 1.1.276

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,22 +6,14 @@ var hooks_1 = require("../app/hooks");
6
6
  var slices_1 = require("../slices");
7
7
  var Applied_1 = tslib_1.__importDefault(require("./Applied"));
8
8
  var Reward = function (_a) {
9
- var _b, _c;
10
9
  var reward = _a.reward, isLast = _a.isLast, index = _a.index, callback = _a.callback, children = _a.children, AppliedView = _a.AppliedView;
11
10
  var dispatch = (0, hooks_1.useAppDispatch)();
12
11
  var apiUrl = (0, hooks_1.useAppSelector)(slices_1.selectKioskApi);
13
- var _d = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig), config = _d.reward, cardConfig = _d.card;
12
+ var _b = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig), config = _b.reward, cardConfig = _b.card;
14
13
  var check = (0, hooks_1.useAppSelector)(slices_1.selectPosCheckout).check;
15
- var discountIdIndicesMap = new Map();
16
- check === null || check === void 0 ? void 0 : check.discounts.forEach(function (item, index) {
17
- var _a;
18
- if (!discountIdIndicesMap.has(item.id)) {
19
- discountIdIndicesMap.set(item.id, []);
20
- }
21
- (_a = discountIdIndicesMap.get(item.id)) === null || _a === void 0 ? void 0 : _a.push(index);
22
- });
14
+ var discounts = check === null || check === void 0 ? void 0 : check.discounts.map(function (i) { return [i.id, i.index]; });
23
15
  var id = reward.discount_id;
24
- var isApplied = (_c = (_b = discountIdIndicesMap.get(id)) === null || _b === void 0 ? void 0 : _b.includes(index)) !== null && _c !== void 0 ? _c : false;
16
+ var isApplied = !!(discounts === null || discounts === void 0 ? void 0 : discounts.includes([id, index]));
25
17
  var apply = function () {
26
18
  dispatch((0, slices_1.addDiscount)({ id: id, index: index }));
27
19
  if (callback)
@@ -521,13 +521,17 @@ var checkoutSlice = (0, toolkit_1.createSlice)({
521
521
  var id = action.payload.id;
522
522
  var discountIndex = action.payload.index;
523
523
  var discount = state.check
524
- ? state.check.discounts.find(function (item, index) { return item.id === id && index === discountIndex; })
524
+ ? state.check.discounts.find(function (item) {
525
+ return item.id === id && item.index === discountIndex;
526
+ })
525
527
  : null;
526
528
  if (discount && discount.discount_type === 'LOYALTY') {
527
529
  state.points = [];
528
530
  }
529
531
  else {
530
- state.discounts = state.discounts.filter(function (item, index) { return item.id !== id && index !== discountIndex; });
532
+ state.discounts = state.discounts.filter(function (item) {
533
+ return item.id !== id && item.index !== discountIndex;
534
+ });
531
535
  }
532
536
  },
533
537
  addTax: function (state, action) {
@@ -3,22 +3,14 @@ import { useAppDispatch, useAppSelector } from '../app/hooks';
3
3
  import { addDiscount, removeDiscount, selectKioskApi, selectKioskConfig, selectPosCheckout } from '../slices';
4
4
  import { default as AppliedContainer } from './Applied';
5
5
  var Reward = function (_a) {
6
- var _b, _c;
7
6
  var reward = _a.reward, isLast = _a.isLast, index = _a.index, callback = _a.callback, children = _a.children, AppliedView = _a.AppliedView;
8
7
  var dispatch = useAppDispatch();
9
8
  var apiUrl = useAppSelector(selectKioskApi);
10
- var _d = useAppSelector(selectKioskConfig), config = _d.reward, cardConfig = _d.card;
9
+ var _b = useAppSelector(selectKioskConfig), config = _b.reward, cardConfig = _b.card;
11
10
  var check = useAppSelector(selectPosCheckout).check;
12
- var discountIdIndicesMap = new Map();
13
- check === null || check === void 0 ? void 0 : check.discounts.forEach(function (item, index) {
14
- var _a;
15
- if (!discountIdIndicesMap.has(item.id)) {
16
- discountIdIndicesMap.set(item.id, []);
17
- }
18
- (_a = discountIdIndicesMap.get(item.id)) === null || _a === void 0 ? void 0 : _a.push(index);
19
- });
11
+ var discounts = check === null || check === void 0 ? void 0 : check.discounts.map(function (i) { return [i.id, i.index]; });
20
12
  var id = reward.discount_id;
21
- var isApplied = (_c = (_b = discountIdIndicesMap.get(id)) === null || _b === void 0 ? void 0 : _b.includes(index)) !== null && _c !== void 0 ? _c : false;
13
+ var isApplied = !!(discounts === null || discounts === void 0 ? void 0 : discounts.includes([id, index]));
22
14
  var apply = function () {
23
15
  dispatch(addDiscount({ id: id, index: index }));
24
16
  if (callback)
@@ -517,13 +517,17 @@ var checkoutSlice = createSlice({
517
517
  var id = action.payload.id;
518
518
  var discountIndex = action.payload.index;
519
519
  var discount = state.check
520
- ? state.check.discounts.find(function (item, index) { return item.id === id && index === discountIndex; })
520
+ ? state.check.discounts.find(function (item) {
521
+ return item.id === id && item.index === discountIndex;
522
+ })
521
523
  : null;
522
524
  if (discount && discount.discount_type === 'LOYALTY') {
523
525
  state.points = [];
524
526
  }
525
527
  else {
526
- state.discounts = state.discounts.filter(function (item, index) { return item.id !== id && index !== discountIndex; });
528
+ state.discounts = state.discounts.filter(function (item) {
529
+ return item.id !== id && item.index !== discountIndex;
530
+ });
527
531
  }
528
532
  },
529
533
  addTax: function (state, action) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/store",
3
- "version": "1.1.274",
3
+ "version": "1.1.276",
4
4
  "description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",