@open-tender/utils 0.4.45 → 0.4.47
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 +3 -3
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +4 -2
- package/dist/cjs/hooks/useSignUpGuestForm.js +12 -2
- package/dist/esm/hooks/useSignUpForm.d.ts +2 -2
- package/dist/esm/hooks/useSignUpForm.js +1 -1
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +4 -2
- package/dist/esm/hooks/useSignUpGuestForm.js +12 -2
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
interface NotificationCheckbox {
|
|
3
|
+
export interface NotificationCheckbox {
|
|
4
4
|
label: string;
|
|
5
5
|
name: NotificationChannel;
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
|
+
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
8
9
|
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
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
10
11
|
data: CustomerCreate;
|
|
@@ -17,4 +18,3 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
17
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
19
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
19
20
|
};
|
|
20
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSignUpForm = void 0;
|
|
3
|
+
exports.useSignUpForm = exports.notificationChannelFields = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const initState = {
|
|
@@ -9,7 +9,7 @@ const initState = {
|
|
|
9
9
|
email: '',
|
|
10
10
|
phone: ''
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
exports.notificationChannelFields = [
|
|
13
13
|
{
|
|
14
14
|
label: 'Email',
|
|
15
15
|
name: 'EMAIL',
|
|
@@ -86,7 +86,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
|
|
|
86
86
|
}
|
|
87
87
|
];
|
|
88
88
|
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
89
|
-
const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
|
|
89
|
+
const notificationFields = exports.notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
|
|
90
90
|
(0, react_1.useEffect)(() => {
|
|
91
91
|
return () => {
|
|
92
92
|
setData(initState);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
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']) => {
|
|
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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
|
|
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
|
+
notificationFields: import("./useSignUpForm").NotificationCheckbox[];
|
|
7
8
|
data: CustomerCreate;
|
|
8
9
|
errors: Record<string, string>;
|
|
9
10
|
disabled: boolean;
|
|
@@ -12,4 +13,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
13
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
14
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
14
15
|
handleGuest: () => void;
|
|
16
|
+
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
15
17
|
};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useSignUpGuestForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const useSignUpForm_1 = require("./useSignUpForm");
|
|
6
7
|
const initialData = {
|
|
7
8
|
first_name: '',
|
|
8
9
|
last_name: '',
|
|
@@ -10,11 +11,12 @@ const initialData = {
|
|
|
10
11
|
email: '',
|
|
11
12
|
password: ''
|
|
12
13
|
};
|
|
13
|
-
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
14
|
+
const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
|
|
14
15
|
const submitRef = (0, react_1.useRef)(null);
|
|
15
16
|
const inputRef = (0, react_1.useRef)(null);
|
|
16
17
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
17
18
|
const [data, setData] = (0, react_1.useState)(initData);
|
|
19
|
+
const [comms, setComms] = (0, react_1.useState)([]);
|
|
18
20
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
19
21
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
20
22
|
const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
|
|
@@ -66,6 +68,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
66
68
|
}
|
|
67
69
|
];
|
|
68
70
|
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
71
|
+
const notificationFields = useSignUpForm_1.notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
|
|
69
72
|
const handleChange = (name, value) => {
|
|
70
73
|
const val = name === 'phone'
|
|
71
74
|
? (0, utils_1.makePhone)(value)
|
|
@@ -95,6 +98,11 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
95
98
|
submitGuest(Object.assign(Object.assign({}, guestData), { email }));
|
|
96
99
|
}
|
|
97
100
|
};
|
|
101
|
+
const handleComms = (name, value) => {
|
|
102
|
+
const other = comms.filter(i => i !== name);
|
|
103
|
+
const updated = value ? [...other, name] : other;
|
|
104
|
+
setComms(updated);
|
|
105
|
+
};
|
|
98
106
|
(0, react_1.useEffect)(() => {
|
|
99
107
|
var _a, _b;
|
|
100
108
|
if (loading === 'idle') {
|
|
@@ -122,6 +130,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
122
130
|
submitRef,
|
|
123
131
|
inputRef,
|
|
124
132
|
fields,
|
|
133
|
+
notificationFields,
|
|
125
134
|
data,
|
|
126
135
|
errors,
|
|
127
136
|
disabled,
|
|
@@ -129,7 +138,8 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
129
138
|
submitting,
|
|
130
139
|
handleChange,
|
|
131
140
|
handleSubmit,
|
|
132
|
-
handleGuest
|
|
141
|
+
handleGuest,
|
|
142
|
+
handleComms
|
|
133
143
|
};
|
|
134
144
|
};
|
|
135
145
|
exports.useSignUpGuestForm = useSignUpGuestForm;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutConfig, ConfigBrand, Customer, CustomerCreate, NotificationChannel, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
interface NotificationCheckbox {
|
|
3
|
+
export interface NotificationCheckbox {
|
|
4
4
|
label: string;
|
|
5
5
|
name: NotificationChannel;
|
|
6
6
|
type: string;
|
|
7
7
|
}
|
|
8
|
+
export declare const notificationChannelFields: NotificationCheckbox[];
|
|
8
9
|
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
10
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
10
11
|
data: CustomerCreate;
|
|
@@ -17,4 +18,3 @@ export declare const useSignUpForm: (loading: RequestStatus, error: RequestError
|
|
|
17
18
|
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
18
19
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
19
20
|
};
|
|
20
|
-
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
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']) => {
|
|
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) => void, submitGuest: (data: CheckoutFormCustomer) => void, tpls?: ConfigBrand['tpls'], notificationChannels?: NotificationChannel[]) => {
|
|
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
|
+
notificationFields: import("./useSignUpForm").NotificationCheckbox[];
|
|
7
8
|
data: CustomerCreate;
|
|
8
9
|
errors: Record<string, string>;
|
|
9
10
|
disabled: boolean;
|
|
@@ -12,4 +13,5 @@ export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCust
|
|
|
12
13
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
14
|
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
14
15
|
handleGuest: () => void;
|
|
16
|
+
handleComms: (name: NotificationChannel, value: boolean) => void;
|
|
15
17
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRef, useState, useEffect } from 'react';
|
|
2
2
|
import { checkGuestData, makeBirthDate, makeFormErrors, makePhone, slashesToDashes } from '../utils';
|
|
3
|
+
import { notificationChannelFields } from './useSignUpForm';
|
|
3
4
|
const initialData = {
|
|
4
5
|
first_name: '',
|
|
5
6
|
last_name: '',
|
|
@@ -7,11 +8,12 @@ const initialData = {
|
|
|
7
8
|
email: '',
|
|
8
9
|
password: ''
|
|
9
10
|
};
|
|
10
|
-
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
|
|
11
|
+
export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls, notificationChannels = []) => {
|
|
11
12
|
const submitRef = useRef(null);
|
|
12
13
|
const inputRef = useRef(null);
|
|
13
14
|
const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
|
|
14
15
|
const [data, setData] = useState(initData);
|
|
16
|
+
const [comms, setComms] = useState([]);
|
|
15
17
|
const [errors, setErrors] = useState({});
|
|
16
18
|
const [submitting, setSubmitting] = useState(false);
|
|
17
19
|
const { guestData, guestIncomplete } = checkGuestData(data, email);
|
|
@@ -63,6 +65,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
63
65
|
}
|
|
64
66
|
];
|
|
65
67
|
const fields = allFields.filter(i => !toRemove.includes(i.name));
|
|
68
|
+
const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
|
|
66
69
|
const handleChange = (name, value) => {
|
|
67
70
|
const val = name === 'phone'
|
|
68
71
|
? makePhone(value)
|
|
@@ -92,6 +95,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
92
95
|
submitGuest(Object.assign(Object.assign({}, guestData), { email }));
|
|
93
96
|
}
|
|
94
97
|
};
|
|
98
|
+
const handleComms = (name, value) => {
|
|
99
|
+
const other = comms.filter(i => i !== name);
|
|
100
|
+
const updated = value ? [...other, name] : other;
|
|
101
|
+
setComms(updated);
|
|
102
|
+
};
|
|
95
103
|
useEffect(() => {
|
|
96
104
|
var _a, _b;
|
|
97
105
|
if (loading === 'idle') {
|
|
@@ -119,6 +127,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
119
127
|
submitRef,
|
|
120
128
|
inputRef,
|
|
121
129
|
fields,
|
|
130
|
+
notificationFields,
|
|
122
131
|
data,
|
|
123
132
|
errors,
|
|
124
133
|
disabled,
|
|
@@ -126,6 +135,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
126
135
|
submitting,
|
|
127
136
|
handleChange,
|
|
128
137
|
handleSubmit,
|
|
129
|
-
handleGuest
|
|
138
|
+
handleGuest,
|
|
139
|
+
handleComms
|
|
130
140
|
};
|
|
131
141
|
};
|
package/package.json
CHANGED