@open-tender/utils 0.4.36 → 0.4.37
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 +2 -2
- package/dist/cjs/hooks/useSignUpForm.js +8 -2
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +3 -3
- package/dist/cjs/hooks/useSignUpGuestForm.js +15 -4
- package/dist/esm/hooks/useSignUpForm.d.ts +2 -2
- package/dist/esm/hooks/useSignUpForm.js +8 -2
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +3 -3
- package/dist/esm/hooks/useSignUpGuestForm.js +15 -4
- package/package.json +1 -1
- package/dist/.DS_Store +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutConfig, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
3
|
interface NotificationCheckbox {
|
|
4
4
|
label: string;
|
|
5
5
|
name: NotificationChannel;
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string) => {
|
|
8
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
|
|
9
9
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
10
10
|
data: CustomerCreate;
|
|
11
11
|
comms: NotificationChannel[];
|
|
@@ -27,13 +27,14 @@ const notificationChannelFields = [
|
|
|
27
27
|
type: 'checkbox'
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
|
-
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements) => {
|
|
30
|
+
const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls) => {
|
|
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)([]);
|
|
34
34
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
35
35
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
36
36
|
const { displayed, required } = checkConfig || {};
|
|
37
|
+
const hasPunchh = tpls === 'PUNCHH';
|
|
37
38
|
const companyDisplayed = displayed && displayed.customer.includes('company');
|
|
38
39
|
const companyRequired = required && required.customer.includes('company');
|
|
39
40
|
const showCompany = companyDisplayed || companyRequired;
|
|
@@ -80,7 +81,12 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
80
81
|
type: 'text',
|
|
81
82
|
required: companyRequired
|
|
82
83
|
},
|
|
83
|
-
{
|
|
84
|
+
{
|
|
85
|
+
label: 'Birth Date (mm/dd/yyyy)',
|
|
86
|
+
name: 'birth_date',
|
|
87
|
+
type: 'tel',
|
|
88
|
+
required: hasPunchh
|
|
89
|
+
},
|
|
84
90
|
{
|
|
85
91
|
label: 'Gender',
|
|
86
92
|
name: 'gender',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutFormCustomer,
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate) => void, submitGuest: (data: CheckoutFormCustomer) => void,
|
|
2
|
+
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, 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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls']) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: {
|
|
8
8
|
email: string;
|
|
9
9
|
company?: string | undefined;
|
|
@@ -9,7 +9,7 @@ const initialData = {
|
|
|
9
9
|
phone: '',
|
|
10
10
|
password: ''
|
|
11
11
|
};
|
|
12
|
-
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest,
|
|
12
|
+
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
13
13
|
const submitRef = (0, react_1.useRef)(null);
|
|
14
14
|
const inputRef = (0, react_1.useRef)(null);
|
|
15
15
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -17,10 +17,17 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
17
17
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
18
18
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
19
19
|
const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
|
|
20
|
+
const hasThanx = tpls === 'THANX';
|
|
21
|
+
const hasPunchh = tpls === 'PUNCHH';
|
|
20
22
|
const isIncomplete = hasThanx ? guestIncomplete : (0, utils_1.checkEmpty)(data);
|
|
21
23
|
const isLoading = loading === 'pending';
|
|
22
24
|
const disabled = isIncomplete || isLoading;
|
|
23
25
|
const guestDisabled = guestIncomplete || isLoading;
|
|
26
|
+
const toRemove = [];
|
|
27
|
+
if (!hasPunchh)
|
|
28
|
+
toRemove.push('birthday');
|
|
29
|
+
if (hasThanx)
|
|
30
|
+
toRemove.push('password');
|
|
24
31
|
const allFields = [
|
|
25
32
|
{
|
|
26
33
|
label: 'Email',
|
|
@@ -42,6 +49,12 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
42
49
|
required: true
|
|
43
50
|
},
|
|
44
51
|
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
52
|
+
{
|
|
53
|
+
label: 'Birth Date (mm/dd/yyyy)',
|
|
54
|
+
name: 'birthday',
|
|
55
|
+
type: 'tel',
|
|
56
|
+
required: false
|
|
57
|
+
},
|
|
45
58
|
{
|
|
46
59
|
label: 'Password',
|
|
47
60
|
name: 'password',
|
|
@@ -49,9 +62,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
49
62
|
autoComplete: 'new-password'
|
|
50
63
|
}
|
|
51
64
|
];
|
|
52
|
-
const fields =
|
|
53
|
-
? allFields.filter(i => i.name !== 'password')
|
|
54
|
-
: allFields;
|
|
65
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
55
66
|
const handleChange = (name, value) => {
|
|
56
67
|
const val = name === 'phone' ? (0, utils_1.makePhone)(value) : value;
|
|
57
68
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutConfig, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
3
|
interface NotificationCheckbox {
|
|
4
4
|
label: string;
|
|
5
5
|
name: NotificationChannel;
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string) => {
|
|
8
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: ((data: Customer) => void) | undefined) => void, callback?: ((data: Customer) => void) | undefined, checkConfig?: CheckoutConfig, hidePassword?: boolean, optionalFields?: string[], notificationChannels?: NotificationChannel[], passwordRequirements?: string, tpls?: ConfigBrand['tpls']) => {
|
|
9
9
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
10
10
|
data: CustomerCreate;
|
|
11
11
|
comms: NotificationChannel[];
|
|
@@ -24,13 +24,14 @@ const notificationChannelFields = [
|
|
|
24
24
|
type: 'checkbox'
|
|
25
25
|
}
|
|
26
26
|
];
|
|
27
|
-
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements) => {
|
|
27
|
+
export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls) => {
|
|
28
28
|
const submitRef = useRef(null);
|
|
29
29
|
const [data, setData] = useState(initState);
|
|
30
30
|
const [comms, setComms] = useState([]);
|
|
31
31
|
const [errors, setErrors] = useState({});
|
|
32
32
|
const [submitting, setSubmitting] = useState(false);
|
|
33
33
|
const { displayed, required } = checkConfig || {};
|
|
34
|
+
const hasPunchh = tpls === 'PUNCHH';
|
|
34
35
|
const companyDisplayed = displayed && displayed.customer.includes('company');
|
|
35
36
|
const companyRequired = required && required.customer.includes('company');
|
|
36
37
|
const showCompany = companyDisplayed || companyRequired;
|
|
@@ -77,7 +78,12 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
|
|
|
77
78
|
type: 'text',
|
|
78
79
|
required: companyRequired
|
|
79
80
|
},
|
|
80
|
-
{
|
|
81
|
+
{
|
|
82
|
+
label: 'Birth Date (mm/dd/yyyy)',
|
|
83
|
+
name: 'birth_date',
|
|
84
|
+
type: 'tel',
|
|
85
|
+
required: hasPunchh
|
|
86
|
+
},
|
|
81
87
|
{
|
|
82
88
|
label: 'Gender',
|
|
83
89
|
name: 'gender',
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutFormCustomer,
|
|
3
|
-
export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, signUp: (data: CustomerCreate) => void, submitGuest: (data: CheckoutFormCustomer) => void,
|
|
2
|
+
import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, 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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls']) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
fields:
|
|
6
|
+
fields: import("@open-tender/types").FormFieldType[];
|
|
7
7
|
data: {
|
|
8
8
|
email: string;
|
|
9
9
|
company?: string | undefined;
|
|
@@ -6,7 +6,7 @@ const initialData = {
|
|
|
6
6
|
phone: '',
|
|
7
7
|
password: ''
|
|
8
8
|
};
|
|
9
|
-
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest,
|
|
9
|
+
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
10
10
|
const submitRef = useRef(null);
|
|
11
11
|
const inputRef = useRef(null);
|
|
12
12
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
@@ -14,10 +14,17 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
14
14
|
const [errors, setErrors] = useState({});
|
|
15
15
|
const [submitting, setSubmitting] = useState(false);
|
|
16
16
|
const { guestData, guestIncomplete } = checkGuestData(data, email);
|
|
17
|
+
const hasThanx = tpls === 'THANX';
|
|
18
|
+
const hasPunchh = tpls === 'PUNCHH';
|
|
17
19
|
const isIncomplete = hasThanx ? guestIncomplete : checkEmpty(data);
|
|
18
20
|
const isLoading = loading === 'pending';
|
|
19
21
|
const disabled = isIncomplete || isLoading;
|
|
20
22
|
const guestDisabled = guestIncomplete || isLoading;
|
|
23
|
+
const toRemove = [];
|
|
24
|
+
if (!hasPunchh)
|
|
25
|
+
toRemove.push('birthday');
|
|
26
|
+
if (hasThanx)
|
|
27
|
+
toRemove.push('password');
|
|
21
28
|
const allFields = [
|
|
22
29
|
{
|
|
23
30
|
label: 'Email',
|
|
@@ -39,6 +46,12 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
39
46
|
required: true
|
|
40
47
|
},
|
|
41
48
|
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
49
|
+
{
|
|
50
|
+
label: 'Birth Date (mm/dd/yyyy)',
|
|
51
|
+
name: 'birthday',
|
|
52
|
+
type: 'tel',
|
|
53
|
+
required: false
|
|
54
|
+
},
|
|
42
55
|
{
|
|
43
56
|
label: 'Password',
|
|
44
57
|
name: 'password',
|
|
@@ -46,9 +59,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
46
59
|
autoComplete: 'new-password'
|
|
47
60
|
}
|
|
48
61
|
];
|
|
49
|
-
const fields =
|
|
50
|
-
? allFields.filter(i => i.name !== 'password')
|
|
51
|
-
: allFields;
|
|
62
|
+
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
52
63
|
const handleChange = (name, value) => {
|
|
53
64
|
const val = name === 'phone' ? makePhone(value) : value;
|
|
54
65
|
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
package/package.json
CHANGED
package/dist/.DS_Store
DELETED
|
Binary file
|