@open-tender/utils 0.1.139 → 0.1.141

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,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useGuestCheckoutForm: (guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, submit: (data: CheckoutFormCustomer) => void) => {
3
+ export declare const useGuestCheckoutForm: (guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, submit: (data: CheckoutFormCustomer) => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: FormFields;
@@ -9,7 +9,7 @@ const initialData = {
9
9
  email: '',
10
10
  phone: ''
11
11
  };
12
- const useGuestCheckoutForm = (guest, loading, error, submit) => {
12
+ const useGuestCheckoutForm = (guest, loading, error, guestErrors, submit) => {
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({}, initialData), guest);
@@ -34,8 +34,7 @@ const useGuestCheckoutForm = (guest, loading, error, submit) => {
34
34
  label: 'Email',
35
35
  name: 'email',
36
36
  type: 'email',
37
- required: true,
38
- disabled: true
37
+ required: true
39
38
  },
40
39
  { label: 'Phone', name: 'phone', type: 'tel', required: true }
41
40
  ];
@@ -63,8 +62,11 @@ const useGuestCheckoutForm = (guest, loading, error, submit) => {
63
62
  setErrors(errs);
64
63
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
65
64
  }
65
+ else if (guestErrors) {
66
+ setErrors(guestErrors);
67
+ }
66
68
  }
67
- }, [loading, error]);
69
+ }, [loading, error, guestErrors]);
68
70
  (0, react_1.useEffect)(() => {
69
71
  return () => {
70
72
  setData(initialData);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate) => void, submitGuest: (data: CheckoutFormCustomer) => void, hasThanx?: boolean) => {
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, hasThanx?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: FormFields;
@@ -9,7 +9,7 @@ const initialData = {
9
9
  phone: '',
10
10
  password: ''
11
11
  };
12
- const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, hasThanx) => {
12
+ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, hasThanx) => {
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 });
@@ -84,8 +84,11 @@ const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, h
84
84
  setErrors(errs);
85
85
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
86
86
  }
87
+ else if (guestErrors) {
88
+ setErrors(guestErrors);
89
+ }
87
90
  }
88
- }, [loading, error]);
91
+ }, [loading, error, guestErrors]);
89
92
  (0, react_1.useEffect)(() => {
90
93
  return () => {
91
94
  setData(Object.assign(Object.assign({}, initialData), { email: '' }));
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useGuestCheckoutForm: (guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, submit: (data: CheckoutFormCustomer) => void) => {
3
+ export declare const useGuestCheckoutForm: (guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, guestErrors: Record<string, string> | null, submit: (data: CheckoutFormCustomer) => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: FormFields;
@@ -6,7 +6,7 @@ const initialData = {
6
6
  email: '',
7
7
  phone: ''
8
8
  };
9
- export const useGuestCheckoutForm = (guest, loading, error, submit) => {
9
+ export const useGuestCheckoutForm = (guest, loading, error, guestErrors, submit) => {
10
10
  const submitRef = useRef(null);
11
11
  const inputRef = useRef(null);
12
12
  const initData = Object.assign(Object.assign({}, initialData), guest);
@@ -31,8 +31,7 @@ export const useGuestCheckoutForm = (guest, loading, error, submit) => {
31
31
  label: 'Email',
32
32
  name: 'email',
33
33
  type: 'email',
34
- required: true,
35
- disabled: true
34
+ required: true
36
35
  },
37
36
  { label: 'Phone', name: 'phone', type: 'tel', required: true }
38
37
  ];
@@ -60,8 +59,11 @@ export const useGuestCheckoutForm = (guest, loading, error, submit) => {
60
59
  setErrors(errs);
61
60
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
62
61
  }
62
+ else if (guestErrors) {
63
+ setErrors(guestErrors);
64
+ }
63
65
  }
64
- }, [loading, error]);
66
+ }, [loading, error, guestErrors]);
65
67
  useEffect(() => {
66
68
  return () => {
67
69
  setData(initialData);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CheckoutFormCustomer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignUpGuestForm: (email: string, guest: CheckoutFormCustomer, loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate) => void, submitGuest: (data: CheckoutFormCustomer) => void, hasThanx?: boolean) => {
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, hasThanx?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  fields: FormFields;
@@ -6,7 +6,7 @@ const initialData = {
6
6
  phone: '',
7
7
  password: ''
8
8
  };
9
- export const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, hasThanx) => {
9
+ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, hasThanx) => {
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 });
@@ -81,8 +81,11 @@ export const useSignUpGuestForm = (email, guest, loading, error, signUp, submitG
81
81
  setErrors(errs);
82
82
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
83
83
  }
84
+ else if (guestErrors) {
85
+ setErrors(guestErrors);
86
+ }
84
87
  }
85
- }, [loading, error]);
88
+ }, [loading, error, guestErrors]);
86
89
  useEffect(() => {
87
90
  return () => {
88
91
  setData(Object.assign(Object.assign({}, initialData), { email: '' }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.139",
3
+ "version": "0.1.141",
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",