@open-tender/utils 0.4.9 → 0.4.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/__tests__/utils/helpers.test.js +24 -0
- package/dist/cjs/utils/helpers.d.ts +2 -0
- package/dist/cjs/utils/helpers.js +17 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/pizzaBuilder.d.ts +10 -0
- package/dist/cjs/utils/pizzaBuilder.js +42 -0
- package/dist/cjs/utils/refunds.d.ts +1 -1
- package/dist/cjs/utils/rewards.d.ts +3 -1
- package/dist/cjs/utils/rewards.js +71 -1
- package/dist/esm/__tests__/utils/helpers.test.js +25 -1
- package/dist/esm/utils/helpers.d.ts +2 -0
- package/dist/esm/utils/helpers.js +14 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/pizzaBuilder.d.ts +10 -0
- package/dist/esm/utils/pizzaBuilder.js +37 -0
- package/dist/esm/utils/refunds.d.ts +1 -1
- package/dist/esm/utils/rewards.d.ts +3 -1
- package/dist/esm/utils/rewards.js +69 -1
- package/package.json +3 -2
|
@@ -70,3 +70,27 @@ describe('containsAll', () => {
|
|
|
70
70
|
expect((0, utils_1.containsAll)([], [])).toBe(true);
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
|
+
describe('range', () => {
|
|
74
|
+
it('returns numbers array', () => {
|
|
75
|
+
expect((0, utils_1.range)(5)).toStrictEqual([0, 1, 2, 3, 4]);
|
|
76
|
+
expect((0, utils_1.range)(1, 5)).toStrictEqual([1, 2, 3, 4]);
|
|
77
|
+
expect((0, utils_1.range)(0, 20, 5)).toStrictEqual([0, 5, 10, 15]);
|
|
78
|
+
expect((0, utils_1.range)(0, -4, -1)).toStrictEqual([0, -1, -2, -3]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('sample', () => {
|
|
82
|
+
it('returns undefined for an empty array', () => {
|
|
83
|
+
expect((0, utils_1.sample)([])).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
it('returns a random element from the array', () => {
|
|
86
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
87
|
+
const result = (0, utils_1.sample)(numbers);
|
|
88
|
+
expect(numbers.includes(result)).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
it('returns only one of the elements of the array', () => {
|
|
91
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
92
|
+
const result = (0, utils_1.sample)(numbers);
|
|
93
|
+
expect(numbers).toContain(result);
|
|
94
|
+
expect(numbers.indexOf(result)).not.toBe(-1);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -59,3 +59,5 @@ export declare const hasEntities: <T extends unknown[]>(reducer: {
|
|
|
59
59
|
loading: RequestStatus;
|
|
60
60
|
error: RequestError;
|
|
61
61
|
}) => number | false;
|
|
62
|
+
export declare const range: (start: number, end?: number, step?: number) => number[];
|
|
63
|
+
export declare const sample: <T>(collection: T[]) => T | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatPercentage = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.containsAll = exports.containsAny = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
|
|
3
|
+
exports.sample = exports.range = exports.hasEntities = exports.convertStringToArray = exports.formatDollars = exports.formatPercentage = exports.formatQuantity = exports.addCommas = exports.displayPrice = exports.makeSlides = exports.makeImageUrl = exports.makeImageMap = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.checkNotFound = exports.checkGuestData = exports.checkEmpty = exports.validateEmail = exports.dashesToSlashes = exports.slashesToDashes = exports.makeBirthDate = exports.validatePhone = exports.makePhone = exports.cleanPhone = exports.capitalize = exports.serialize = exports.stripTags = exports.slugify = exports.containsAll = exports.containsAny = exports.contains = exports.isNum = exports.isEmpty = exports.isObject = exports.isString = void 0;
|
|
4
4
|
const isString = (str) => {
|
|
5
5
|
return typeof str === 'string';
|
|
6
6
|
};
|
|
@@ -226,3 +226,19 @@ const hasEntities = (reducer) => {
|
|
|
226
226
|
return !error && entities.length;
|
|
227
227
|
};
|
|
228
228
|
exports.hasEntities = hasEntities;
|
|
229
|
+
const range = (start, end, step = 1) => {
|
|
230
|
+
if (typeof end === 'undefined') {
|
|
231
|
+
end = start;
|
|
232
|
+
start = 0;
|
|
233
|
+
}
|
|
234
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
235
|
+
return Array.from({ length }, (_, index) => start + index * step);
|
|
236
|
+
};
|
|
237
|
+
exports.range = range;
|
|
238
|
+
const sample = (collection) => {
|
|
239
|
+
if (collection.length === 0)
|
|
240
|
+
return undefined;
|
|
241
|
+
const randomIndex = Math.floor(Math.random() * collection.length);
|
|
242
|
+
return collection[randomIndex];
|
|
243
|
+
};
|
|
244
|
+
exports.sample = sample;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { Amount, Coverage } from '@open-tender/types';
|
|
3
|
+
export declare const selectItemsWithEqualDistribution: (min: number, max: number, cellsCount: number, coverage: Coverage) => number[];
|
|
4
|
+
export declare const getCoverageMinMaxMap: (cellsCount: number) => Record<Coverage, {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const toppingAlignItems: Record<number, CSSProperties['alignItems']>;
|
|
9
|
+
export declare const toppingJustifyContent: Record<number, CSSProperties['justifyContent']>;
|
|
10
|
+
export declare const squareSizeMap: Record<Amount, number>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.squareSizeMap = exports.toppingJustifyContent = exports.toppingAlignItems = exports.getCoverageMinMaxMap = exports.selectItemsWithEqualDistribution = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const selectItemsWithEqualDistribution = (min, max, cellsCount, coverage) => {
|
|
6
|
+
const coverageCount = cellsCount / (coverage === 'whole' ? 1 : 2);
|
|
7
|
+
const itemsRange = (0, helpers_1.range)(min, max + 1);
|
|
8
|
+
const step = Math.ceil(itemsRange.length / coverageCount);
|
|
9
|
+
const selectedItems = [];
|
|
10
|
+
for (let i = 0; i < coverageCount; i++) {
|
|
11
|
+
const startIndex = i * step;
|
|
12
|
+
const endIndex = (i + 1) * step;
|
|
13
|
+
selectedItems.push((0, helpers_1.sample)(itemsRange.slice(startIndex, endIndex)));
|
|
14
|
+
}
|
|
15
|
+
return selectedItems;
|
|
16
|
+
};
|
|
17
|
+
exports.selectItemsWithEqualDistribution = selectItemsWithEqualDistribution;
|
|
18
|
+
const getCoverageMinMaxMap = (cellsCount) => ({
|
|
19
|
+
'1st-half': { min: cellsCount / 2, max: cellsCount - 1 },
|
|
20
|
+
'2nd-half': { min: 0, max: cellsCount / 2 - 1 },
|
|
21
|
+
whole: { min: 0, max: cellsCount - 1 }
|
|
22
|
+
});
|
|
23
|
+
exports.getCoverageMinMaxMap = getCoverageMinMaxMap;
|
|
24
|
+
exports.toppingAlignItems = {
|
|
25
|
+
0: 'flex-start',
|
|
26
|
+
1: 'center',
|
|
27
|
+
2: 'flex-end',
|
|
28
|
+
3: 'flex-end',
|
|
29
|
+
4: 'flex-start'
|
|
30
|
+
};
|
|
31
|
+
exports.toppingJustifyContent = {
|
|
32
|
+
0: 'flex-end',
|
|
33
|
+
1: 'center',
|
|
34
|
+
2: 'flex-start',
|
|
35
|
+
3: 'flex-end',
|
|
36
|
+
4: 'flex-start'
|
|
37
|
+
};
|
|
38
|
+
exports.squareSizeMap = {
|
|
39
|
+
extra: 8,
|
|
40
|
+
normal: 6,
|
|
41
|
+
light: 4
|
|
42
|
+
};
|
|
@@ -23,7 +23,7 @@ export declare const makeRefundLookup: (order: Order) => {
|
|
|
23
23
|
subtotal: `${number}.${number}`;
|
|
24
24
|
gift_card: `${number}.${number}`;
|
|
25
25
|
surcharge: `${number}.${number}`;
|
|
26
|
-
discount:
|
|
26
|
+
discount: import("@open-tender/types").NegativeMoney;
|
|
27
27
|
tax: `${number}.${number}`;
|
|
28
28
|
tip: `${number}.${number}`;
|
|
29
29
|
shipping: `${number}.${number}`;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
1
|
+
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
+
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
+
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeValidDeals = void 0;
|
|
3
|
+
exports.makeDiscountEnhanced = exports.makeLimitations = exports.makeValidDeals = void 0;
|
|
4
4
|
const datetimes_1 = require("./datetimes");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
5
6
|
const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
6
7
|
if (!deals || !deals.length)
|
|
7
8
|
return [];
|
|
@@ -34,3 +35,72 @@ const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
|
34
35
|
return deals;
|
|
35
36
|
};
|
|
36
37
|
exports.makeValidDeals = makeValidDeals;
|
|
38
|
+
const makeDiscountServiceType = (serviceType) => {
|
|
39
|
+
switch (serviceType) {
|
|
40
|
+
case 'WALKIN':
|
|
41
|
+
return 'In-store only';
|
|
42
|
+
case 'PICKUP':
|
|
43
|
+
return 'Pickup only';
|
|
44
|
+
case 'DELIVERY':
|
|
45
|
+
return 'Delivery only';
|
|
46
|
+
default:
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const makeDiscountOrderType = (orderType) => {
|
|
51
|
+
switch (orderType) {
|
|
52
|
+
case 'OLO':
|
|
53
|
+
return null;
|
|
54
|
+
case 'CATERING':
|
|
55
|
+
return 'Catering only';
|
|
56
|
+
case 'MERCH':
|
|
57
|
+
return 'Merch only';
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const makeChannelType = (channelType) => {
|
|
63
|
+
switch (channelType) {
|
|
64
|
+
case 'APP':
|
|
65
|
+
return 'App Only!';
|
|
66
|
+
case 'ONLINE':
|
|
67
|
+
return 'Online Only!';
|
|
68
|
+
case 'POS':
|
|
69
|
+
return 'At POS Only!';
|
|
70
|
+
case 'KIOSK':
|
|
71
|
+
return 'Kiosk Only!';
|
|
72
|
+
default:
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const makeLimitations = (item) => {
|
|
77
|
+
const { channel_type, order_type, service_type } = item;
|
|
78
|
+
const serviceType = makeDiscountServiceType(service_type);
|
|
79
|
+
const orderType = makeDiscountOrderType(order_type);
|
|
80
|
+
const channelType = channel_type && makeChannelType(channel_type);
|
|
81
|
+
const comma = serviceType && orderType ? ', ' : null;
|
|
82
|
+
const dash = (serviceType || orderType) && channelType ? ' - ' : null;
|
|
83
|
+
if (serviceType || orderType || channelType) {
|
|
84
|
+
return `
|
|
85
|
+
${serviceType}
|
|
86
|
+
${comma}
|
|
87
|
+
${orderType}
|
|
88
|
+
${dash}
|
|
89
|
+
${channelType}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
return 'Valid on all online & app orders';
|
|
93
|
+
};
|
|
94
|
+
exports.makeLimitations = makeLimitations;
|
|
95
|
+
const makeDiscountEnhanced = (item) => {
|
|
96
|
+
const today = (0, datetimes_1.makeLocalDateStr)(new Date(), 0, 'yyyy-MM-dd');
|
|
97
|
+
const imageMap = (0, helpers_1.makeImageMap)(item.images);
|
|
98
|
+
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
99
|
+
const todayOnly = item.end_date === today;
|
|
100
|
+
const expiration = item.end_date
|
|
101
|
+
? (0, datetimes_1.formatDateStr)(item.end_date, 'MMM d')
|
|
102
|
+
: null;
|
|
103
|
+
const limitations = (0, exports.makeLimitations)(item);
|
|
104
|
+
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
105
|
+
};
|
|
106
|
+
exports.makeDiscountEnhanced = makeDiscountEnhanced;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatPercentage, formatQuantity, containsAll, containsAny } from '../../utils';
|
|
1
|
+
import { formatPercentage, formatQuantity, containsAll, containsAny, range, sample } from '../../utils';
|
|
2
2
|
describe('formatPercentage', () => {
|
|
3
3
|
it('formats percentage when decimal is undefined', () => {
|
|
4
4
|
expect(formatPercentage('0')).toBe('0');
|
|
@@ -68,3 +68,27 @@ describe('containsAll', () => {
|
|
|
68
68
|
expect(containsAll([], [])).toBe(true);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
+
describe('range', () => {
|
|
72
|
+
it('returns numbers array', () => {
|
|
73
|
+
expect(range(5)).toStrictEqual([0, 1, 2, 3, 4]);
|
|
74
|
+
expect(range(1, 5)).toStrictEqual([1, 2, 3, 4]);
|
|
75
|
+
expect(range(0, 20, 5)).toStrictEqual([0, 5, 10, 15]);
|
|
76
|
+
expect(range(0, -4, -1)).toStrictEqual([0, -1, -2, -3]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('sample', () => {
|
|
80
|
+
it('returns undefined for an empty array', () => {
|
|
81
|
+
expect(sample([])).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
it('returns a random element from the array', () => {
|
|
84
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
85
|
+
const result = sample(numbers);
|
|
86
|
+
expect(numbers.includes(result)).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
it('returns only one of the elements of the array', () => {
|
|
89
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
90
|
+
const result = sample(numbers);
|
|
91
|
+
expect(numbers).toContain(result);
|
|
92
|
+
expect(numbers.indexOf(result)).not.toBe(-1);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -59,3 +59,5 @@ export declare const hasEntities: <T extends unknown[]>(reducer: {
|
|
|
59
59
|
loading: RequestStatus;
|
|
60
60
|
error: RequestError;
|
|
61
61
|
}) => number | false;
|
|
62
|
+
export declare const range: (start: number, end?: number, step?: number) => number[];
|
|
63
|
+
export declare const sample: <T>(collection: T[]) => T | undefined;
|
|
@@ -189,3 +189,17 @@ export const hasEntities = (reducer) => {
|
|
|
189
189
|
return false;
|
|
190
190
|
return !error && entities.length;
|
|
191
191
|
};
|
|
192
|
+
export const range = (start, end, step = 1) => {
|
|
193
|
+
if (typeof end === 'undefined') {
|
|
194
|
+
end = start;
|
|
195
|
+
start = 0;
|
|
196
|
+
}
|
|
197
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
198
|
+
return Array.from({ length }, (_, index) => start + index * step);
|
|
199
|
+
};
|
|
200
|
+
export const sample = (collection) => {
|
|
201
|
+
if (collection.length === 0)
|
|
202
|
+
return undefined;
|
|
203
|
+
const randomIndex = Math.floor(Math.random() * collection.length);
|
|
204
|
+
return collection[randomIndex];
|
|
205
|
+
};
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { Amount, Coverage } from '@open-tender/types';
|
|
3
|
+
export declare const selectItemsWithEqualDistribution: (min: number, max: number, cellsCount: number, coverage: Coverage) => number[];
|
|
4
|
+
export declare const getCoverageMinMaxMap: (cellsCount: number) => Record<Coverage, {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const toppingAlignItems: Record<number, CSSProperties['alignItems']>;
|
|
9
|
+
export declare const toppingJustifyContent: Record<number, CSSProperties['justifyContent']>;
|
|
10
|
+
export declare const squareSizeMap: Record<Amount, number>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { range, sample } from './helpers';
|
|
2
|
+
export const selectItemsWithEqualDistribution = (min, max, cellsCount, coverage) => {
|
|
3
|
+
const coverageCount = cellsCount / (coverage === 'whole' ? 1 : 2);
|
|
4
|
+
const itemsRange = range(min, max + 1);
|
|
5
|
+
const step = Math.ceil(itemsRange.length / coverageCount);
|
|
6
|
+
const selectedItems = [];
|
|
7
|
+
for (let i = 0; i < coverageCount; i++) {
|
|
8
|
+
const startIndex = i * step;
|
|
9
|
+
const endIndex = (i + 1) * step;
|
|
10
|
+
selectedItems.push(sample(itemsRange.slice(startIndex, endIndex)));
|
|
11
|
+
}
|
|
12
|
+
return selectedItems;
|
|
13
|
+
};
|
|
14
|
+
export const getCoverageMinMaxMap = (cellsCount) => ({
|
|
15
|
+
'1st-half': { min: cellsCount / 2, max: cellsCount - 1 },
|
|
16
|
+
'2nd-half': { min: 0, max: cellsCount / 2 - 1 },
|
|
17
|
+
whole: { min: 0, max: cellsCount - 1 }
|
|
18
|
+
});
|
|
19
|
+
export const toppingAlignItems = {
|
|
20
|
+
0: 'flex-start',
|
|
21
|
+
1: 'center',
|
|
22
|
+
2: 'flex-end',
|
|
23
|
+
3: 'flex-end',
|
|
24
|
+
4: 'flex-start'
|
|
25
|
+
};
|
|
26
|
+
export const toppingJustifyContent = {
|
|
27
|
+
0: 'flex-end',
|
|
28
|
+
1: 'center',
|
|
29
|
+
2: 'flex-start',
|
|
30
|
+
3: 'flex-end',
|
|
31
|
+
4: 'flex-start'
|
|
32
|
+
};
|
|
33
|
+
export const squareSizeMap = {
|
|
34
|
+
extra: 8,
|
|
35
|
+
normal: 6,
|
|
36
|
+
light: 4
|
|
37
|
+
};
|
|
@@ -23,7 +23,7 @@ export declare const makeRefundLookup: (order: Order) => {
|
|
|
23
23
|
subtotal: `${number}.${number}`;
|
|
24
24
|
gift_card: `${number}.${number}`;
|
|
25
25
|
surcharge: `${number}.${number}`;
|
|
26
|
-
discount:
|
|
26
|
+
discount: import("@open-tender/types").NegativeMoney;
|
|
27
27
|
tax: `${number}.${number}`;
|
|
28
28
|
tip: `${number}.${number}`;
|
|
29
29
|
shipping: `${number}.${number}`;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
1
|
+
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
+
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
+
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getMinutesfromDate, time24ToMinutes } from './datetimes';
|
|
1
|
+
import { formatDateStr, getMinutesfromDate, makeLocalDateStr, time24ToMinutes } from './datetimes';
|
|
2
|
+
import { makeImageMap } from './helpers';
|
|
2
3
|
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
3
4
|
if (!deals || !deals.length)
|
|
4
5
|
return [];
|
|
@@ -30,3 +31,70 @@ export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) =
|
|
|
30
31
|
});
|
|
31
32
|
return deals;
|
|
32
33
|
};
|
|
34
|
+
const makeDiscountServiceType = (serviceType) => {
|
|
35
|
+
switch (serviceType) {
|
|
36
|
+
case 'WALKIN':
|
|
37
|
+
return 'In-store only';
|
|
38
|
+
case 'PICKUP':
|
|
39
|
+
return 'Pickup only';
|
|
40
|
+
case 'DELIVERY':
|
|
41
|
+
return 'Delivery only';
|
|
42
|
+
default:
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const makeDiscountOrderType = (orderType) => {
|
|
47
|
+
switch (orderType) {
|
|
48
|
+
case 'OLO':
|
|
49
|
+
return null;
|
|
50
|
+
case 'CATERING':
|
|
51
|
+
return 'Catering only';
|
|
52
|
+
case 'MERCH':
|
|
53
|
+
return 'Merch only';
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const makeChannelType = (channelType) => {
|
|
59
|
+
switch (channelType) {
|
|
60
|
+
case 'APP':
|
|
61
|
+
return 'App Only!';
|
|
62
|
+
case 'ONLINE':
|
|
63
|
+
return 'Online Only!';
|
|
64
|
+
case 'POS':
|
|
65
|
+
return 'At POS Only!';
|
|
66
|
+
case 'KIOSK':
|
|
67
|
+
return 'Kiosk Only!';
|
|
68
|
+
default:
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const makeLimitations = (item) => {
|
|
73
|
+
const { channel_type, order_type, service_type } = item;
|
|
74
|
+
const serviceType = makeDiscountServiceType(service_type);
|
|
75
|
+
const orderType = makeDiscountOrderType(order_type);
|
|
76
|
+
const channelType = channel_type && makeChannelType(channel_type);
|
|
77
|
+
const comma = serviceType && orderType ? ', ' : null;
|
|
78
|
+
const dash = (serviceType || orderType) && channelType ? ' - ' : null;
|
|
79
|
+
if (serviceType || orderType || channelType) {
|
|
80
|
+
return `
|
|
81
|
+
${serviceType}
|
|
82
|
+
${comma}
|
|
83
|
+
${orderType}
|
|
84
|
+
${dash}
|
|
85
|
+
${channelType}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
return 'Valid on all online & app orders';
|
|
89
|
+
};
|
|
90
|
+
export const makeDiscountEnhanced = (item) => {
|
|
91
|
+
const today = makeLocalDateStr(new Date(), 0, 'yyyy-MM-dd');
|
|
92
|
+
const imageMap = makeImageMap(item.images);
|
|
93
|
+
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
94
|
+
const todayOnly = item.end_date === today;
|
|
95
|
+
const expiration = item.end_date
|
|
96
|
+
? formatDateStr(item.end_date, 'MMM d')
|
|
97
|
+
: null;
|
|
98
|
+
const limitations = makeLimitations(item);
|
|
99
|
+
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
100
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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,6 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
+
"@open-tender/types": "^0.4.34",
|
|
39
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
40
41
|
"@types/google.maps": "^3.53.5",
|
|
41
42
|
"@types/jest": "^29.5.11",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"typescript": "^4.8.2"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@open-tender/types": "^0.4.
|
|
61
|
+
"@open-tender/types": "^0.4.30",
|
|
61
62
|
"@reduxjs/toolkit": "^1.8.5",
|
|
62
63
|
"react": "^18.2.0"
|
|
63
64
|
},
|