@open-tender/utils 0.5.9 → 0.5.11
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/useMenuItemsFilter.d.ts +5 -0
- package/dist/cjs/hooks/useMenuItemsFilter.js +46 -0
- package/dist/cjs/utils/datetimes.d.ts +1 -1
- package/dist/cjs/utils/datetimes.js +5 -3
- package/dist/cjs/utils/menu.d.ts +2 -1
- package/dist/cjs/utils/menu.js +13 -1
- package/dist/esm/hooks/useMenuItemsFilter.d.ts +5 -0
- package/dist/esm/hooks/useMenuItemsFilter.js +44 -0
- package/dist/esm/utils/datetimes.d.ts +1 -1
- package/dist/esm/utils/datetimes.js +5 -3
- package/dist/esm/utils/menu.d.ts +2 -1
- package/dist/esm/utils/menu.js +11 -0
- package/package.json +3 -3
|
@@ -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;
|
|
@@ -51,7 +51,7 @@ export declare const isoToDateStrMinutes: (iso: ISOString, tz: Timezone) => {
|
|
|
51
51
|
date: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
|
|
52
52
|
minutes: number;
|
|
53
53
|
};
|
|
54
|
-
export declare const makeReadableDateStrFromIso: (iso: string, tz: Timezone, verbose?: boolean) => string;
|
|
54
|
+
export declare const makeReadableDateStrFromIso: (iso: string, tz: Timezone, verbose?: boolean, withTime?: boolean) => string;
|
|
55
55
|
export declare const makeRequestedIso: (requestedAt: string) => string;
|
|
56
56
|
export declare const makeRequestedAtStr: (requestedAt: string | null, tz: Timezone, verbose?: boolean) => string;
|
|
57
57
|
export declare const makeEstimatedTime: (requestedAt: ISOString | string, revenueCenter: RevenueCenter, serviceType: ServiceType, verbose?: boolean) => string | null;
|
|
@@ -212,20 +212,22 @@ const isoToDateStrMinutes = (iso, tz) => {
|
|
|
212
212
|
return { date, minutes };
|
|
213
213
|
};
|
|
214
214
|
exports.isoToDateStrMinutes = isoToDateStrMinutes;
|
|
215
|
-
const makeReadableDateStrFromIso = (iso, tz, verbose = false) => {
|
|
215
|
+
const makeReadableDateStrFromIso = (iso, tz, verbose = false, withTime = true) => {
|
|
216
216
|
if (!iso || iso.toLowerCase() === 'asap')
|
|
217
217
|
return 'ASAP';
|
|
218
218
|
const date = (0, date_fns_tz_1.utcToZonedTime)((0, date_fns_1.parseISO)(iso), tz);
|
|
219
219
|
const timeString = (0, date_fns_tz_1.format)(date, exports.TIME).toLowerCase();
|
|
220
220
|
const dateString = (0, exports.makeLocalDateStr)(date);
|
|
221
221
|
if (dateString === (0, exports.todayDate)()) {
|
|
222
|
+
if (!withTime)
|
|
223
|
+
return 'Today';
|
|
222
224
|
return verbose ? `Today @ ${timeString}` : timeString;
|
|
223
225
|
}
|
|
224
226
|
else if (dateString === (0, exports.tomorrowDate)()) {
|
|
225
|
-
return `${verbose ? 'Tomorrow' : 'Tmrw'}
|
|
227
|
+
return `${verbose ? 'Tomorrow' : 'Tmrw'} ${withTime && `@ ${timeString}`}`;
|
|
226
228
|
}
|
|
227
229
|
else {
|
|
228
|
-
return `${verbose ? (0, date_fns_tz_1.format)(date, 'EEE, MMM d') : (0, date_fns_tz_1.format)(date, 'M/d')}
|
|
230
|
+
return `${verbose ? (0, date_fns_tz_1.format)(date, 'EEE, MMM d') : (0, date_fns_tz_1.format)(date, 'M/d')} ${withTime && `@ ${timeString}`}`;
|
|
229
231
|
}
|
|
230
232
|
};
|
|
231
233
|
exports.makeReadableDateStrFromIso = makeReadableDateStrFromIso;
|
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;
|
|
@@ -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;
|
|
@@ -51,7 +51,7 @@ export declare const isoToDateStrMinutes: (iso: ISOString, tz: Timezone) => {
|
|
|
51
51
|
date: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
|
|
52
52
|
minutes: number;
|
|
53
53
|
};
|
|
54
|
-
export declare const makeReadableDateStrFromIso: (iso: string, tz: Timezone, verbose?: boolean) => string;
|
|
54
|
+
export declare const makeReadableDateStrFromIso: (iso: string, tz: Timezone, verbose?: boolean, withTime?: boolean) => string;
|
|
55
55
|
export declare const makeRequestedIso: (requestedAt: string) => string;
|
|
56
56
|
export declare const makeRequestedAtStr: (requestedAt: string | null, tz: Timezone, verbose?: boolean) => string;
|
|
57
57
|
export declare const makeEstimatedTime: (requestedAt: ISOString | string, revenueCenter: RevenueCenter, serviceType: ServiceType, verbose?: boolean) => string | null;
|
|
@@ -173,20 +173,22 @@ export const isoToDateStrMinutes = (iso, tz) => {
|
|
|
173
173
|
const date = format(dateObj, DATE);
|
|
174
174
|
return { date, minutes };
|
|
175
175
|
};
|
|
176
|
-
export const makeReadableDateStrFromIso = (iso, tz, verbose = false) => {
|
|
176
|
+
export const makeReadableDateStrFromIso = (iso, tz, verbose = false, withTime = true) => {
|
|
177
177
|
if (!iso || iso.toLowerCase() === 'asap')
|
|
178
178
|
return 'ASAP';
|
|
179
179
|
const date = utcToZonedTime(parseISO(iso), tz);
|
|
180
180
|
const timeString = format(date, TIME).toLowerCase();
|
|
181
181
|
const dateString = makeLocalDateStr(date);
|
|
182
182
|
if (dateString === todayDate()) {
|
|
183
|
+
if (!withTime)
|
|
184
|
+
return 'Today';
|
|
183
185
|
return verbose ? `Today @ ${timeString}` : timeString;
|
|
184
186
|
}
|
|
185
187
|
else if (dateString === tomorrowDate()) {
|
|
186
|
-
return `${verbose ? 'Tomorrow' : 'Tmrw'}
|
|
188
|
+
return `${verbose ? 'Tomorrow' : 'Tmrw'} ${withTime && `@ ${timeString}`}`;
|
|
187
189
|
}
|
|
188
190
|
else {
|
|
189
|
-
return `${verbose ? format(date, 'EEE, MMM d') : format(date, 'M/d')}
|
|
191
|
+
return `${verbose ? format(date, 'EEE, MMM d') : format(date, 'M/d')} ${withTime && `@ ${timeString}`}`;
|
|
190
192
|
}
|
|
191
193
|
};
|
|
192
194
|
export const makeRequestedIso = (requestedAt) => {
|
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.11",
|
|
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
|
},
|