@open-tender/utils 0.0.69 → 0.1.0

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