@open-tender/utils 0.4.66 → 0.4.68
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/useSignUpGuestForm.d.ts +1 -0
- package/dist/cjs/hooks/useSignUpGuestForm.js +18 -14
- package/dist/cjs/utils/cart.js +2 -0
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +1 -0
- package/dist/esm/hooks/useSignUpGuestForm.js +19 -15
- package/dist/esm/utils/cart.js +2 -0
- package/package.json +3 -3
|
@@ -15,4 +15,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
15
15
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
16
16
|
handleGuest: () => void;
|
|
17
17
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
|
+
resetState: () => void;
|
|
18
19
|
};
|
|
@@ -103,23 +103,26 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
103
103
|
const updated = value ? [...other, name] : other;
|
|
104
104
|
setComms(updated);
|
|
105
105
|
};
|
|
106
|
-
(0, react_1.
|
|
106
|
+
const resetState = (0, react_1.useCallback)(() => {
|
|
107
107
|
var _a, _b;
|
|
108
|
-
if (loading
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
setErrors(errs);
|
|
116
|
-
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
117
|
-
}
|
|
118
|
-
else if (guestErrors) {
|
|
119
|
-
setErrors(guestErrors);
|
|
108
|
+
if (loading !== 'idle')
|
|
109
|
+
return;
|
|
110
|
+
setSubmitting(false);
|
|
111
|
+
if (error) {
|
|
112
|
+
const errs = (0, utils_1.makeFormErrors)(error);
|
|
113
|
+
if (errs.form.includes('parameters')) {
|
|
114
|
+
errs.form = 'There are one or more errors below';
|
|
120
115
|
}
|
|
116
|
+
setErrors(errs);
|
|
117
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
118
|
+
}
|
|
119
|
+
else if (guestErrors) {
|
|
120
|
+
setErrors(guestErrors);
|
|
121
121
|
}
|
|
122
122
|
}, [loading, error, guestErrors]);
|
|
123
|
+
(0, react_1.useEffect)(() => {
|
|
124
|
+
resetState();
|
|
125
|
+
}, [resetState]);
|
|
123
126
|
(0, react_1.useEffect)(() => {
|
|
124
127
|
return () => {
|
|
125
128
|
setData(Object.assign(Object.assign({}, initialData), { email: '' }));
|
|
@@ -140,7 +143,8 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
140
143
|
handleChange,
|
|
141
144
|
handleSubmit,
|
|
142
145
|
handleGuest,
|
|
143
|
-
handleComms
|
|
146
|
+
handleComms,
|
|
147
|
+
resetState
|
|
144
148
|
};
|
|
145
149
|
};
|
|
146
150
|
exports.useSignUpGuestForm = useSignUpGuestForm;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -15,4 +15,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
15
15
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
16
16
|
handleGuest: () => void;
|
|
17
17
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
|
+
resetState: () => void;
|
|
18
19
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useState, useEffect } from 'react';
|
|
1
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
3
|
import { notificationChannelFields } from './useSignUpForm';
|
|
4
4
|
const initialData = {
|
|
@@ -100,23 +100,26 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
100
100
|
const updated = value ? [...other, name] : other;
|
|
101
101
|
setComms(updated);
|
|
102
102
|
};
|
|
103
|
-
|
|
103
|
+
const resetState = useCallback(() => {
|
|
104
104
|
var _a, _b;
|
|
105
|
-
if (loading
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
setErrors(errs);
|
|
113
|
-
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
114
|
-
}
|
|
115
|
-
else if (guestErrors) {
|
|
116
|
-
setErrors(guestErrors);
|
|
105
|
+
if (loading !== 'idle')
|
|
106
|
+
return;
|
|
107
|
+
setSubmitting(false);
|
|
108
|
+
if (error) {
|
|
109
|
+
const errs = makeFormErrors(error);
|
|
110
|
+
if (errs.form.includes('parameters')) {
|
|
111
|
+
errs.form = 'There are one or more errors below';
|
|
117
112
|
}
|
|
113
|
+
setErrors(errs);
|
|
114
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
115
|
+
}
|
|
116
|
+
else if (guestErrors) {
|
|
117
|
+
setErrors(guestErrors);
|
|
118
118
|
}
|
|
119
119
|
}, [loading, error, guestErrors]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
resetState();
|
|
122
|
+
}, [resetState]);
|
|
120
123
|
useEffect(() => {
|
|
121
124
|
return () => {
|
|
122
125
|
setData(Object.assign(Object.assign({}, initialData), { email: '' }));
|
|
@@ -137,6 +140,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
137
140
|
handleChange,
|
|
138
141
|
handleSubmit,
|
|
139
142
|
handleGuest,
|
|
140
|
-
handleComms
|
|
143
|
+
handleComms,
|
|
144
|
+
resetState
|
|
141
145
|
};
|
|
142
146
|
};
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -844,6 +844,8 @@ export const prepareOrder = (data) => {
|
|
|
844
844
|
order.cart_id = data.cartId;
|
|
845
845
|
if (data.save)
|
|
846
846
|
order.save = data.save;
|
|
847
|
+
if (data.token)
|
|
848
|
+
order.token = data.token;
|
|
847
849
|
return order;
|
|
848
850
|
};
|
|
849
851
|
export const checkAmountRemaining = (total, tenders) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.68",
|
|
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,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.
|
|
39
|
+
"@open-tender/types": "^0.4.94",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"typescript": "^4.8.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@open-tender/types": "^0.4.
|
|
61
|
+
"@open-tender/types": "^0.4.94",
|
|
62
62
|
"@reduxjs/toolkit": "^1.8.5",
|
|
63
63
|
"react": "^18.2.0"
|
|
64
64
|
},
|