@open-tender/utils 0.0.69 → 0.1.1

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 (95) hide show
  1. package/dist/cjs/hooks/menu/useBuilder.d.ts +8 -7
  2. package/dist/cjs/hooks/menu/useBuilder.js +92 -86
  3. package/dist/cjs/hooks/menu/useOrderItem.d.ts +33 -43
  4. package/dist/cjs/hooks/menu/useOrderItem.js +21 -22
  5. package/dist/cjs/hooks/useAddressForm.js +1 -1
  6. package/dist/cjs/hooks/useAllergenForm.js +1 -1
  7. package/dist/cjs/hooks/useCartGuestForm.js +2 -2
  8. package/dist/cjs/hooks/useCheckoutLoginForm.js +1 -1
  9. package/dist/cjs/hooks/useCreditCard.js +2 -2
  10. package/dist/cjs/hooks/useCreditCardForm.js +3 -3
  11. package/dist/cjs/hooks/useCurbside.js +1 -1
  12. package/dist/cjs/hooks/useDineInForm.js +1 -1
  13. package/dist/cjs/hooks/useDonationForm.js +5 -5
  14. package/dist/cjs/hooks/useGiftCardAssignForm.js +1 -1
  15. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +1 -1
  16. package/dist/cjs/hooks/useGiftCardForm.js +6 -4
  17. package/dist/cjs/hooks/useGiftCardsForm.js +22 -9
  18. package/dist/cjs/hooks/useGuestForm.js +1 -1
  19. package/dist/cjs/hooks/useImage.d.ts +1 -1
  20. package/dist/cjs/hooks/useImage.js +2 -1
  21. package/dist/cjs/hooks/useLevelUpForm.js +1 -1
  22. package/dist/cjs/hooks/useOrderFulfillmentForm.js +3 -3
  23. package/dist/cjs/hooks/useOrderRating.js +1 -1
  24. package/dist/cjs/hooks/useOrderRatingForm.js +1 -1
  25. package/dist/cjs/hooks/useProfileForm.js +3 -3
  26. package/dist/cjs/hooks/useResetPasswordForm.js +2 -2
  27. package/dist/cjs/hooks/useSendResetForm.js +4 -2
  28. package/dist/cjs/hooks/useSignUpForm.js +14 -10
  29. package/dist/cjs/hooks/useSignUpGuestForm.js +3 -3
  30. package/dist/cjs/hooks/useSigninForm.js +1 -1
  31. package/dist/cjs/utils/cart.d.ts +97 -453
  32. package/dist/cjs/utils/cart.js +297 -376
  33. package/dist/cjs/utils/customer.js +1 -1
  34. package/dist/cjs/utils/errors.js +4 -2
  35. package/dist/cjs/utils/favorites.d.ts +3 -3
  36. package/dist/cjs/utils/favorites.js +11 -4
  37. package/dist/cjs/utils/helpers.d.ts +8 -3
  38. package/dist/cjs/utils/helpers.js +31 -3
  39. package/dist/cjs/utils/index.d.ts +1 -0
  40. package/dist/cjs/utils/index.js +1 -0
  41. package/dist/cjs/utils/maps.js +1 -1
  42. package/dist/cjs/utils/orders.d.ts +3 -3
  43. package/dist/cjs/utils/refunds.d.ts +4 -4
  44. package/dist/cjs/utils/revenueCenters.d.ts +11 -0
  45. package/dist/cjs/utils/revenueCenters.js +125 -0
  46. package/dist/cjs/utils/rewards.js +5 -5
  47. package/dist/cjs/utils/theme.js +7 -7
  48. package/dist/esm/hooks/menu/useBuilder.d.ts +8 -7
  49. package/dist/esm/hooks/menu/useBuilder.js +92 -86
  50. package/dist/esm/hooks/menu/useOrderItem.d.ts +33 -43
  51. package/dist/esm/hooks/menu/useOrderItem.js +22 -23
  52. package/dist/esm/hooks/useAddressForm.js +1 -1
  53. package/dist/esm/hooks/useAllergenForm.js +1 -1
  54. package/dist/esm/hooks/useCartGuestForm.js +2 -2
  55. package/dist/esm/hooks/useCheckoutLoginForm.js +1 -1
  56. package/dist/esm/hooks/useCreditCard.js +3 -3
  57. package/dist/esm/hooks/useCreditCardForm.js +3 -3
  58. package/dist/esm/hooks/useCurbside.js +1 -1
  59. package/dist/esm/hooks/useDineInForm.js +1 -1
  60. package/dist/esm/hooks/useDonationForm.js +5 -5
  61. package/dist/esm/hooks/useGiftCardAssignForm.js +1 -1
  62. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +1 -1
  63. package/dist/esm/hooks/useGiftCardForm.js +6 -4
  64. package/dist/esm/hooks/useGiftCardsForm.js +22 -9
  65. package/dist/esm/hooks/useGuestForm.js +1 -1
  66. package/dist/esm/hooks/useImage.d.ts +1 -1
  67. package/dist/esm/hooks/useImage.js +2 -1
  68. package/dist/esm/hooks/useLevelUpForm.js +1 -1
  69. package/dist/esm/hooks/useOrderFulfillmentForm.js +3 -3
  70. package/dist/esm/hooks/useOrderRating.js +1 -1
  71. package/dist/esm/hooks/useOrderRatingForm.js +1 -1
  72. package/dist/esm/hooks/useProfileForm.js +3 -3
  73. package/dist/esm/hooks/useResetPasswordForm.js +2 -2
  74. package/dist/esm/hooks/useSendResetForm.js +4 -2
  75. package/dist/esm/hooks/useSignUpForm.js +14 -10
  76. package/dist/esm/hooks/useSignUpGuestForm.js +3 -3
  77. package/dist/esm/hooks/useSigninForm.js +1 -1
  78. package/dist/esm/utils/cart.d.ts +97 -453
  79. package/dist/esm/utils/cart.js +285 -354
  80. package/dist/esm/utils/customer.js +1 -1
  81. package/dist/esm/utils/errors.js +4 -2
  82. package/dist/esm/utils/favorites.d.ts +3 -3
  83. package/dist/esm/utils/favorites.js +11 -4
  84. package/dist/esm/utils/helpers.d.ts +8 -3
  85. package/dist/esm/utils/helpers.js +25 -2
  86. package/dist/esm/utils/index.d.ts +1 -0
  87. package/dist/esm/utils/index.js +1 -0
  88. package/dist/esm/utils/maps.js +1 -1
  89. package/dist/esm/utils/orders.d.ts +3 -3
  90. package/dist/esm/utils/refunds.d.ts +4 -4
  91. package/dist/esm/utils/revenueCenters.d.ts +11 -0
  92. package/dist/esm/utils/revenueCenters.js +115 -0
  93. package/dist/esm/utils/rewards.js +1 -1
  94. package/dist/esm/utils/theme.js +7 -7
  95. package/package.json +2 -4
@@ -1,5 +1,5 @@
1
1
  import { useMemo, useRef, useState, useEffect } from 'react';
2
- import { validateCreditCard } from '@open-tender/utils';
2
+ import { validateCreditCard } from '../utils';
3
3
  export const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [], recaptchaKey = null, initState, cardData, cardType, windowRef) => {
4
4
  var _a, _b;
5
5
  const submitRef = useRef(null);
@@ -13,7 +13,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
13
13
  const [creditCardOptions, setCreditCardOptions] = useState([]);
14
14
  const [errors, setErrors] = useState({});
15
15
  const [submitting, setSubmitting] = useState(false);
16
- const url = (_b = (_a = windowRef === null || windowRef === void 0 ? void 0 : windowRef.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : "";
16
+ const url = (_b = (_a = windowRef === null || windowRef === void 0 ? void 0 : windowRef.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : '';
17
17
  const newCardErrors = useMemo(() => errors
18
18
  ? Object.entries(errors)
19
19
  .filter(([key]) => key !== 'form')
@@ -36,9 +36,9 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
36
36
  }, [windowRef, loading, error, setAlert, success]);
37
37
  useEffect(() => {
38
38
  if (creditCards.length) {
39
- const options = creditCards.map((i) => ({
39
+ const options = creditCards.map(i => ({
40
40
  name: `${i.card_type_name} ending in ${i.last4}`,
41
- value: i.customer_card_id,
41
+ value: i.customer_card_id
42
42
  }));
43
43
  setCreditCardOptions(options);
44
44
  const defaultCard = creditCards.length
@@ -95,7 +95,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
95
95
  var _a;
96
96
  const alert = {
97
97
  type: 'working',
98
- args: { text: 'Submitting your purchase...' },
98
+ args: { text: 'Submitting your purchase...' }
99
99
  };
100
100
  if (recaptchaKey) {
101
101
  try {
@@ -103,7 +103,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
103
103
  if (!token) {
104
104
  setSubmitting(false);
105
105
  setErrors({
106
- form: 'Please complete the recaptcha before submitting',
106
+ form: 'Please complete the recaptcha before submitting'
107
107
  });
108
108
  windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
109
109
  }
@@ -111,7 +111,14 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
111
111
  setSubmitting(true);
112
112
  setAlert(alert);
113
113
  const gift_cards = makeGiftCards(cards);
114
- purchase({ token, credit_card, name: name !== null && name !== void 0 ? name : "", email: email !== null && email !== void 0 ? email : "", url, gift_cards });
114
+ purchase({
115
+ token,
116
+ credit_card,
117
+ name: name !== null && name !== void 0 ? name : '',
118
+ email: email !== null && email !== void 0 ? email : '',
119
+ url,
120
+ gift_cards
121
+ });
115
122
  }
116
123
  }
117
124
  catch (err) {
@@ -124,7 +131,13 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
124
131
  setSubmitting(true);
125
132
  setAlert(alert);
126
133
  const gift_cards = makeGiftCards(cards);
127
- purchase({ credit_card, name: name !== null && name !== void 0 ? name : "", email: email !== null && email !== void 0 ? email : "", url, gift_cards });
134
+ purchase({
135
+ credit_card,
136
+ name: name !== null && name !== void 0 ? name : '',
137
+ email: email !== null && email !== void 0 ? email : '',
138
+ url,
139
+ gift_cards
140
+ });
128
141
  }
129
142
  };
130
143
  const handleSubmit = (evt) => {
@@ -180,6 +193,6 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
180
193
  creditCard,
181
194
  setCreditCard,
182
195
  errors,
183
- submitting,
196
+ submitting
184
197
  };
185
198
  };
@@ -34,6 +34,6 @@ export const useGuestForm = (email, loading, errors, checkGuest) => {
34
34
  errMsg,
35
35
  submitting,
36
36
  handleChange,
37
- handleSubmit,
37
+ handleSubmit
38
38
  };
39
39
  };
@@ -1,4 +1,4 @@
1
- export declare const useImage: (src: string) => {
1
+ export declare const useImage: (src: string | null | undefined) => {
2
2
  hasLoaded: boolean;
3
3
  hasError: boolean;
4
4
  hasStartedInitialFetch: boolean;
@@ -9,7 +9,8 @@ export const useImage = (src) => {
9
9
  setHasLoaded(false);
10
10
  setHasError(false);
11
11
  const image = new Image();
12
- image.src = src;
12
+ if (src)
13
+ image.src = src;
13
14
  const handleError = () => {
14
15
  setHasError(true);
15
16
  };
@@ -34,6 +34,6 @@ export const useLevelUpForm = (email, loading, error, connect, callback) => {
34
34
  errors,
35
35
  submitting,
36
36
  handleChange,
37
- handleSubmit,
37
+ handleSubmit
38
38
  };
39
39
  };
@@ -4,9 +4,9 @@ export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, up
4
4
  const [data, setData] = useState({});
5
5
  const [submitting, setSubmitting] = useState(false);
6
6
  const errors = error || {};
7
- const empty = Object.values(fulfillment).every((i) => !i);
7
+ const empty = Object.values(fulfillment).every(i => !i);
8
8
  const fields = !empty && !showAllFields
9
- ? settings === null || settings === void 0 ? void 0 : settings.fields.filter((i) => i.name.startsWith('arrival'))
9
+ ? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
10
10
  : settings === null || settings === void 0 ? void 0 : settings.fields;
11
11
  useEffect(() => {
12
12
  if (loading === 'idle')
@@ -33,6 +33,6 @@ export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, up
33
33
  errors,
34
34
  submitting,
35
35
  handleChange,
36
- handleSubmit,
36
+ handleSubmit
37
37
  };
38
38
  };
@@ -25,6 +25,6 @@ export const useOrderRating = (orderId, orderRating, updateRating) => {
25
25
  handleComments,
26
26
  handleSubmit,
27
27
  handleClose,
28
- stars,
28
+ stars
29
29
  };
30
30
  };
@@ -26,6 +26,6 @@ export const useOrderRatingForm = (orderId, orderRating, updateRating, callback)
26
26
  handleRating,
27
27
  comments,
28
28
  handleComments,
29
- handleSubmit,
29
+ handleSubmit
30
30
  };
31
31
  };
@@ -15,10 +15,10 @@ export const useProfileForm = (profile, loading, error, update, optIns = {}) =>
15
15
  name: 'email',
16
16
  type: 'email',
17
17
  required: true,
18
- autoComplete: 'email',
18
+ autoComplete: 'email'
19
19
  },
20
20
  { label: 'Phone', name: 'phone', type: 'tel', required: true },
21
- { label: 'Company', name: 'company', type: 'text' },
21
+ { label: 'Company', name: 'company', type: 'text' }
22
22
  ];
23
23
  useEffect(() => {
24
24
  if (loading === 'idle') {
@@ -67,6 +67,6 @@ export const useProfileForm = (profile, loading, error, update, optIns = {}) =>
67
67
  errMsg,
68
68
  handleChange,
69
69
  handleRadio,
70
- handleSubmit,
70
+ handleSubmit
71
71
  };
72
72
  };
@@ -7,7 +7,7 @@ export const useResetPasswordForm = (loading, error, reset, resetForm, resetToke
7
7
  const [submitting, setSubmitting] = useState(false);
8
8
  const fields = [
9
9
  { label: 'New Password', name: 'new_password', type: 'password' },
10
- { label: 'Confirm Password', name: 'confirm', type: 'password' },
10
+ { label: 'Confirm Password', name: 'confirm', type: 'password' }
11
11
  ];
12
12
  useEffect(() => {
13
13
  setData({});
@@ -59,6 +59,6 @@ export const useResetPasswordForm = (loading, error, reset, resetForm, resetToke
59
59
  errors,
60
60
  submitting,
61
61
  handleChange,
62
- handleSubmit,
62
+ handleSubmit
63
63
  };
64
64
  };
@@ -16,7 +16,9 @@ export const useSendResetForm = (loading, error, sendReset, callback, windowref,
16
16
  const handleSubmit = (evt) => {
17
17
  var _a, _b;
18
18
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
19
- const linkUrl = windowref ? `${windowref.location.origin}/reset-password` : `${linkUrlVal}`;
19
+ const linkUrl = windowref
20
+ ? `${windowref.location.origin}/reset-password`
21
+ : `${linkUrlVal}`;
20
22
  sendReset(data.email, linkUrl).then(() => {
21
23
  if (callback)
22
24
  callback();
@@ -29,6 +31,6 @@ export const useSendResetForm = (loading, error, sendReset, callback, windowref,
29
31
  data,
30
32
  errMsg,
31
33
  handleChange,
32
- handleSubmit,
34
+ handleSubmit
33
35
  };
34
36
  };
@@ -1,5 +1,5 @@
1
1
  import { useRef, useState, useEffect } from 'react';
2
- import { makePhone } from '@open-tender/utils';
2
+ import { makePhone } from '../utils';
3
3
  export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}, hasThanx = false) => {
4
4
  const { displayed, required } = checkConfig || {};
5
5
  const companyDisplayed = displayed && displayed.customer.includes('company');
@@ -14,41 +14,41 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}
14
14
  label: 'First Name',
15
15
  name: 'first_name',
16
16
  type: 'text',
17
- required: true,
17
+ required: true
18
18
  },
19
19
  {
20
20
  label: 'Last Name',
21
21
  name: 'last_name',
22
22
  type: 'text',
23
- required: true,
23
+ required: true
24
24
  },
25
25
  {
26
26
  label: 'Email',
27
27
  name: 'email',
28
28
  type: 'email',
29
29
  required: true,
30
- autoComplete: 'email',
30
+ autoComplete: 'email'
31
31
  },
32
32
  {
33
33
  label: 'Password',
34
34
  name: 'password',
35
35
  type: 'password',
36
36
  required: true,
37
- autoComplete: 'new-password',
37
+ autoComplete: 'new-password'
38
38
  },
39
- { label: 'Phone', name: 'phone', type: 'tel', required: true },
39
+ { label: 'Phone', name: 'phone', type: 'tel', required: true }
40
40
  ];
41
41
  if (companyDisplayed || companyRequired) {
42
42
  const company = {
43
43
  label: 'Company',
44
44
  name: 'company',
45
45
  type: 'text',
46
- required: companyRequired,
46
+ required: companyRequired
47
47
  };
48
48
  fields = [...fields, company];
49
49
  }
50
50
  const formfields = hasThanx
51
- ? fields.filter((i) => i.name !== 'password')
51
+ ? fields.filter(i => i.name !== 'password')
52
52
  : fields;
53
53
  useEffect(() => {
54
54
  return () => {
@@ -65,7 +65,11 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}
65
65
  }
66
66
  }, [loading, error]);
67
67
  const handleChange = (name, type, value, checked) => {
68
- const inputValue = type === 'checkbox' ? checked : name === 'phone' ? makePhone(value !== null && value !== void 0 ? value : "") : value;
68
+ const inputValue = type === 'checkbox'
69
+ ? checked
70
+ : name === 'phone'
71
+ ? makePhone(value !== null && value !== void 0 ? value : '')
72
+ : value;
69
73
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
70
74
  };
71
75
  const handleSubmit = (evt) => {
@@ -84,6 +88,6 @@ export const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}
84
88
  formfields,
85
89
  errMsg,
86
90
  handleChange,
87
- handleSubmit,
91
+ handleSubmit
88
92
  };
89
93
  };
@@ -1,10 +1,10 @@
1
1
  import { useRef, useState, useEffect } from 'react';
2
- import { checkEmpty, checkGuestData, makePhone } from '@open-tender/utils';
2
+ import { checkEmpty, checkGuestData, makePhone } from '../utils';
3
3
  const initialData = {
4
4
  first_name: '',
5
5
  last_name: '',
6
6
  phone: '',
7
- password: '',
7
+ password: ''
8
8
  };
9
9
  export const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, hasThanx) => {
10
10
  const submitRef = useRef(null);
@@ -67,6 +67,6 @@ export const useSignUpGuestForm = (email, guest, loading, error, signUp, submitG
67
67
  submitting,
68
68
  handleChange,
69
69
  handleSubmit,
70
- handleGuest,
70
+ handleGuest
71
71
  };
72
72
  };
@@ -34,6 +34,6 @@ export const useSignInForm = (email, loading, error, login, callback) => {
34
34
  data,
35
35
  submitting,
36
36
  handleChange,
37
- handleSubmit,
37
+ handleSubmit
38
38
  };
39
39
  };