@open-tender/utils 0.5.60 → 0.5.62
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/useAccordion.d.ts +1 -1
- package/dist/cjs/hooks/useAccordion.js +7 -1
- package/dist/cjs/hooks/useBuilder.d.ts +3 -1
- package/dist/cjs/hooks/useBuilder.js +10 -1
- package/dist/cjs/hooks/useProfileForm.d.ts +1 -0
- package/dist/cjs/utils/passwordValidation.js +1 -1
- package/dist/esm/hooks/useAccordion.d.ts +1 -1
- package/dist/esm/hooks/useAccordion.js +7 -1
- package/dist/esm/hooks/useBuilder.d.ts +3 -1
- package/dist/esm/hooks/useBuilder.js +10 -1
- package/dist/esm/hooks/useProfileForm.d.ts +1 -0
- package/dist/esm/utils/passwordValidation.js +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CartItem, CartLevels, ConfigAccordion } from '@open-tender/types';
|
|
3
|
-
export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId?: number | null, config?: ConfigAccordion) => {
|
|
3
|
+
export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId?: number | null, config?: ConfigAccordion, setImageUrl?: ((imageUrl: string | null) => void) | undefined) => {
|
|
4
4
|
open: string | null;
|
|
5
5
|
setOpen: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
6
6
|
groups: import("@open-tender/types").CartItemGroups;
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useAccordion = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useAccordion = (builtItem, toggleOption, cartId, config
|
|
6
|
+
const useAccordion = (builtItem, toggleOption, cartId, config, setImageUrl //
|
|
7
|
+
) => {
|
|
7
8
|
var _a;
|
|
8
9
|
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
9
10
|
const [open, setOpen] = (0, react_1.useState)(null);
|
|
@@ -29,6 +30,11 @@ const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
|
29
30
|
const toggleSize = (optionId) => {
|
|
30
31
|
if (sizeGroup) {
|
|
31
32
|
toggleOption([[sizeGroup.id, optionId]]);
|
|
33
|
+
if (setImageUrl) {
|
|
34
|
+
const selectedOption = sizeGroup.options.find(o => o.id === optionId);
|
|
35
|
+
if (selectedOption && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.imageUrl))
|
|
36
|
+
setImageUrl(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.imageUrl);
|
|
37
|
+
}
|
|
32
38
|
setOpen(null);
|
|
33
39
|
}
|
|
34
40
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CartItem, CartLevels } from '@open-tender/types';
|
|
1
|
+
import { CartItem, CartItemGroups, CartLevels } from '@open-tender/types';
|
|
2
2
|
export declare const useBuilder: (orderItem: CartItem, orderTimeoutCallback?: () => void) => {
|
|
3
3
|
item: CartItem;
|
|
4
4
|
increment: () => void;
|
|
@@ -11,4 +11,6 @@ export declare const useBuilder: (orderItem: CartItem, orderTimeoutCallback?: ()
|
|
|
11
11
|
incrementOption: (levels: CartLevels) => CartItem;
|
|
12
12
|
decrementOption: (levels: CartLevels) => CartItem;
|
|
13
13
|
setOptionQuantity: (levels: CartLevels, quantity: number) => CartItem;
|
|
14
|
+
setGroups: (groups: CartItemGroups) => void;
|
|
15
|
+
setImageUrl: (imageUrl: string | null) => void;
|
|
14
16
|
};
|
|
@@ -134,6 +134,13 @@ const useBuilder = (orderItem, orderTimeoutCallback) => {
|
|
|
134
134
|
setItem(pricedItem);
|
|
135
135
|
return pricedItem;
|
|
136
136
|
};
|
|
137
|
+
const setGroups = (groups) => {
|
|
138
|
+
const pricedItem = (0, utils_1.calcPrices)(Object.assign(Object.assign({}, item), { groups }));
|
|
139
|
+
setItem(pricedItem);
|
|
140
|
+
};
|
|
141
|
+
const setImageUrl = (imageUrl) => {
|
|
142
|
+
setItem(prev => (Object.assign(Object.assign({}, prev), { imageUrl })));
|
|
143
|
+
};
|
|
137
144
|
return {
|
|
138
145
|
item,
|
|
139
146
|
increment,
|
|
@@ -145,7 +152,9 @@ const useBuilder = (orderItem, orderTimeoutCallback) => {
|
|
|
145
152
|
toggleOption,
|
|
146
153
|
incrementOption,
|
|
147
154
|
decrementOption,
|
|
148
|
-
setOptionQuantity
|
|
155
|
+
setOptionQuantity,
|
|
156
|
+
setGroups,
|
|
157
|
+
setImageUrl
|
|
149
158
|
};
|
|
150
159
|
};
|
|
151
160
|
exports.useBuilder = useBuilder;
|
|
@@ -75,6 +75,7 @@ export declare const useProfileForm: (profile: Customer | null, loading: Request
|
|
|
75
75
|
style?: import("react").CSSProperties | undefined;
|
|
76
76
|
type: string;
|
|
77
77
|
value?: string | undefined;
|
|
78
|
+
onBlur?: ((evt: any) => void) | undefined;
|
|
78
79
|
})[];
|
|
79
80
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
80
81
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
@@ -86,7 +86,7 @@ const getPasswordRequirements = (password) => {
|
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
met: hasOnlyAllowedChars(password) && hasSpecialChar(password),
|
|
89
|
-
message: `One special character from: ${ALLOWED_SPECIAL_CHARS}
|
|
89
|
+
message: `One special character from: ${ALLOWED_SPECIAL_CHARS}`,
|
|
90
90
|
},
|
|
91
91
|
];
|
|
92
92
|
return requirements;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CartItem, CartLevels, ConfigAccordion } from '@open-tender/types';
|
|
3
|
-
export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId?: number | null, config?: ConfigAccordion) => {
|
|
3
|
+
export declare const useAccordion: (builtItem: CartItem, toggleOption: (levels: CartLevels) => void, cartId?: number | null, config?: ConfigAccordion, setImageUrl?: ((imageUrl: string | null) => void) | undefined) => {
|
|
4
4
|
open: string | null;
|
|
5
5
|
setOpen: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
6
6
|
groups: import("@open-tender/types").CartItemGroups;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { calcNutritionalInfo } from '../utils';
|
|
3
|
-
export const useAccordion = (builtItem, toggleOption, cartId, config
|
|
3
|
+
export const useAccordion = (builtItem, toggleOption, cartId, config, setImageUrl //
|
|
4
|
+
) => {
|
|
4
5
|
var _a;
|
|
5
6
|
const { hasCals: showCals = false, hasCustomize = false, hasMadeFor: showMadeFor = true, hasNotes: showNotes = true } = config || {};
|
|
6
7
|
const [open, setOpen] = useState(null);
|
|
@@ -26,6 +27,11 @@ export const useAccordion = (builtItem, toggleOption, cartId, config) => {
|
|
|
26
27
|
const toggleSize = (optionId) => {
|
|
27
28
|
if (sizeGroup) {
|
|
28
29
|
toggleOption([[sizeGroup.id, optionId]]);
|
|
30
|
+
if (setImageUrl) {
|
|
31
|
+
const selectedOption = sizeGroup.options.find(o => o.id === optionId);
|
|
32
|
+
if (selectedOption && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.imageUrl))
|
|
33
|
+
setImageUrl(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.imageUrl);
|
|
34
|
+
}
|
|
29
35
|
setOpen(null);
|
|
30
36
|
}
|
|
31
37
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CartItem, CartLevels } from '@open-tender/types';
|
|
1
|
+
import { CartItem, CartItemGroups, CartLevels } from '@open-tender/types';
|
|
2
2
|
export declare const useBuilder: (orderItem: CartItem, orderTimeoutCallback?: () => void) => {
|
|
3
3
|
item: CartItem;
|
|
4
4
|
increment: () => void;
|
|
@@ -11,4 +11,6 @@ export declare const useBuilder: (orderItem: CartItem, orderTimeoutCallback?: ()
|
|
|
11
11
|
incrementOption: (levels: CartLevels) => CartItem;
|
|
12
12
|
decrementOption: (levels: CartLevels) => CartItem;
|
|
13
13
|
setOptionQuantity: (levels: CartLevels, quantity: number) => CartItem;
|
|
14
|
+
setGroups: (groups: CartItemGroups) => void;
|
|
15
|
+
setImageUrl: (imageUrl: string | null) => void;
|
|
14
16
|
};
|
|
@@ -131,6 +131,13 @@ export const useBuilder = (orderItem, orderTimeoutCallback) => {
|
|
|
131
131
|
setItem(pricedItem);
|
|
132
132
|
return pricedItem;
|
|
133
133
|
};
|
|
134
|
+
const setGroups = (groups) => {
|
|
135
|
+
const pricedItem = calcPrices(Object.assign(Object.assign({}, item), { groups }));
|
|
136
|
+
setItem(pricedItem);
|
|
137
|
+
};
|
|
138
|
+
const setImageUrl = (imageUrl) => {
|
|
139
|
+
setItem(prev => (Object.assign(Object.assign({}, prev), { imageUrl })));
|
|
140
|
+
};
|
|
134
141
|
return {
|
|
135
142
|
item,
|
|
136
143
|
increment,
|
|
@@ -142,6 +149,8 @@ export const useBuilder = (orderItem, orderTimeoutCallback) => {
|
|
|
142
149
|
toggleOption,
|
|
143
150
|
incrementOption,
|
|
144
151
|
decrementOption,
|
|
145
|
-
setOptionQuantity
|
|
152
|
+
setOptionQuantity,
|
|
153
|
+
setGroups,
|
|
154
|
+
setImageUrl
|
|
146
155
|
};
|
|
147
156
|
};
|
|
@@ -75,6 +75,7 @@ export declare const useProfileForm: (profile: Customer | null, loading: Request
|
|
|
75
75
|
style?: import("react").CSSProperties | undefined;
|
|
76
76
|
type: string;
|
|
77
77
|
value?: string | undefined;
|
|
78
|
+
onBlur?: ((evt: any) => void) | undefined;
|
|
78
79
|
})[];
|
|
79
80
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
80
81
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
@@ -82,7 +82,7 @@ export const getPasswordRequirements = (password) => {
|
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
84
|
met: hasOnlyAllowedChars(password) && hasSpecialChar(password),
|
|
85
|
-
message: `One special character from: ${ALLOWED_SPECIAL_CHARS}
|
|
85
|
+
message: `One special character from: ${ALLOWED_SPECIAL_CHARS}`,
|
|
86
86
|
},
|
|
87
87
|
];
|
|
88
88
|
return requirements;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.62",
|
|
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",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"typescript": "^4.8.2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@open-tender/types": "^0.4.
|
|
60
|
+
"@open-tender/types": "^0.4.174",
|
|
61
61
|
"@reduxjs/toolkit": "^1.8.5",
|
|
62
62
|
"react": "^18.2.0"
|
|
63
63
|
},
|