@open-tender/utils 0.4.32 → 0.4.34

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;
@@ -42,7 +43,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
42
43
  toRemove.push('company');
43
44
  if (hidePassword)
44
45
  toRemove.push('password');
45
- if (optionalFields && !optionalFields.includes('birth_date'))
46
+ if (optionalFields && !optionalFields.includes('birth_date') && !hasPunchh)
46
47
  toRemove.push('birth_date');
47
48
  if (optionalFields && !optionalFields.includes('gender'))
48
49
  toRemove.push('gender');
@@ -80,7 +81,7 @@ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePasswo
80
81
  type: 'text',
81
82
  required: companyRequired
82
83
  },
83
- { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
84
+ { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel', required: hasPunchh },
84
85
  {
85
86
  label: 'Gender',
86
87
  name: 'gender',
@@ -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('birthday');
29
+ if (hasThanx)
30
+ toRemove.push('password');
26
31
  const allFields = [
27
32
  {
28
33
  label: 'Email',
@@ -45,10 +50,10 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
45
50
  },
46
51
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
47
52
  {
48
- label: 'Birth Date',
49
- name: 'birth_date',
50
- type: 'date',
51
- required: true
53
+ label: 'Birth Date (mm/dd/yyyy)',
54
+ name: 'birthday',
55
+ type: 'tel',
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;
@@ -39,7 +40,7 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
39
40
  toRemove.push('company');
40
41
  if (hidePassword)
41
42
  toRemove.push('password');
42
- if (optionalFields && !optionalFields.includes('birth_date'))
43
+ if (optionalFields && !optionalFields.includes('birth_date') && !hasPunchh)
43
44
  toRemove.push('birth_date');
44
45
  if (optionalFields && !optionalFields.includes('gender'))
45
46
  toRemove.push('gender');
@@ -77,7 +78,7 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig, hid
77
78
  type: 'text',
78
79
  required: companyRequired
79
80
  },
80
- { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
81
+ { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel', required: hasPunchh },
81
82
  {
82
83
  label: 'Gender',
83
84
  name: 'gender',
@@ -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('birthday');
26
+ if (hasThanx)
27
+ toRemove.push('password');
23
28
  const allFields = [
24
29
  {
25
30
  label: 'Email',
@@ -42,10 +47,10 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
42
47
  },
43
48
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
44
49
  {
45
- label: 'Birth Date',
46
- name: 'birth_date',
47
- type: 'date',
48
- required: true
50
+ label: 'Birth Date (mm/dd/yyyy)',
51
+ name: 'birthday',
52
+ type: 'tel',
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.34",
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",