@open-tender/utils 0.4.37 → 0.4.39
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.
|
@@ -4,15 +4,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
7
|
-
data:
|
|
8
|
-
email: string;
|
|
9
|
-
company?: string | undefined;
|
|
10
|
-
customer_id?: number | undefined;
|
|
11
|
-
first_name?: string | undefined;
|
|
12
|
-
password?: string | undefined;
|
|
13
|
-
phone?: string | undefined;
|
|
14
|
-
last_name?: string | undefined;
|
|
15
|
-
};
|
|
7
|
+
data: CustomerCreate;
|
|
16
8
|
errors: Record<string, string>;
|
|
17
9
|
disabled: boolean;
|
|
18
10
|
guestDisabled: boolean;
|
|
@@ -7,6 +7,7 @@ const initialData = {
|
|
|
7
7
|
first_name: '',
|
|
8
8
|
last_name: '',
|
|
9
9
|
phone: '',
|
|
10
|
+
email: '',
|
|
10
11
|
password: ''
|
|
11
12
|
};
|
|
12
13
|
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
@@ -19,13 +20,15 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
19
20
|
const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
|
|
20
21
|
const hasThanx = tpls === 'THANX';
|
|
21
22
|
const hasPunchh = tpls === 'PUNCHH';
|
|
22
|
-
const isIncomplete = hasThanx
|
|
23
|
+
const isIncomplete = hasThanx
|
|
24
|
+
? guestIncomplete
|
|
25
|
+
: Object.values(data).filter(i => !i).length > 0;
|
|
23
26
|
const isLoading = loading === 'pending';
|
|
24
27
|
const disabled = isIncomplete || isLoading;
|
|
25
28
|
const guestDisabled = guestIncomplete || isLoading;
|
|
26
29
|
const toRemove = [];
|
|
27
30
|
if (!hasPunchh)
|
|
28
|
-
toRemove.push('
|
|
31
|
+
toRemove.push('birth_date');
|
|
29
32
|
if (hasThanx)
|
|
30
33
|
toRemove.push('password');
|
|
31
34
|
const allFields = [
|
|
@@ -51,7 +54,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
51
54
|
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
52
55
|
{
|
|
53
56
|
label: 'Birth Date (mm/dd/yyyy)',
|
|
54
|
-
name: '
|
|
57
|
+
name: 'birth_date',
|
|
55
58
|
type: 'tel',
|
|
56
59
|
required: false
|
|
57
60
|
},
|
|
@@ -64,7 +67,11 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
64
67
|
];
|
|
65
68
|
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
66
69
|
const handleChange = (name, value) => {
|
|
67
|
-
const val = name === 'phone'
|
|
70
|
+
const val = name === 'phone'
|
|
71
|
+
? (0, utils_1.makePhone)(value)
|
|
72
|
+
: name === 'birth_date'
|
|
73
|
+
? (0, utils_1.makeBirthDate)(value)
|
|
74
|
+
: value;
|
|
68
75
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
69
76
|
};
|
|
70
77
|
const handleSubmit = (evt) => {
|
|
@@ -73,7 +80,11 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
73
80
|
if (!disabled) {
|
|
74
81
|
setErrors({});
|
|
75
82
|
setSubmitting(true);
|
|
76
|
-
|
|
83
|
+
const values = Object.assign(Object.assign({}, data), { email });
|
|
84
|
+
if (values.birth_date) {
|
|
85
|
+
values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
|
|
86
|
+
}
|
|
87
|
+
signUp(values);
|
|
77
88
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
78
89
|
}
|
|
79
90
|
};
|
|
@@ -4,15 +4,7 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: import("@open-tender/types").FormFieldType[];
|
|
7
|
-
data:
|
|
8
|
-
email: string;
|
|
9
|
-
company?: string | undefined;
|
|
10
|
-
customer_id?: number | undefined;
|
|
11
|
-
first_name?: string | undefined;
|
|
12
|
-
password?: string | undefined;
|
|
13
|
-
phone?: string | undefined;
|
|
14
|
-
last_name?: string | undefined;
|
|
15
|
-
};
|
|
7
|
+
data: CustomerCreate;
|
|
16
8
|
errors: Record<string, string>;
|
|
17
9
|
disabled: boolean;
|
|
18
10
|
guestDisabled: boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useRef, useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
3
|
const initialData = {
|
|
4
4
|
first_name: '',
|
|
5
5
|
last_name: '',
|
|
6
6
|
phone: '',
|
|
7
|
+
email: '',
|
|
7
8
|
password: ''
|
|
8
9
|
};
|
|
9
10
|
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
@@ -16,13 +17,15 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
16
17
|
const { guestData, guestIncomplete } = checkGuestData(data, email);
|
|
17
18
|
const hasThanx = tpls === 'THANX';
|
|
18
19
|
const hasPunchh = tpls === 'PUNCHH';
|
|
19
|
-
const isIncomplete = hasThanx
|
|
20
|
+
const isIncomplete = hasThanx
|
|
21
|
+
? guestIncomplete
|
|
22
|
+
: Object.values(data).filter(i => !i).length > 0;
|
|
20
23
|
const isLoading = loading === 'pending';
|
|
21
24
|
const disabled = isIncomplete || isLoading;
|
|
22
25
|
const guestDisabled = guestIncomplete || isLoading;
|
|
23
26
|
const toRemove = [];
|
|
24
27
|
if (!hasPunchh)
|
|
25
|
-
toRemove.push('
|
|
28
|
+
toRemove.push('birth_date');
|
|
26
29
|
if (hasThanx)
|
|
27
30
|
toRemove.push('password');
|
|
28
31
|
const allFields = [
|
|
@@ -48,7 +51,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
48
51
|
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
49
52
|
{
|
|
50
53
|
label: 'Birth Date (mm/dd/yyyy)',
|
|
51
|
-
name: '
|
|
54
|
+
name: 'birth_date',
|
|
52
55
|
type: 'tel',
|
|
53
56
|
required: false
|
|
54
57
|
},
|
|
@@ -61,7 +64,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
61
64
|
];
|
|
62
65
|
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
63
66
|
const handleChange = (name, value) => {
|
|
64
|
-
const val = name === 'phone'
|
|
67
|
+
const val = name === 'phone'
|
|
68
|
+
? makePhone(value)
|
|
69
|
+
: name === 'birth_date'
|
|
70
|
+
? makeBirthDate(value)
|
|
71
|
+
: value;
|
|
65
72
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
66
73
|
};
|
|
67
74
|
const handleSubmit = (evt) => {
|
|
@@ -70,7 +77,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
70
77
|
if (!disabled) {
|
|
71
78
|
setErrors({});
|
|
72
79
|
setSubmitting(true);
|
|
73
|
-
|
|
80
|
+
const values = Object.assign(Object.assign({}, data), { email });
|
|
81
|
+
if (values.birth_date) {
|
|
82
|
+
values.birth_date = slashesToDashes(values.birth_date);
|
|
83
|
+
}
|
|
84
|
+
signUp(values);
|
|
74
85
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
75
86
|
}
|
|
76
87
|
};
|
package/package.json
CHANGED