@open-tender/utils 0.4.32 → 0.4.33

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.
@@ -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;
@@ -46,6 +47,8 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
46
47
  toRemove.push('birth_date');
47
48
  if (optionalFields && !optionalFields.includes('gender'))
48
49
  toRemove.push('gender');
50
+ if (!hasPunchh)
51
+ toRemove.push('birth_date');
49
52
  const allFields = [
50
53
  {
51
54
  label: 'First Name',
@@ -74,6 +77,12 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
74
77
  autoComplete: 'new-password'
75
78
  },
76
79
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
80
+ {
81
+ label: 'Birth Date',
82
+ name: 'birth_date',
83
+ type: 'date',
84
+ required: true
85
+ },
77
86
  {
78
87
  label: 'Company',
79
88
  name: 'company',
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
2
+ import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
3
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: FormFields;
6
+ fields: import("@open-tender/types").FormFieldType[];
7
7
  data: {
8
8
  email: string;
9
9
  company?: string | undefined;
@@ -23,6 +23,11 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
23
23
  const isLoading = loading === 'pending';
24
24
  const disabled = isIncomplete || isLoading;
25
25
  const guestDisabled = guestIncomplete || isLoading;
26
+ const toRemove = [];
27
+ if (!hasPunchh)
28
+ toRemove.push('birth_date');
29
+ if (hasThanx)
30
+ toRemove.push('password');
26
31
  const allFields = [
27
32
  {
28
33
  label: 'Email',
@@ -48,7 +53,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
48
53
  label: 'Birth Date',
49
54
  name: 'birth_date',
50
55
  type: 'date',
51
- required: true
56
+ required: false
52
57
  },
53
58
  {
54
59
  label: 'Password',
@@ -57,10 +62,7 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
57
62
  autoComplete: 'new-password'
58
63
  }
59
64
  ];
60
- const fields = hasThanx
61
- ? allFields.filter(i => i.name !== 'password' && i.name !== 'birth_date')
62
- : !hasPunchh ? allFields.filter((i => i.name !== 'birth_date'))
63
- : allFields;
65
+ const fields = allFields.filter(i => !toRemove.includes(i.name));
64
66
  const handleChange = (name, value) => {
65
67
  const val = name === 'phone' ? (0, utils_1.makePhone)(value) : value;
66
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;
@@ -43,6 +44,8 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
43
44
  toRemove.push('birth_date');
44
45
  if (optionalFields && !optionalFields.includes('gender'))
45
46
  toRemove.push('gender');
47
+ if (!hasPunchh)
48
+ toRemove.push('birth_date');
46
49
  const allFields = [
47
50
  {
48
51
  label: 'First Name',
@@ -71,6 +74,12 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
71
74
  autoComplete: 'new-password'
72
75
  },
73
76
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
77
+ {
78
+ label: 'Birth Date',
79
+ name: 'birth_date',
80
+ type: 'date',
81
+ required: true
82
+ },
74
83
  {
75
84
  label: 'Company',
76
85
  name: 'company',
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
2
+ import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
3
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: FormFields;
6
+ fields: import("@open-tender/types").FormFieldType[];
7
7
  data: {
8
8
  email: string;
9
9
  company?: string | undefined;
@@ -20,6 +20,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
20
20
  const isLoading = loading === 'pending';
21
21
  const disabled = isIncomplete || isLoading;
22
22
  const guestDisabled = guestIncomplete || isLoading;
23
+ const toRemove = [];
24
+ if (!hasPunchh)
25
+ toRemove.push('birth_date');
26
+ if (hasThanx)
27
+ toRemove.push('password');
23
28
  const allFields = [
24
29
  {
25
30
  label: 'Email',
@@ -45,7 +50,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
45
50
  label: 'Birth Date',
46
51
  name: 'birth_date',
47
52
  type: 'date',
48
- required: true
53
+ required: false
49
54
  },
50
55
  {
51
56
  label: 'Password',
@@ -54,10 +59,7 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
54
59
  autoComplete: 'new-password'
55
60
  }
56
61
  ];
57
- const fields = hasThanx
58
- ? allFields.filter(i => i.name !== 'password' && i.name !== 'birth_date')
59
- : !hasPunchh ? allFields.filter((i => i.name !== 'birth_date'))
60
- : allFields;
62
+ const fields = allFields.filter(i => !toRemove.includes(i.name));
61
63
  const handleChange = (name, value) => {
62
64
  const val = name === 'phone' ? makePhone(value) : value;
63
65
  setData(Object.assign(Object.assign({}, data), { [name]: val }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.32",
3
+ "version": "0.4.33",
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",