@open-tender/utils 0.1.0 → 0.1.2
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/useImage.d.ts +1 -1
- package/dist/cjs/hooks/useImage.js +2 -1
- package/dist/cjs/utils/cart.js +9 -15
- package/dist/cjs/utils/helpers.d.ts +1 -23
- package/dist/esm/hooks/useImage.d.ts +1 -1
- package/dist/esm/hooks/useImage.js +2 -1
- package/dist/esm/utils/cart.js +9 -15
- package/dist/esm/utils/helpers.d.ts +1 -23
- package/package.json +1 -1
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -605,16 +605,14 @@ const makeItemLookup = (categories, itemIds) => {
|
|
|
605
605
|
const itemLookup = {};
|
|
606
606
|
categories.forEach(category => {
|
|
607
607
|
category.items.forEach(item => {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = (0, exports.makeOrderItem)(item, true);
|
|
608
|
+
if (itemIds.includes(item.id)) {
|
|
609
|
+
itemLookup[item.id] = (0, exports.makeOrderItem)(item, true);
|
|
611
610
|
}
|
|
612
611
|
});
|
|
613
612
|
category.children.forEach(child => {
|
|
614
613
|
child.items.forEach(item => {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = (0, exports.makeOrderItem)(item, true);
|
|
614
|
+
if (itemIds.includes(item.id)) {
|
|
615
|
+
itemLookup[item.id] = (0, exports.makeOrderItem)(item, true);
|
|
618
616
|
}
|
|
619
617
|
});
|
|
620
618
|
});
|
|
@@ -623,18 +621,14 @@ const makeItemLookup = (categories, itemIds) => {
|
|
|
623
621
|
};
|
|
624
622
|
// TODO: refactor for nested modifiers
|
|
625
623
|
const makeGroupsLookup = (item) => {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
var _a;
|
|
629
|
-
const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
|
|
624
|
+
return item.groups.reduce((grpObj, i) => {
|
|
625
|
+
const options = i.options.reduce((optObj, o) => {
|
|
630
626
|
if (o.id) {
|
|
631
627
|
optObj[o.id] = o;
|
|
632
628
|
}
|
|
633
629
|
return optObj;
|
|
634
630
|
}, {});
|
|
635
|
-
|
|
636
|
-
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
637
|
-
}
|
|
631
|
+
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
638
632
|
return grpObj;
|
|
639
633
|
}, {});
|
|
640
634
|
};
|
|
@@ -658,9 +652,9 @@ const validateCart = (cart, categories, soldOut) => {
|
|
|
658
652
|
const invalidOptions = [];
|
|
659
653
|
const newGroups = makeGroupsLookup(newItem);
|
|
660
654
|
// check if any required groups for the new item are missing from the old item
|
|
661
|
-
const newRequiredGroups = Object.values(newGroups).filter(
|
|
655
|
+
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
662
656
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
663
|
-
missingGroups = newRequiredGroups.filter(
|
|
657
|
+
missingGroups = newRequiredGroups.filter(i => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
|
|
664
658
|
const newEmptyGroups = Object.values(newGroups)
|
|
665
659
|
.filter((i) => {
|
|
666
660
|
return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
|
|
@@ -29,29 +29,7 @@ export declare const makeRandomNumberString: () => string;
|
|
|
29
29
|
export declare const getWidth: () => number;
|
|
30
30
|
export declare const getHeight: () => number;
|
|
31
31
|
export declare const makeImageUrl: (images: ContentImages, isMobile: boolean) => string | null | undefined;
|
|
32
|
-
export declare const makeSlides: (items: Announcements, isMobile: boolean) =>
|
|
33
|
-
imageUrl: string | null | undefined;
|
|
34
|
-
announcement_id: number;
|
|
35
|
-
display_order: number;
|
|
36
|
-
hide_text: boolean;
|
|
37
|
-
hide_text_mobile: boolean;
|
|
38
|
-
horizontal: string;
|
|
39
|
-
images: ContentImages;
|
|
40
|
-
overlay_color: string;
|
|
41
|
-
overlay_opacity: number;
|
|
42
|
-
show_overlay: boolean;
|
|
43
|
-
subtitle: string;
|
|
44
|
-
subtitle_color: string;
|
|
45
|
-
subtitle_size: string | number | null;
|
|
46
|
-
text_color: string;
|
|
47
|
-
title: string;
|
|
48
|
-
title_color: string;
|
|
49
|
-
title_size: string | number | null;
|
|
50
|
-
url: string | null;
|
|
51
|
-
url_text: string | null;
|
|
52
|
-
vertical: string;
|
|
53
|
-
imageUri?: string | undefined;
|
|
54
|
-
}[] | null;
|
|
32
|
+
export declare const makeSlides: (items: Announcements, isMobile: boolean) => Announcements | null;
|
|
55
33
|
export declare const displayPrice: (price: string) => string;
|
|
56
34
|
export declare const addCommas: (x: number, d: number) => string;
|
|
57
35
|
export declare const formatQuantity: (n: string) => string;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -574,16 +574,14 @@ const makeItemLookup = (categories, itemIds) => {
|
|
|
574
574
|
const itemLookup = {};
|
|
575
575
|
categories.forEach(category => {
|
|
576
576
|
category.items.forEach(item => {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = makeOrderItem(item, true);
|
|
577
|
+
if (itemIds.includes(item.id)) {
|
|
578
|
+
itemLookup[item.id] = makeOrderItem(item, true);
|
|
580
579
|
}
|
|
581
580
|
});
|
|
582
581
|
category.children.forEach(child => {
|
|
583
582
|
child.items.forEach(item => {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
itemLookup[(_b = item.id) !== null && _b !== void 0 ? _b : 0] = makeOrderItem(item, true);
|
|
583
|
+
if (itemIds.includes(item.id)) {
|
|
584
|
+
itemLookup[item.id] = makeOrderItem(item, true);
|
|
587
585
|
}
|
|
588
586
|
});
|
|
589
587
|
});
|
|
@@ -592,18 +590,14 @@ const makeItemLookup = (categories, itemIds) => {
|
|
|
592
590
|
};
|
|
593
591
|
// TODO: refactor for nested modifiers
|
|
594
592
|
const makeGroupsLookup = (item) => {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
var _a;
|
|
598
|
-
const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
|
|
593
|
+
return item.groups.reduce((grpObj, i) => {
|
|
594
|
+
const options = i.options.reduce((optObj, o) => {
|
|
599
595
|
if (o.id) {
|
|
600
596
|
optObj[o.id] = o;
|
|
601
597
|
}
|
|
602
598
|
return optObj;
|
|
603
599
|
}, {});
|
|
604
|
-
|
|
605
|
-
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
606
|
-
}
|
|
600
|
+
grpObj[i.id] = Object.assign(Object.assign({}, i), { options });
|
|
607
601
|
return grpObj;
|
|
608
602
|
}, {});
|
|
609
603
|
};
|
|
@@ -627,9 +621,9 @@ export const validateCart = (cart, categories, soldOut) => {
|
|
|
627
621
|
const invalidOptions = [];
|
|
628
622
|
const newGroups = makeGroupsLookup(newItem);
|
|
629
623
|
// check if any required groups for the new item are missing from the old item
|
|
630
|
-
const newRequiredGroups = Object.values(newGroups).filter(
|
|
624
|
+
const newRequiredGroups = Object.values(newGroups).filter(i => i.min > 0);
|
|
631
625
|
const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
|
|
632
|
-
missingGroups = newRequiredGroups.filter(
|
|
626
|
+
missingGroups = newRequiredGroups.filter(i => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
|
|
633
627
|
const newEmptyGroups = Object.values(newGroups)
|
|
634
628
|
.filter((i) => {
|
|
635
629
|
return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
|
|
@@ -29,29 +29,7 @@ export declare const makeRandomNumberString: () => string;
|
|
|
29
29
|
export declare const getWidth: () => number;
|
|
30
30
|
export declare const getHeight: () => number;
|
|
31
31
|
export declare const makeImageUrl: (images: ContentImages, isMobile: boolean) => string | null | undefined;
|
|
32
|
-
export declare const makeSlides: (items: Announcements, isMobile: boolean) =>
|
|
33
|
-
imageUrl: string | null | undefined;
|
|
34
|
-
announcement_id: number;
|
|
35
|
-
display_order: number;
|
|
36
|
-
hide_text: boolean;
|
|
37
|
-
hide_text_mobile: boolean;
|
|
38
|
-
horizontal: string;
|
|
39
|
-
images: ContentImages;
|
|
40
|
-
overlay_color: string;
|
|
41
|
-
overlay_opacity: number;
|
|
42
|
-
show_overlay: boolean;
|
|
43
|
-
subtitle: string;
|
|
44
|
-
subtitle_color: string;
|
|
45
|
-
subtitle_size: string | number | null;
|
|
46
|
-
text_color: string;
|
|
47
|
-
title: string;
|
|
48
|
-
title_color: string;
|
|
49
|
-
title_size: string | number | null;
|
|
50
|
-
url: string | null;
|
|
51
|
-
url_text: string | null;
|
|
52
|
-
vertical: string;
|
|
53
|
-
imageUri?: string | undefined;
|
|
54
|
-
}[] | null;
|
|
32
|
+
export declare const makeSlides: (items: Announcements, isMobile: boolean) => Announcements | null;
|
|
55
33
|
export declare const displayPrice: (price: string) => string;
|
|
56
34
|
export declare const addCommas: (x: number, d: number) => string;
|
|
57
35
|
export declare const formatQuantity: (n: string) => string;
|
package/package.json
CHANGED