@open-tender/utils 0.5.10 → 0.5.12
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.
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useMenuItemsFilter.d.ts +5 -0
- package/dist/cjs/hooks/useMenuItemsFilter.js +46 -0
- package/dist/cjs/utils/menu.d.ts +2 -1
- package/dist/cjs/utils/menu.js +13 -1
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useMenuItemsFilter.d.ts +5 -0
- package/dist/esm/hooks/useMenuItemsFilter.js +44 -0
- package/dist/esm/utils/menu.d.ts +2 -1
- package/dist/esm/utils/menu.js +11 -0
- package/package.json +3 -3
|
@@ -21,6 +21,7 @@ export * from './useGuestForm';
|
|
|
21
21
|
export * from './useGuestCheckoutForm';
|
|
22
22
|
export * from './useImage';
|
|
23
23
|
export * from './useMenuItem';
|
|
24
|
+
export * from './useMenuItemsFilter';
|
|
24
25
|
export * from './useModifier';
|
|
25
26
|
export * from './useModifierGroup';
|
|
26
27
|
export * from './useOneTimePasscodeForm';
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -24,6 +24,7 @@ tslib_1.__exportStar(require("./useGuestForm"), exports);
|
|
|
24
24
|
tslib_1.__exportStar(require("./useGuestCheckoutForm"), exports);
|
|
25
25
|
tslib_1.__exportStar(require("./useImage"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./useMenuItem"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./useMenuItemsFilter"), exports);
|
|
27
28
|
tslib_1.__exportStar(require("./useModifier"), exports);
|
|
28
29
|
tslib_1.__exportStar(require("./useModifierGroup"), exports);
|
|
29
30
|
tslib_1.__exportStar(require("./useOneTimePasscodeForm"), exports);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cloud_1 = require("@open-tender/cloud");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const useMenuItemsFilter = () => {
|
|
6
|
+
const { tagsFilter, allergensFilter } = (0, cloud_1.useAppSelector)(cloud_1.selectDisplaySettings) || {};
|
|
7
|
+
const { view_suspended_item } = (0, cloud_1.useAppSelector)(cloud_1.selectBrand) || {};
|
|
8
|
+
const { requestedAt } = (0, cloud_1.useAppSelector)(cloud_1.selectOrder);
|
|
9
|
+
const now = new Date();
|
|
10
|
+
const requestedDate = requestedAt === null || requestedAt === 'asap'
|
|
11
|
+
? now
|
|
12
|
+
: (0, utils_1.isoToDate)(requestedAt);
|
|
13
|
+
const selectedTagsNames = (0, cloud_1.useAppSelector)(cloud_1.selectSelectedTagNames);
|
|
14
|
+
const selectedAllergens = (0, cloud_1.useAppSelector)(cloud_1.selectSelectedAllergenNames);
|
|
15
|
+
const filterItems = (items) => {
|
|
16
|
+
if (!items)
|
|
17
|
+
return [];
|
|
18
|
+
return items.filter(item => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
// Filter by tags (included selected tags items)
|
|
21
|
+
if (selectedTagsNames.length && tagsFilter === 'SHOW_HIDE') {
|
|
22
|
+
const itemTags = ((_a = item.tags) === null || _a === void 0 ? void 0 : _a.split(', ')) || [];
|
|
23
|
+
if (!(0, utils_1.containsAny)(itemTags, selectedTagsNames)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Filter by allergens (exclude allergic items)
|
|
28
|
+
if (selectedAllergens.length && allergensFilter === 'SHOW_HIDE') {
|
|
29
|
+
const itemAllergens = ((_b = item.allergens) === null || _b === void 0 ? void 0 : _b.split(', ')) || [];
|
|
30
|
+
if ((0, utils_1.containsAny)(itemAllergens, selectedAllergens)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Filter by suspended until
|
|
35
|
+
if (item.suspend_until && view_suspended_item === 'HIDE') {
|
|
36
|
+
const suspendDate = new Date(item.suspend_until * 1000);
|
|
37
|
+
if (requestedDate < suspendDate) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
return { filterItems };
|
|
45
|
+
};
|
|
46
|
+
exports.default = useMenuItemsFilter;
|
package/dist/cjs/utils/menu.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
|
|
1
|
+
import { MenuCategories, MenuDisplayedSections, ThemeImagePosition, Timezone } from '@open-tender/types';
|
|
2
2
|
export declare const getBinaryArr: <T>(arr: T[]) => T[][];
|
|
3
3
|
export declare const makeItemChunks: <T extends {
|
|
4
4
|
id: number;
|
|
@@ -127,3 +127,4 @@ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
|
|
|
127
127
|
flexDirection: string;
|
|
128
128
|
alignItems: string;
|
|
129
129
|
};
|
|
130
|
+
export declare const makeSuspendUnitlMsg: (suspendedUntil: number, tz: Timezone, soldOutMessage: string | undefined, withTime?: boolean) => string;
|
package/dist/cjs/utils/menu.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMenuItemLayout = exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
|
|
3
|
+
exports.makeSuspendUnitlMsg = exports.makeMenuItemLayout = exports.makeFlatCategories = exports.makeOtherMenuSections = exports.makeItemChunks = exports.getBinaryArr = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
|
+
const datetimes_1 = require("./datetimes");
|
|
5
6
|
const getBinaryArr = (arr) => {
|
|
6
7
|
const result = [];
|
|
7
8
|
for (let i = 0; i < arr.length; i += 2) {
|
|
@@ -80,3 +81,14 @@ const makeMenuItemLayout = (position) => {
|
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
exports.makeMenuItemLayout = makeMenuItemLayout;
|
|
84
|
+
const makeSuspendUnitlMsg = (suspendedUntil, tz, soldOutMessage, withTime = true) => {
|
|
85
|
+
const suspendedUntilDate = suspendedUntil
|
|
86
|
+
? new Date(suspendedUntil * 1000)
|
|
87
|
+
: null;
|
|
88
|
+
const soldOutDynamicMsg = soldOutMessage === null || soldOutMessage === void 0 ? void 0 : soldOutMessage.replace('{{suspended_until}}', suspendedUntilDate
|
|
89
|
+
? (0, datetimes_1.makeReadableDateStrFromIso)(suspendedUntilDate.toISOString(), tz, false, withTime)
|
|
90
|
+
: '');
|
|
91
|
+
const soldOutMsg = soldOutDynamicMsg || 'Sold out for day';
|
|
92
|
+
return soldOutMsg;
|
|
93
|
+
};
|
|
94
|
+
exports.makeSuspendUnitlMsg = makeSuspendUnitlMsg;
|
|
@@ -21,6 +21,7 @@ export * from './useGuestForm';
|
|
|
21
21
|
export * from './useGuestCheckoutForm';
|
|
22
22
|
export * from './useImage';
|
|
23
23
|
export * from './useMenuItem';
|
|
24
|
+
export * from './useMenuItemsFilter';
|
|
24
25
|
export * from './useModifier';
|
|
25
26
|
export * from './useModifierGroup';
|
|
26
27
|
export * from './useOneTimePasscodeForm';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from './useGuestForm';
|
|
|
21
21
|
export * from './useGuestCheckoutForm';
|
|
22
22
|
export * from './useImage';
|
|
23
23
|
export * from './useMenuItem';
|
|
24
|
+
export * from './useMenuItemsFilter';
|
|
24
25
|
export * from './useModifier';
|
|
25
26
|
export * from './useModifierGroup';
|
|
26
27
|
export * from './useOneTimePasscodeForm';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { selectBrand, selectDisplaySettings, selectOrder, selectSelectedAllergenNames, selectSelectedTagNames, useAppSelector } from '@open-tender/cloud';
|
|
2
|
+
import { containsAny, isoToDate } from '../utils';
|
|
3
|
+
const useMenuItemsFilter = () => {
|
|
4
|
+
const { tagsFilter, allergensFilter } = useAppSelector(selectDisplaySettings) || {};
|
|
5
|
+
const { view_suspended_item } = useAppSelector(selectBrand) || {};
|
|
6
|
+
const { requestedAt } = useAppSelector(selectOrder);
|
|
7
|
+
const now = new Date();
|
|
8
|
+
const requestedDate = requestedAt === null || requestedAt === 'asap'
|
|
9
|
+
? now
|
|
10
|
+
: isoToDate(requestedAt);
|
|
11
|
+
const selectedTagsNames = useAppSelector(selectSelectedTagNames);
|
|
12
|
+
const selectedAllergens = useAppSelector(selectSelectedAllergenNames);
|
|
13
|
+
const filterItems = (items) => {
|
|
14
|
+
if (!items)
|
|
15
|
+
return [];
|
|
16
|
+
return items.filter(item => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
// Filter by tags (included selected tags items)
|
|
19
|
+
if (selectedTagsNames.length && tagsFilter === 'SHOW_HIDE') {
|
|
20
|
+
const itemTags = ((_a = item.tags) === null || _a === void 0 ? void 0 : _a.split(', ')) || [];
|
|
21
|
+
if (!containsAny(itemTags, selectedTagsNames)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Filter by allergens (exclude allergic items)
|
|
26
|
+
if (selectedAllergens.length && allergensFilter === 'SHOW_HIDE') {
|
|
27
|
+
const itemAllergens = ((_b = item.allergens) === null || _b === void 0 ? void 0 : _b.split(', ')) || [];
|
|
28
|
+
if (containsAny(itemAllergens, selectedAllergens)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Filter by suspended until
|
|
33
|
+
if (item.suspend_until && view_suspended_item === 'HIDE') {
|
|
34
|
+
const suspendDate = new Date(item.suspend_until * 1000);
|
|
35
|
+
if (requestedDate < suspendDate) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return { filterItems };
|
|
43
|
+
};
|
|
44
|
+
export default useMenuItemsFilter;
|
package/dist/esm/utils/menu.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MenuCategories, MenuDisplayedSections, ThemeImagePosition } from '@open-tender/types';
|
|
1
|
+
import { MenuCategories, MenuDisplayedSections, ThemeImagePosition, Timezone } from '@open-tender/types';
|
|
2
2
|
export declare const getBinaryArr: <T>(arr: T[]) => T[][];
|
|
3
3
|
export declare const makeItemChunks: <T extends {
|
|
4
4
|
id: number;
|
|
@@ -127,3 +127,4 @@ export declare const makeMenuItemLayout: (position: ThemeImagePosition) => {
|
|
|
127
127
|
flexDirection: string;
|
|
128
128
|
alignItems: string;
|
|
129
129
|
};
|
|
130
|
+
export declare const makeSuspendUnitlMsg: (suspendedUntil: number, tz: Timezone, soldOutMessage: string | undefined, withTime?: boolean) => string;
|
package/dist/esm/utils/menu.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { capitalize, slugify } from './helpers';
|
|
2
|
+
import { makeReadableDateStrFromIso } from './datetimes';
|
|
2
3
|
export const getBinaryArr = (arr) => {
|
|
3
4
|
const result = [];
|
|
4
5
|
for (let i = 0; i < arr.length; i += 2) {
|
|
@@ -72,3 +73,13 @@ export const makeMenuItemLayout = (position) => {
|
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
};
|
|
76
|
+
export const makeSuspendUnitlMsg = (suspendedUntil, tz, soldOutMessage, withTime = true) => {
|
|
77
|
+
const suspendedUntilDate = suspendedUntil
|
|
78
|
+
? new Date(suspendedUntil * 1000)
|
|
79
|
+
: null;
|
|
80
|
+
const soldOutDynamicMsg = soldOutMessage === null || soldOutMessage === void 0 ? void 0 : soldOutMessage.replace('{{suspended_until}}', suspendedUntilDate
|
|
81
|
+
? makeReadableDateStrFromIso(suspendedUntilDate.toISOString(), tz, false, withTime)
|
|
82
|
+
: '');
|
|
83
|
+
const soldOutMsg = soldOutDynamicMsg || 'Sold out for day';
|
|
84
|
+
return soldOutMsg;
|
|
85
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.12",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.134",
|
|
40
39
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
40
|
"@types/google.maps": "^3.53.5",
|
|
42
41
|
"@types/jest": "^29.5.11",
|
|
@@ -58,7 +57,8 @@
|
|
|
58
57
|
"typescript": "^4.8.2"
|
|
59
58
|
},
|
|
60
59
|
"peerDependencies": {
|
|
61
|
-
"@open-tender/
|
|
60
|
+
"@open-tender/cloud": "^0.5.15",
|
|
61
|
+
"@open-tender/types": "^0.4.138",
|
|
62
62
|
"@reduxjs/toolkit": "^1.8.5",
|
|
63
63
|
"react": "^18.2.0"
|
|
64
64
|
},
|