@open-tender/utils 0.0.66 → 0.0.68

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.
Files changed (105) hide show
  1. package/dist/cjs/hooks/index.d.ts +3 -0
  2. package/dist/cjs/hooks/index.js +3 -0
  3. package/dist/cjs/hooks/useAddressForm.d.ts +1 -1
  4. package/dist/cjs/hooks/useAddressForm.js +2 -1
  5. package/dist/cjs/hooks/useAllergenForm.d.ts +1 -1
  6. package/dist/cjs/hooks/useAllergenForm.js +2 -1
  7. package/dist/cjs/hooks/useCartGuestForm.d.ts +1 -1
  8. package/dist/cjs/hooks/useCartGuestForm.js +2 -1
  9. package/dist/cjs/hooks/useCheckoutLoginForm.d.ts +1 -1
  10. package/dist/cjs/hooks/useCheckoutLoginForm.js +2 -1
  11. package/dist/cjs/hooks/useCreditCard.d.ts +11 -6
  12. package/dist/cjs/hooks/useCreditCard.js +43 -60
  13. package/dist/cjs/hooks/useCreditCardForm.d.ts +9 -0
  14. package/dist/cjs/hooks/useCreditCardForm.js +75 -0
  15. package/dist/cjs/hooks/useCurbside.d.ts +1 -1
  16. package/dist/cjs/hooks/useCurbside.js +2 -1
  17. package/dist/cjs/hooks/useDineInForm.d.ts +1 -1
  18. package/dist/cjs/hooks/useDineInForm.js +2 -1
  19. package/dist/cjs/hooks/useDonationForm.d.ts +1 -1
  20. package/dist/cjs/hooks/useDonationForm.js +2 -1
  21. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +1 -1
  22. package/dist/cjs/hooks/useGiftCardAssignForm.js +2 -1
  23. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +1 -1
  24. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +2 -1
  25. package/dist/cjs/hooks/useGiftCardForm.d.ts +1 -1
  26. package/dist/cjs/hooks/useGiftCardForm.js +2 -1
  27. package/dist/cjs/hooks/useGiftCardsForm.d.ts +1 -1
  28. package/dist/cjs/hooks/useGiftCardsForm.js +2 -1
  29. package/dist/cjs/hooks/useGuestForm.d.ts +1 -1
  30. package/dist/cjs/hooks/useGuestForm.js +2 -1
  31. package/dist/cjs/hooks/useImage.d.ts +6 -0
  32. package/dist/cjs/hooks/useImage.js +31 -0
  33. package/dist/cjs/hooks/useLevelUpForm.d.ts +12 -0
  34. package/dist/cjs/hooks/useLevelUpForm.js +42 -0
  35. package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +1 -1
  36. package/dist/cjs/hooks/useOrderFulfillmentForm.js +2 -1
  37. package/dist/cjs/hooks/useOrderRating.d.ts +1 -1
  38. package/dist/cjs/hooks/useOrderRating.js +2 -1
  39. package/dist/cjs/hooks/useOrderRatingForm.d.ts +1 -1
  40. package/dist/cjs/hooks/useOrderRatingForm.js +2 -1
  41. package/dist/cjs/hooks/useProfileForm.d.ts +1 -1
  42. package/dist/cjs/hooks/useProfileForm.js +2 -1
  43. package/dist/cjs/hooks/useResetPasswordForm.d.ts +1 -1
  44. package/dist/cjs/hooks/useResetPasswordForm.js +2 -1
  45. package/dist/cjs/hooks/useSendResetForm.d.ts +1 -1
  46. package/dist/cjs/hooks/useSendResetForm.js +2 -1
  47. package/dist/cjs/hooks/useSignUpForm.d.ts +1 -1
  48. package/dist/cjs/hooks/useSignUpForm.js +2 -1
  49. package/dist/cjs/hooks/useSignUpGuestForm.d.ts +1 -1
  50. package/dist/cjs/hooks/useSignUpGuestForm.js +2 -1
  51. package/dist/cjs/hooks/useSigninForm.d.ts +1 -1
  52. package/dist/cjs/hooks/useSigninForm.js +2 -1
  53. package/dist/esm/hooks/index.d.ts +3 -0
  54. package/dist/esm/hooks/index.js +3 -0
  55. package/dist/esm/hooks/useAddressForm.d.ts +1 -1
  56. package/dist/esm/hooks/useAddressForm.js +2 -1
  57. package/dist/esm/hooks/useAllergenForm.d.ts +1 -1
  58. package/dist/esm/hooks/useAllergenForm.js +2 -1
  59. package/dist/esm/hooks/useCartGuestForm.d.ts +1 -1
  60. package/dist/esm/hooks/useCartGuestForm.js +2 -1
  61. package/dist/esm/hooks/useCheckoutLoginForm.d.ts +1 -1
  62. package/dist/esm/hooks/useCheckoutLoginForm.js +2 -1
  63. package/dist/esm/hooks/useCreditCard.d.ts +11 -6
  64. package/dist/esm/hooks/useCreditCard.js +44 -59
  65. package/dist/esm/hooks/useCreditCardForm.d.ts +9 -0
  66. package/dist/esm/hooks/useCreditCardForm.js +71 -0
  67. package/dist/esm/hooks/useCurbside.d.ts +1 -1
  68. package/dist/esm/hooks/useCurbside.js +2 -1
  69. package/dist/esm/hooks/useDineInForm.d.ts +1 -1
  70. package/dist/esm/hooks/useDineInForm.js +2 -1
  71. package/dist/esm/hooks/useDonationForm.d.ts +1 -1
  72. package/dist/esm/hooks/useDonationForm.js +2 -1
  73. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +1 -1
  74. package/dist/esm/hooks/useGiftCardAssignForm.js +2 -1
  75. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +1 -1
  76. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +2 -1
  77. package/dist/esm/hooks/useGiftCardForm.d.ts +1 -1
  78. package/dist/esm/hooks/useGiftCardForm.js +2 -1
  79. package/dist/esm/hooks/useGiftCardsForm.d.ts +1 -1
  80. package/dist/esm/hooks/useGiftCardsForm.js +2 -1
  81. package/dist/esm/hooks/useGuestForm.d.ts +1 -1
  82. package/dist/esm/hooks/useGuestForm.js +2 -1
  83. package/dist/esm/hooks/useImage.d.ts +6 -0
  84. package/dist/esm/hooks/useImage.js +29 -0
  85. package/dist/esm/hooks/useLevelUpForm.d.ts +12 -0
  86. package/dist/esm/hooks/useLevelUpForm.js +40 -0
  87. package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +1 -1
  88. package/dist/esm/hooks/useOrderFulfillmentForm.js +2 -1
  89. package/dist/esm/hooks/useOrderRating.d.ts +1 -1
  90. package/dist/esm/hooks/useOrderRating.js +2 -1
  91. package/dist/esm/hooks/useOrderRatingForm.d.ts +1 -1
  92. package/dist/esm/hooks/useOrderRatingForm.js +2 -1
  93. package/dist/esm/hooks/useProfileForm.d.ts +1 -1
  94. package/dist/esm/hooks/useProfileForm.js +2 -1
  95. package/dist/esm/hooks/useResetPasswordForm.d.ts +1 -1
  96. package/dist/esm/hooks/useResetPasswordForm.js +2 -1
  97. package/dist/esm/hooks/useSendResetForm.d.ts +1 -1
  98. package/dist/esm/hooks/useSendResetForm.js +2 -1
  99. package/dist/esm/hooks/useSignUpForm.d.ts +1 -1
  100. package/dist/esm/hooks/useSignUpForm.js +2 -1
  101. package/dist/esm/hooks/useSignUpGuestForm.d.ts +1 -1
  102. package/dist/esm/hooks/useSignUpGuestForm.js +2 -1
  103. package/dist/esm/hooks/useSigninForm.d.ts +1 -1
  104. package/dist/esm/hooks/useSigninForm.js +2 -1
  105. package/package.json +1 -1
@@ -7,5 +7,5 @@ export declare const useGuestForm: (email: string, loading: RequestStatus, error
7
7
  errMsg: any;
8
8
  submitting: boolean;
9
9
  handleChange: (name: string, value: string) => void;
10
- handleSubmit: () => void;
10
+ handleSubmit: (evt?: any) => void;
11
11
  };
@@ -20,8 +20,9 @@ export const useGuestForm = (email, loading, errors, checkGuest) => {
20
20
  const handleChange = (name, value) => {
21
21
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
22
22
  };
23
- const handleSubmit = () => {
23
+ const handleSubmit = (evt) => {
24
24
  var _a, _b;
25
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
25
26
  const { email } = data;
26
27
  checkGuest(email);
27
28
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
@@ -0,0 +1,6 @@
1
+ declare const useImage: (src: string) => {
2
+ hasLoaded: boolean;
3
+ hasError: boolean;
4
+ hasStartedInitialFetch: boolean;
5
+ };
6
+ export default useImage;
@@ -0,0 +1,29 @@
1
+ import { useState, useEffect } from 'react';
2
+ // https://typesafe.blog/article/fetch-images-with-a-react-hook
3
+ const useImage = (src) => {
4
+ const [hasLoaded, setHasLoaded] = useState(false);
5
+ const [hasError, setHasError] = useState(false);
6
+ const [hasStartedInitialFetch, setHasStartedInitialFetch] = useState(false);
7
+ useEffect(() => {
8
+ setHasStartedInitialFetch(true);
9
+ setHasLoaded(false);
10
+ setHasError(false);
11
+ const image = new Image();
12
+ image.src = src;
13
+ const handleError = () => {
14
+ setHasError(true);
15
+ };
16
+ const handleLoad = () => {
17
+ setHasLoaded(true);
18
+ setHasError(false);
19
+ };
20
+ image.onerror = handleError;
21
+ image.onload = handleLoad;
22
+ return () => {
23
+ image.removeEventListener('error', handleError);
24
+ image.removeEventListener('load', handleLoad);
25
+ };
26
+ }, [src]);
27
+ return { hasLoaded, hasError, hasStartedInitialFetch };
28
+ };
29
+ export default useImage;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { RequestStatus } from '@open-tender/types';
3
+ declare const useLevelUpForm: (email: string, loading: RequestStatus, error: any, connect: (data: any, callback: any) => void, callback: any) => {
4
+ submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
+ inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
+ data: any;
7
+ errors: {};
8
+ submitting: boolean;
9
+ handleChange: (evt?: any) => void;
10
+ handleSubmit: (evt?: any) => void;
11
+ };
12
+ export default useLevelUpForm;
@@ -0,0 +1,40 @@
1
+ import { useState, useEffect, useRef } from 'react';
2
+ const useLevelUpForm = (email, loading, error, connect, callback) => {
3
+ const submitRef = useRef(null);
4
+ const inputRef = useRef(null);
5
+ const [data, setData] = useState({ email });
6
+ const [errors, setErrors] = useState({});
7
+ const [submitting, setSubmitting] = useState(false);
8
+ useEffect(() => {
9
+ var _a;
10
+ if (loading === 'idle') {
11
+ setSubmitting(false);
12
+ if (error) {
13
+ setErrors(error);
14
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
15
+ }
16
+ }
17
+ }, [loading, error]);
18
+ const handleChange = (evt) => {
19
+ const { id, type, value, checked } = evt === null || evt === void 0 ? void 0 : evt.target;
20
+ const inputValue = type === 'checkbox' ? checked : value;
21
+ setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
22
+ };
23
+ const handleSubmit = (evt) => {
24
+ var _a;
25
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
26
+ setSubmitting(true);
27
+ connect(data, callback);
28
+ (_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur();
29
+ };
30
+ return {
31
+ submitRef,
32
+ inputRef,
33
+ data,
34
+ errors,
35
+ submitting,
36
+ handleChange,
37
+ handleSubmit,
38
+ };
39
+ };
40
+ export default useLevelUpForm;
@@ -7,5 +7,5 @@ export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: Par
7
7
  errors: any;
8
8
  submitting: boolean;
9
9
  handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
10
- handleSubmit: () => void;
10
+ handleSubmit: (evt?: any) => void;
11
11
  };
@@ -19,8 +19,9 @@ export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, up
19
19
  const inputValue = type === 'checkbox' ? checked : value;
20
20
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
21
21
  };
22
- const handleSubmit = () => {
22
+ const handleSubmit = (evt) => {
23
23
  var _a, _b;
24
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
24
25
  setSubmitting(true);
25
26
  update(orderId, Object.assign(Object.assign({}, data), { has_arrived: true }));
26
27
  ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
@@ -4,7 +4,7 @@ export declare const useOrderRating: (orderId: number, orderRating: OrderRating,
4
4
  handleRating: (star: number) => void;
5
5
  comments: string;
6
6
  handleComments: (inputComments: string) => void;
7
- handleSubmit: () => void;
7
+ handleSubmit: (evt?: any) => void;
8
8
  handleClose: () => void;
9
9
  stars: number[];
10
10
  };
@@ -9,7 +9,8 @@ export const useOrderRating = (orderId, orderRating, updateRating) => {
9
9
  const handleComments = (inputComments) => {
10
10
  setComments(inputComments);
11
11
  };
12
- const handleSubmit = () => {
12
+ const handleSubmit = (evt) => {
13
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
13
14
  const data = { rating, comments };
14
15
  updateRating(orderId, data);
15
16
  };
@@ -7,5 +7,5 @@ export declare const useOrderRatingForm: (orderId: number, orderRating: OrderRat
7
7
  handleRating: (star: number) => void;
8
8
  comments: string;
9
9
  handleComments: (value: string) => void;
10
- handleSubmit: () => void;
10
+ handleSubmit: (evt?: any) => void;
11
11
  };
@@ -10,8 +10,9 @@ export const useOrderRatingForm = (orderId, orderRating, updateRating, callback)
10
10
  const handleComments = (value) => {
11
11
  setComments(value);
12
12
  };
13
- const handleSubmit = () => {
13
+ const handleSubmit = (evt) => {
14
14
  var _a, _b;
15
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
15
16
  const data = { rating, comments };
16
17
  updateRating(orderId, data);
17
18
  if (callback)
@@ -18,5 +18,5 @@ export declare const useProfileForm: (profile: Partial<Profile>, loading: Reques
18
18
  errMsg: string | null;
19
19
  handleChange: (name: string, type: string, value?: string, checked?: boolean) => void;
20
20
  handleRadio: (name: string, value: string) => void;
21
- handleSubmit: () => void;
21
+ handleSubmit: (evt?: any) => void;
22
22
  };
@@ -44,8 +44,9 @@ export const useProfileForm = (profile, loading, error, update, optIns = {}) =>
44
44
  const handleRadio = (name, value) => {
45
45
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
46
46
  };
47
- const handleSubmit = () => {
47
+ const handleSubmit = (evt) => {
48
48
  var _a, _b;
49
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
49
50
  setSubmitting(true);
50
51
  const updatedData = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
51
52
  updatedData.birth_date = data.birth_date
@@ -14,5 +14,5 @@ export declare const useResetPasswordForm: (loading: RequestStatus, error: any,
14
14
  errors: {};
15
15
  submitting: boolean;
16
16
  handleChange: (name: string, value: string) => void;
17
- handleSubmit: () => void;
17
+ handleSubmit: (evt?: any) => void;
18
18
  };
@@ -32,8 +32,9 @@ export const useResetPasswordForm = (loading, error, reset, resetForm, resetToke
32
32
  const handleChange = (name, value) => {
33
33
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
34
34
  };
35
- const handleSubmit = () => {
35
+ const handleSubmit = (evt) => {
36
36
  var _a, _b, _c, _d, _e, _f;
37
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
37
38
  const { new_password, confirm } = data;
38
39
  if (!new_password || new_password.length < 8) {
39
40
  setErrors({ new_password: 'Must be at least 8 characters' });
@@ -6,5 +6,5 @@ export declare const useSendResetForm: (loading: RequestStatus, error: any, send
6
6
  data: any;
7
7
  errMsg: any;
8
8
  handleChange: (name: string, value: string) => void;
9
- handleSubmit: () => void;
9
+ handleSubmit: (evt?: any) => void;
10
10
  };
@@ -13,8 +13,9 @@ export const useSendResetForm = (loading, error, sendReset, callback, windowref,
13
13
  const handleChange = (name, value) => {
14
14
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
15
15
  };
16
- const handleSubmit = () => {
16
+ const handleSubmit = (evt) => {
17
17
  var _a, _b;
18
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
18
19
  const linkUrl = windowref ? `${windowref.location.origin}/reset-password` : `${linkUrlVal}`;
19
20
  sendReset(data.email, linkUrl).then(() => {
20
21
  if (callback)
@@ -15,5 +15,5 @@ export declare const useSignUpForm: (loading: RequestInfo, error: any, signUp: (
15
15
  formfields: SignUpFormField[];
16
16
  errMsg: string | null;
17
17
  handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
18
- handleSubmit: () => void;
18
+ handleSubmit: (evt?: any) => void;
19
19
  };
@@ -68,8 +68,9 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}
68
68
  const inputValue = type === 'checkbox' ? checked : name === 'phone' ? makePhone(value !== null && value !== void 0 ? value : "") : value;
69
69
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
70
70
  };
71
- const handleSubmit = () => {
71
+ const handleSubmit = (evt) => {
72
72
  var _a, _b;
73
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
73
74
  setErrors({});
74
75
  setSubmitting(true);
75
76
  signUp(data, callback);
@@ -16,6 +16,6 @@ export declare const useSignUpGuestForm: (email: string, guest: Partial<GuestDat
16
16
  errMsg: string | null;
17
17
  submitting: boolean;
18
18
  handleChange: (id: string, value: string) => void;
19
- handleSubmit: () => void;
19
+ handleSubmit: (evt?: any) => void;
20
20
  handleGuest: () => void;
21
21
  };
@@ -39,8 +39,9 @@ export const useSignUpGuestForm = (email, guest, loading, error, signUp, submitG
39
39
  }
40
40
  }
41
41
  }, [loading, error]);
42
- const handleSubmit = () => {
42
+ const handleSubmit = (evt) => {
43
43
  var _a, _b;
44
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
44
45
  if (!disabled) {
45
46
  setErrors({});
46
47
  setSubmitting(true);
@@ -6,5 +6,5 @@ export declare const useSignInForm: (email: string, loading: RequestStatus, erro
6
6
  data: Partial<LoginData>;
7
7
  submitting: boolean;
8
8
  handleChange: (name: string, value: string) => void;
9
- handleSubmit: () => void;
9
+ handleSubmit: (evt?: any) => void;
10
10
  };
@@ -20,8 +20,9 @@ export const useSignInForm = (email, loading, error, login, callback) => {
20
20
  const handleChange = (name, value) => {
21
21
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
22
22
  };
23
- const handleSubmit = () => {
23
+ const handleSubmit = (evt) => {
24
24
  var _a, _b;
25
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
25
26
  setHasSubmit(true);
26
27
  const { email, password } = data;
27
28
  login(email, password);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.66",
3
+ "version": "0.0.68",
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",