@open-tender/utils 0.4.38 → 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,7 +20,9 @@ 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 ? guestIncomplete : (0, utils_1.checkEmpty)(data);
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;
@@ -77,7 +80,11 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
77
80
  if (!disabled) {
78
81
  setErrors({});
79
82
  setSubmitting(true);
80
- signUp(Object.assign(Object.assign({}, data), { email }));
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);
81
88
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
82
89
  }
83
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 { checkEmpty, checkGuestData, makeBirthDate, makeFormErrors, makePhone } from '../utils';
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,7 +17,9 @@ 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 ? guestIncomplete : checkEmpty(data);
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;
@@ -74,7 +77,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
74
77
  if (!disabled) {
75
78
  setErrors({});
76
79
  setSubmitting(true);
77
- signUp(Object.assign(Object.assign({}, data), { email }));
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);
78
85
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
79
86
  }
80
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.38",
3
+ "version": "0.4.39",
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",