@open-tender/utils 0.5.40 → 0.5.42
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/useSignUpForm.d.ts +1 -1
- package/dist/cjs/hooks/useSignUpForm.js +8 -5
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +1 -1
- package/dist/cjs/hooks/useSignUpGuestForm.js +8 -5
- package/dist/cjs/utils/cart.js +1 -5
- package/dist/esm/hooks/useSignUpForm.d.ts +1 -1
- package/dist/esm/hooks/useSignUpForm.js +8 -5
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +1 -1
- package/dist/esm/hooks/useSignUpGuestForm.js +8 -5
- package/dist/esm/utils/cart.js +1 -5
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ export interface NotificationCheckbox {
|
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
9
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
9
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
|
|
10
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
11
|
data: CustomerCreate;
|
|
12
12
|
comms: NotificationChannel[];
|
|
@@ -27,7 +27,7 @@ exports.notificationChannelFields = [
|
|
|
27
27
|
type: 'checkbox'
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
|
-
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
30
|
+
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
|
|
31
31
|
const submitRef = (0, react_1.useRef)(null);
|
|
32
32
|
const [data, setData] = (0, react_1.useState)(initState);
|
|
33
33
|
const [comms, setComms] = (0, react_1.useState)([]);
|
|
@@ -121,13 +121,16 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
121
121
|
setComms(updated);
|
|
122
122
|
};
|
|
123
123
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
var _a, _b;
|
|
124
|
+
var _a, _b, _c;
|
|
125
125
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
126
126
|
setErrors({});
|
|
127
127
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
128
128
|
if (values.birth_date) {
|
|
129
129
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
130
130
|
}
|
|
131
|
+
const loginToken = includeLoginRecaptcha
|
|
132
|
+
? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
|
|
133
|
+
: undefined;
|
|
131
134
|
if (includeRecaptcha) {
|
|
132
135
|
try {
|
|
133
136
|
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
@@ -138,7 +141,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
138
141
|
}
|
|
139
142
|
else {
|
|
140
143
|
setSubmitting(true);
|
|
141
|
-
signUp(values, callback, token);
|
|
144
|
+
signUp(values, callback, token, loginToken);
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
147
|
catch (err) {
|
|
@@ -149,9 +152,9 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
149
152
|
}
|
|
150
153
|
else {
|
|
151
154
|
setSubmitting(true);
|
|
152
|
-
signUp(values, callback);
|
|
155
|
+
signUp(values, callback, undefined, loginToken);
|
|
153
156
|
}
|
|
154
|
-
((
|
|
157
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
155
158
|
});
|
|
156
159
|
return {
|
|
157
160
|
submitRef,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
3
|
+
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -12,7 +12,7 @@ const initialData = {
|
|
|
12
12
|
email: '',
|
|
13
13
|
password: ''
|
|
14
14
|
};
|
|
15
|
-
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
15
|
+
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
|
|
16
16
|
const submitRef = (0, react_1.useRef)(null);
|
|
17
17
|
const inputRef = (0, react_1.useRef)(null);
|
|
18
18
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -79,7 +79,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
79
79
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
80
80
|
};
|
|
81
81
|
const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
-
var _a, _b;
|
|
82
|
+
var _a, _b, _c;
|
|
83
83
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
84
84
|
if (!disabled) {
|
|
85
85
|
setErrors({});
|
|
@@ -87,6 +87,9 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
87
87
|
if (values.birth_date) {
|
|
88
88
|
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
89
89
|
}
|
|
90
|
+
const loginToken = includeLoginRecaptcha
|
|
91
|
+
? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
|
|
92
|
+
: undefined;
|
|
90
93
|
if (includeRecaptcha) {
|
|
91
94
|
try {
|
|
92
95
|
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
@@ -97,7 +100,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
97
100
|
}
|
|
98
101
|
else {
|
|
99
102
|
setSubmitting(true);
|
|
100
|
-
signUp(values, token);
|
|
103
|
+
signUp(values, token, loginToken);
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
catch (err) {
|
|
@@ -108,9 +111,9 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
108
111
|
}
|
|
109
112
|
else {
|
|
110
113
|
setSubmitting(true);
|
|
111
|
-
signUp(values);
|
|
114
|
+
signUp(values, undefined, loginToken);
|
|
112
115
|
}
|
|
113
|
-
((
|
|
116
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
114
117
|
}
|
|
115
118
|
});
|
|
116
119
|
const handleGuest = () => {
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -82,11 +82,7 @@ const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
82
82
|
.map(id => itemLookup[id])
|
|
83
83
|
.filter(i => i)
|
|
84
84
|
.map(i => (0, exports.makeOrderItem)(i))
|
|
85
|
-
.filter(i => !i.isSoldOut)
|
|
86
|
-
.filter(i => {
|
|
87
|
-
const belowMin = i.groups.filter(g => !g.isSize && (g.quantity || 0) < g.min);
|
|
88
|
-
return belowMin.length === 0;
|
|
89
|
-
});
|
|
85
|
+
.filter(i => !i.isSoldOut);
|
|
90
86
|
};
|
|
91
87
|
exports.makeUpsellItems = makeUpsellItems;
|
|
92
88
|
const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
@@ -6,7 +6,7 @@ export interface NotificationCheckbox {
|
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
9
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
9
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined, token?: string, loginToken?: string) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls'], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
|
|
10
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
11
|
data: CustomerCreate;
|
|
12
12
|
comms: NotificationChannel[];
|
|
@@ -24,7 +24,7 @@ export const notificationChannelFields = [
|
|
|
24
24
|
type: 'checkbox'
|
|
25
25
|
}
|
|
26
26
|
];
|
|
27
|
-
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken) => {
|
|
27
|
+
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls, includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
|
|
28
28
|
const submitRef = useRef(null);
|
|
29
29
|
const [data, setData] = useState(initState);
|
|
30
30
|
const [comms, setComms] = useState([]);
|
|
@@ -118,13 +118,16 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
118
118
|
setComms(updated);
|
|
119
119
|
};
|
|
120
120
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
-
var _a, _b;
|
|
121
|
+
var _a, _b, _c;
|
|
122
122
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
123
123
|
setErrors({});
|
|
124
124
|
const values = Object.assign(Object.assign({}, data), { communications: comms });
|
|
125
125
|
if (values.birth_date) {
|
|
126
126
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
127
127
|
}
|
|
128
|
+
const loginToken = includeLoginRecaptcha
|
|
129
|
+
? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
|
|
130
|
+
: undefined;
|
|
128
131
|
if (includeRecaptcha) {
|
|
129
132
|
try {
|
|
130
133
|
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
@@ -135,7 +138,7 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
135
138
|
}
|
|
136
139
|
else {
|
|
137
140
|
setSubmitting(true);
|
|
138
|
-
signUp(values, callback, token);
|
|
141
|
+
signUp(values, callback, token, loginToken);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
catch (err) {
|
|
@@ -146,9 +149,9 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
146
149
|
}
|
|
147
150
|
else {
|
|
148
151
|
setSubmitting(true);
|
|
149
|
-
signUp(values, callback);
|
|
152
|
+
signUp(values, callback, undefined, loginToken);
|
|
150
153
|
}
|
|
151
|
-
((
|
|
154
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
152
155
|
});
|
|
153
156
|
return {
|
|
154
157
|
submitRef,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>) => {
|
|
3
|
+
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate, token?: string, loginToken?: string) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[], includeRecaptcha?: boolean, getRecaptchaToken?: () => Promise<string | null>, includeLoginRecaptcha?: boolean, getLoginRecaptchaToken?: () => Promise<string | null>) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
@@ -9,7 +9,7 @@ const initialData = {
|
|
|
9
9
|
email: '',
|
|
10
10
|
password: ''
|
|
11
11
|
};
|
|
12
|
-
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken) => {
|
|
12
|
+
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = [], includeRecaptcha, getRecaptchaToken, includeLoginRecaptcha, getLoginRecaptchaToken) => {
|
|
13
13
|
const submitRef = useRef(null);
|
|
14
14
|
const inputRef = useRef(null);
|
|
15
15
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -76,7 +76,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
76
76
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
77
77
|
};
|
|
78
78
|
const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
var _a, _b;
|
|
79
|
+
var _a, _b, _c;
|
|
80
80
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
81
81
|
if (!disabled) {
|
|
82
82
|
setErrors({});
|
|
@@ -84,6 +84,9 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
84
84
|
if (values.birth_date) {
|
|
85
85
|
values.birth_date = slashesToDashes(values.birth_date);
|
|
86
86
|
}
|
|
87
|
+
const loginToken = includeLoginRecaptcha
|
|
88
|
+
? (_a = (yield (getLoginRecaptchaToken === null || getLoginRecaptchaToken === void 0 ? void 0 : getLoginRecaptchaToken()))) !== null && _a !== void 0 ? _a : undefined
|
|
89
|
+
: undefined;
|
|
87
90
|
if (includeRecaptcha) {
|
|
88
91
|
try {
|
|
89
92
|
const token = yield (getRecaptchaToken === null || getRecaptchaToken === void 0 ? void 0 : getRecaptchaToken());
|
|
@@ -94,7 +97,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
94
97
|
}
|
|
95
98
|
else {
|
|
96
99
|
setSubmitting(true);
|
|
97
|
-
signUp(values, token);
|
|
100
|
+
signUp(values, token, loginToken);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
catch (err) {
|
|
@@ -105,9 +108,9 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
105
108
|
}
|
|
106
109
|
else {
|
|
107
110
|
setSubmitting(true);
|
|
108
|
-
signUp(values);
|
|
111
|
+
signUp(values, undefined, loginToken);
|
|
109
112
|
}
|
|
110
|
-
((
|
|
113
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
116
|
const handleGuest = () => {
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -74,11 +74,7 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
74
74
|
.map(id => itemLookup[id])
|
|
75
75
|
.filter(i => i)
|
|
76
76
|
.map(i => makeOrderItem(i))
|
|
77
|
-
.filter(i => !i.isSoldOut)
|
|
78
|
-
.filter(i => {
|
|
79
|
-
const belowMin = i.groups.filter(g => !g.isSize && (g.quantity || 0) < g.min);
|
|
80
|
-
return belowMin.length === 0;
|
|
81
|
-
});
|
|
77
|
+
.filter(i => !i.isSoldOut);
|
|
82
78
|
};
|
|
83
79
|
export const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
84
80
|
const upsellItems = item ? item.upsellItems : null;
|
package/package.json
CHANGED