@open-tender/utils 0.4.31 → 0.4.33

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 (245) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +2 -2
  3. package/dist/cjs/__tests__/utils/helpers.test.d.ts +1 -1
  4. package/dist/cjs/__tests__/utils/helpers.test.js +96 -96
  5. package/dist/cjs/__tests__/utils/theme.test.d.ts +1 -1
  6. package/dist/cjs/__tests__/utils/theme.test.js +37 -37
  7. package/dist/cjs/hooks/index.d.ts +35 -35
  8. package/dist/cjs/hooks/index.js +38 -38
  9. package/dist/cjs/hooks/types.d.ts +4 -4
  10. package/dist/cjs/hooks/types.js +2 -2
  11. package/dist/cjs/hooks/useAccordion.d.ts +22 -22
  12. package/dist/cjs/hooks/useAccordion.js +56 -56
  13. package/dist/cjs/hooks/useAddressForm.d.ts +12 -12
  14. package/dist/cjs/hooks/useAddressForm.js +83 -83
  15. package/dist/cjs/hooks/useAllergenForm.d.ts +10 -10
  16. package/dist/cjs/hooks/useAllergenForm.js +58 -58
  17. package/dist/cjs/hooks/useBuilder.d.ts +14 -14
  18. package/dist/cjs/hooks/useBuilder.js +144 -144
  19. package/dist/cjs/hooks/useCartGuestForm.d.ts +12 -12
  20. package/dist/cjs/hooks/useCartGuestForm.js +58 -58
  21. package/dist/cjs/hooks/useCartPoints.d.ts +13 -13
  22. package/dist/cjs/hooks/useCartPoints.js +74 -74
  23. package/dist/cjs/hooks/useCommunicationPreferences.js +1 -1
  24. package/dist/cjs/hooks/useCreditCard.d.ts +13 -13
  25. package/dist/cjs/hooks/useCreditCard.js +63 -63
  26. package/dist/cjs/hooks/useCreditCardForm.d.ts +10 -10
  27. package/dist/cjs/hooks/useCreditCardForm.js +71 -71
  28. package/dist/cjs/hooks/useCurbside.d.ts +9 -9
  29. package/dist/cjs/hooks/useCurbside.js +39 -39
  30. package/dist/cjs/hooks/useDineInForm.d.ts +11 -11
  31. package/dist/cjs/hooks/useDineInForm.js +56 -56
  32. package/dist/cjs/hooks/useDonationForm.d.ts +28 -28
  33. package/dist/cjs/hooks/useDonationForm.js +172 -172
  34. package/dist/cjs/hooks/useFirstTimes.d.ts +18 -18
  35. package/dist/cjs/hooks/useFirstTimes.js +81 -81
  36. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +14 -14
  37. package/dist/cjs/hooks/useGiftCardAssignForm.js +57 -57
  38. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
  39. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +50 -50
  40. package/dist/cjs/hooks/useGiftCardForm.d.ts +12 -12
  41. package/dist/cjs/hooks/useGiftCardForm.js +74 -74
  42. package/dist/cjs/hooks/useGiftCardsForm.d.ts +31 -31
  43. package/dist/cjs/hooks/useGiftCardsForm.js +195 -195
  44. package/dist/cjs/hooks/useGuestCheckoutForm.d.ts +21 -21
  45. package/dist/cjs/hooks/useGuestCheckoutForm.js +89 -89
  46. package/dist/cjs/hooks/useGuestForm.d.ts +12 -12
  47. package/dist/cjs/hooks/useGuestForm.js +60 -60
  48. package/dist/cjs/hooks/useImage.d.ts +5 -5
  49. package/dist/cjs/hooks/useImage.js +33 -33
  50. package/dist/cjs/hooks/useLoginForm.d.ts +12 -12
  51. package/dist/cjs/hooks/useLoginForm.js +67 -67
  52. package/dist/cjs/hooks/useMenuItem.d.ts +57 -57
  53. package/dist/cjs/hooks/useMenuItem.js +67 -67
  54. package/dist/cjs/hooks/useModifier.d.ts +53 -53
  55. package/dist/cjs/hooks/useModifier.js +72 -72
  56. package/dist/cjs/hooks/useModifierGroup.d.ts +15 -15
  57. package/dist/cjs/hooks/useModifierGroup.js +17 -17
  58. package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +16 -16
  59. package/dist/cjs/hooks/useOneTimePasscodeForm.js +87 -87
  60. package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +11 -11
  61. package/dist/cjs/hooks/useOrderFulfillmentForm.js +65 -65
  62. package/dist/cjs/hooks/useOrderItem.d.ts +48 -48
  63. package/dist/cjs/hooks/useOrderItem.js +54 -54
  64. package/dist/cjs/hooks/useOrderRating.d.ts +10 -10
  65. package/dist/cjs/hooks/useOrderRating.js +34 -34
  66. package/dist/cjs/hooks/useOrderRatingForm.d.ts +11 -11
  67. package/dist/cjs/hooks/useOrderRatingForm.js +35 -35
  68. package/dist/cjs/hooks/useProfileForm.d.ts +15 -15
  69. package/dist/cjs/hooks/useProfileForm.js +116 -116
  70. package/dist/cjs/hooks/useResetPasswordForm.d.ts +12 -12
  71. package/dist/cjs/hooks/useResetPasswordForm.js +77 -77
  72. package/dist/cjs/hooks/useSendResetForm.d.ts +14 -14
  73. package/dist/cjs/hooks/useSendResetForm.js +57 -57
  74. package/dist/cjs/hooks/useSignUpForm.d.ts +20 -20
  75. package/dist/cjs/hooks/useSignUpForm.js +160 -151
  76. package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
  77. package/dist/cjs/hooks/useSignUpGuestForm.js +124 -113
  78. package/dist/cjs/hooks/useSigninForm.d.ts +12 -12
  79. package/dist/cjs/hooks/useSigninForm.js +66 -66
  80. package/dist/cjs/index.d.ts +2 -2
  81. package/dist/cjs/index.js +5 -5
  82. package/dist/cjs/utils/cards.d.ts +20 -20
  83. package/dist/cjs/utils/cards.js +155 -155
  84. package/dist/cjs/utils/cart.d.ts +202 -202
  85. package/dist/cjs/utils/cart.js +909 -909
  86. package/dist/cjs/utils/checkout.d.ts +55 -55
  87. package/dist/cjs/utils/checkout.js +125 -125
  88. package/dist/cjs/utils/constants.d.ts +43 -43
  89. package/dist/cjs/utils/constants.js +58 -58
  90. package/dist/cjs/utils/customer.d.ts +4 -4
  91. package/dist/cjs/utils/customer.js +34 -34
  92. package/dist/cjs/utils/datetimes.d.ts +99 -99
  93. package/dist/cjs/utils/datetimes.js +601 -601
  94. package/dist/cjs/utils/errors.d.ts +51 -51
  95. package/dist/cjs/utils/errors.js +191 -191
  96. package/dist/cjs/utils/favorites.d.ts +10 -10
  97. package/dist/cjs/utils/favorites.js +119 -119
  98. package/dist/cjs/utils/googleMaps.d.ts +14 -14
  99. package/dist/cjs/utils/googleMaps.js +30 -30
  100. package/dist/cjs/utils/helpers.d.ts +63 -63
  101. package/dist/cjs/utils/helpers.js +244 -244
  102. package/dist/cjs/utils/index.d.ts +19 -19
  103. package/dist/cjs/utils/index.js +23 -23
  104. package/dist/cjs/utils/keypad.d.ts +9 -9
  105. package/dist/cjs/utils/keypad.js +105 -105
  106. package/dist/cjs/utils/maps.d.ts +226 -226
  107. package/dist/cjs/utils/maps.js +334 -334
  108. package/dist/cjs/utils/menu.d.ts +117 -117
  109. package/dist/cjs/utils/menu.js +82 -82
  110. package/dist/cjs/utils/orders.d.ts +21 -21
  111. package/dist/cjs/utils/orders.js +202 -202
  112. package/dist/cjs/utils/pizzaBuilder.d.ts +10 -10
  113. package/dist/cjs/utils/pizzaBuilder.js +43 -43
  114. package/dist/cjs/utils/refunds.d.ts +35 -35
  115. package/dist/cjs/utils/refunds.js +98 -98
  116. package/dist/cjs/utils/revenueCenters.d.ts +11 -11
  117. package/dist/cjs/utils/revenueCenters.js +125 -125
  118. package/dist/cjs/utils/rewards.d.ts +4 -4
  119. package/dist/cjs/utils/rewards.js +106 -106
  120. package/dist/cjs/utils/theme.d.ts +27 -27
  121. package/dist/cjs/utils/theme.js +266 -266
  122. package/dist/cjs/utils/version.d.ts +4 -4
  123. package/dist/cjs/utils/version.js +38 -38
  124. package/dist/esm/__tests__/utils/helpers.test.d.ts +1 -1
  125. package/dist/esm/__tests__/utils/helpers.test.js +94 -94
  126. package/dist/esm/__tests__/utils/theme.test.d.ts +1 -1
  127. package/dist/esm/__tests__/utils/theme.test.js +35 -35
  128. package/dist/esm/hooks/index.d.ts +35 -35
  129. package/dist/esm/hooks/index.js +35 -35
  130. package/dist/esm/hooks/types.d.ts +4 -4
  131. package/dist/esm/hooks/types.js +1 -1
  132. package/dist/esm/hooks/useAccordion.d.ts +22 -22
  133. package/dist/esm/hooks/useAccordion.js +52 -52
  134. package/dist/esm/hooks/useAddressForm.d.ts +12 -12
  135. package/dist/esm/hooks/useAddressForm.js +79 -79
  136. package/dist/esm/hooks/useAllergenForm.d.ts +10 -10
  137. package/dist/esm/hooks/useAllergenForm.js +54 -54
  138. package/dist/esm/hooks/useBuilder.d.ts +14 -14
  139. package/dist/esm/hooks/useBuilder.js +140 -140
  140. package/dist/esm/hooks/useCartGuestForm.d.ts +12 -12
  141. package/dist/esm/hooks/useCartGuestForm.js +54 -54
  142. package/dist/esm/hooks/useCartPoints.d.ts +13 -13
  143. package/dist/esm/hooks/useCartPoints.js +70 -70
  144. package/dist/esm/hooks/useCommunicationPreferences.js +1 -1
  145. package/dist/esm/hooks/useCreditCard.d.ts +13 -13
  146. package/dist/esm/hooks/useCreditCard.js +59 -59
  147. package/dist/esm/hooks/useCreditCardForm.d.ts +10 -10
  148. package/dist/esm/hooks/useCreditCardForm.js +67 -67
  149. package/dist/esm/hooks/useCurbside.d.ts +9 -9
  150. package/dist/esm/hooks/useCurbside.js +35 -35
  151. package/dist/esm/hooks/useDineInForm.d.ts +11 -11
  152. package/dist/esm/hooks/useDineInForm.js +52 -52
  153. package/dist/esm/hooks/useDonationForm.d.ts +28 -28
  154. package/dist/esm/hooks/useDonationForm.js +168 -168
  155. package/dist/esm/hooks/useFirstTimes.d.ts +18 -18
  156. package/dist/esm/hooks/useFirstTimes.js +77 -77
  157. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +14 -14
  158. package/dist/esm/hooks/useGiftCardAssignForm.js +53 -53
  159. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
  160. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +46 -46
  161. package/dist/esm/hooks/useGiftCardForm.d.ts +12 -12
  162. package/dist/esm/hooks/useGiftCardForm.js +70 -70
  163. package/dist/esm/hooks/useGiftCardsForm.d.ts +31 -31
  164. package/dist/esm/hooks/useGiftCardsForm.js +191 -191
  165. package/dist/esm/hooks/useGuestCheckoutForm.d.ts +21 -21
  166. package/dist/esm/hooks/useGuestCheckoutForm.js +85 -85
  167. package/dist/esm/hooks/useGuestForm.d.ts +12 -12
  168. package/dist/esm/hooks/useGuestForm.js +56 -56
  169. package/dist/esm/hooks/useImage.d.ts +5 -5
  170. package/dist/esm/hooks/useImage.js +29 -29
  171. package/dist/esm/hooks/useLoginForm.d.ts +12 -12
  172. package/dist/esm/hooks/useLoginForm.js +63 -63
  173. package/dist/esm/hooks/useMenuItem.d.ts +57 -57
  174. package/dist/esm/hooks/useMenuItem.js +63 -63
  175. package/dist/esm/hooks/useModifier.d.ts +53 -53
  176. package/dist/esm/hooks/useModifier.js +68 -68
  177. package/dist/esm/hooks/useModifierGroup.d.ts +15 -15
  178. package/dist/esm/hooks/useModifierGroup.js +13 -13
  179. package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +16 -16
  180. package/dist/esm/hooks/useOneTimePasscodeForm.js +83 -83
  181. package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +11 -11
  182. package/dist/esm/hooks/useOrderFulfillmentForm.js +61 -61
  183. package/dist/esm/hooks/useOrderItem.d.ts +48 -48
  184. package/dist/esm/hooks/useOrderItem.js +50 -50
  185. package/dist/esm/hooks/useOrderRating.d.ts +10 -10
  186. package/dist/esm/hooks/useOrderRating.js +30 -30
  187. package/dist/esm/hooks/useOrderRatingForm.d.ts +11 -11
  188. package/dist/esm/hooks/useOrderRatingForm.js +31 -31
  189. package/dist/esm/hooks/useProfileForm.d.ts +15 -15
  190. package/dist/esm/hooks/useProfileForm.js +112 -112
  191. package/dist/esm/hooks/useResetPasswordForm.d.ts +12 -12
  192. package/dist/esm/hooks/useResetPasswordForm.js +73 -73
  193. package/dist/esm/hooks/useSendResetForm.d.ts +14 -14
  194. package/dist/esm/hooks/useSendResetForm.js +53 -53
  195. package/dist/esm/hooks/useSignUpForm.d.ts +20 -20
  196. package/dist/esm/hooks/useSignUpForm.js +156 -147
  197. package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
  198. package/dist/esm/hooks/useSignUpGuestForm.js +120 -109
  199. package/dist/esm/hooks/useSigninForm.d.ts +12 -12
  200. package/dist/esm/hooks/useSigninForm.js +62 -62
  201. package/dist/esm/index.d.ts +2 -2
  202. package/dist/esm/index.js +2 -2
  203. package/dist/esm/utils/cards.d.ts +20 -20
  204. package/dist/esm/utils/cards.js +146 -146
  205. package/dist/esm/utils/cart.d.ts +202 -202
  206. package/dist/esm/utils/cart.js +868 -868
  207. package/dist/esm/utils/checkout.d.ts +55 -55
  208. package/dist/esm/utils/checkout.js +117 -117
  209. package/dist/esm/utils/constants.d.ts +43 -43
  210. package/dist/esm/utils/constants.js +55 -55
  211. package/dist/esm/utils/customer.d.ts +4 -4
  212. package/dist/esm/utils/customer.js +29 -29
  213. package/dist/esm/utils/datetimes.d.ts +99 -99
  214. package/dist/esm/utils/datetimes.js +531 -531
  215. package/dist/esm/utils/errors.d.ts +51 -51
  216. package/dist/esm/utils/errors.js +180 -180
  217. package/dist/esm/utils/favorites.d.ts +10 -10
  218. package/dist/esm/utils/favorites.js +109 -109
  219. package/dist/esm/utils/googleMaps.d.ts +14 -14
  220. package/dist/esm/utils/googleMaps.js +26 -26
  221. package/dist/esm/utils/helpers.d.ts +63 -63
  222. package/dist/esm/utils/helpers.js +205 -205
  223. package/dist/esm/utils/index.d.ts +19 -19
  224. package/dist/esm/utils/index.js +20 -20
  225. package/dist/esm/utils/keypad.d.ts +9 -9
  226. package/dist/esm/utils/keypad.js +97 -97
  227. package/dist/esm/utils/maps.d.ts +226 -226
  228. package/dist/esm/utils/maps.js +316 -316
  229. package/dist/esm/utils/menu.d.ts +117 -117
  230. package/dist/esm/utils/menu.js +74 -74
  231. package/dist/esm/utils/orders.d.ts +21 -21
  232. package/dist/esm/utils/orders.js +185 -185
  233. package/dist/esm/utils/pizzaBuilder.d.ts +10 -10
  234. package/dist/esm/utils/pizzaBuilder.js +38 -38
  235. package/dist/esm/utils/refunds.d.ts +35 -35
  236. package/dist/esm/utils/refunds.js +90 -90
  237. package/dist/esm/utils/revenueCenters.d.ts +11 -11
  238. package/dist/esm/utils/revenueCenters.js +115 -115
  239. package/dist/esm/utils/rewards.d.ts +4 -4
  240. package/dist/esm/utils/rewards.js +100 -100
  241. package/dist/esm/utils/theme.d.ts +27 -27
  242. package/dist/esm/utils/theme.js +254 -254
  243. package/dist/esm/utils/version.d.ts +4 -4
  244. package/dist/esm/utils/version.js +34 -34
  245. package/package.json +69 -68
@@ -1,151 +1,160 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSignUpForm = void 0;
4
- const react_1 = require("react");
5
- const utils_1 = require("../utils");
6
- const useProfileForm_1 = require("./useProfileForm");
7
- const initState = {
8
- first_name: '',
9
- last_name: '',
10
- email: '',
11
- phone: ''
12
- };
13
- const notificationChannelFields = [
14
- {
15
- label: 'Email',
16
- name: 'EMAIL',
17
- type: 'checkbox'
18
- },
19
- {
20
- label: 'SMS / Text',
21
- name: 'SMS',
22
- type: 'checkbox'
23
- },
24
- {
25
- label: 'Push Notifications',
26
- name: 'PUSH',
27
- type: 'checkbox'
28
- }
29
- ];
30
- const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements) => {
31
- const submitRef = (0, react_1.useRef)(null);
32
- const [data, setData] = (0, react_1.useState)(initState);
33
- const [comms, setComms] = (0, react_1.useState)([]);
34
- const [errors, setErrors] = (0, react_1.useState)({});
35
- const [submitting, setSubmitting] = (0, react_1.useState)(false);
36
- const { displayed, required } = checkConfig || {};
37
- const companyDisplayed = displayed && displayed.customer.includes('company');
38
- const companyRequired = required && required.customer.includes('company');
39
- const showCompany = companyDisplayed || companyRequired;
40
- const toRemove = [];
41
- if (!showCompany)
42
- toRemove.push('company');
43
- if (hidePassword)
44
- toRemove.push('password');
45
- if (optionalFields && !optionalFields.includes('birth_date'))
46
- toRemove.push('birth_date');
47
- if (optionalFields && !optionalFields.includes('gender'))
48
- toRemove.push('gender');
49
- const allFields = [
50
- {
51
- label: 'First Name',
52
- name: 'first_name',
53
- type: 'text',
54
- required: true
55
- },
56
- {
57
- label: 'Last Name',
58
- name: 'last_name',
59
- type: 'text',
60
- required: true
61
- },
62
- {
63
- label: 'Email',
64
- name: 'email',
65
- type: 'email',
66
- required: true,
67
- autoComplete: 'email'
68
- },
69
- {
70
- label: `Password${passwordRequirements || ''}`,
71
- name: 'password',
72
- type: 'password',
73
- required: true,
74
- autoComplete: 'new-password'
75
- },
76
- { label: 'Phone', name: 'phone', type: 'tel', required: true },
77
- {
78
- label: 'Company',
79
- name: 'company',
80
- type: 'text',
81
- required: companyRequired
82
- },
83
- { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
84
- {
85
- label: 'Gender',
86
- name: 'gender',
87
- type: 'select',
88
- showLabel: true,
89
- options: useProfileForm_1.genderOptions
90
- }
91
- ];
92
- const fields = allFields.filter(i => !toRemove.includes(i.name));
93
- const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
94
- (0, react_1.useEffect)(() => {
95
- return () => {
96
- setData(initState);
97
- setErrors({});
98
- };
99
- }, []);
100
- (0, react_1.useEffect)(() => {
101
- if (loading === 'idle') {
102
- setSubmitting(false);
103
- if (error) {
104
- const errs = (0, utils_1.makeFormErrors)(error);
105
- if (errs.birth_date) {
106
- errs.birth_date =
107
- 'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
108
- }
109
- setErrors(errs);
110
- }
111
- }
112
- }, [loading, error]);
113
- const handleChange = (name, value) => {
114
- const inputValue = name === 'phone'
115
- ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : ''))
116
- : name === 'birth_date'
117
- ? (0, utils_1.makeBirthDate)(value)
118
- : value;
119
- setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
120
- };
121
- const handleComms = (name, value) => {
122
- const other = comms.filter(i => i !== name);
123
- const updated = value ? [...other, name] : other;
124
- setComms(updated);
125
- };
126
- const handleSubmit = (evt) => {
127
- var _a, _b;
128
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
129
- setErrors({});
130
- setSubmitting(true);
131
- const values = Object.assign(Object.assign({}, data), { communications: comms });
132
- if (values.birth_date) {
133
- values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
134
- }
135
- signUp(values, callback);
136
- ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
137
- };
138
- return {
139
- submitRef,
140
- data,
141
- comms,
142
- errors,
143
- submitting,
144
- fields,
145
- notificationFields,
146
- handleChange,
147
- handleComms,
148
- handleSubmit
149
- };
150
- };
151
- exports.useSignUpForm = useSignUpForm;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSignUpForm = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("../utils");
6
+ const useProfileForm_1 = require("./useProfileForm");
7
+ const initState = {
8
+ first_name: '',
9
+ last_name: '',
10
+ email: '',
11
+ phone: ''
12
+ };
13
+ const notificationChannelFields = [
14
+ {
15
+ label: 'Email',
16
+ name: 'EMAIL',
17
+ type: 'checkbox'
18
+ },
19
+ {
20
+ label: 'SMS / Text',
21
+ name: 'SMS',
22
+ type: 'checkbox'
23
+ },
24
+ {
25
+ label: 'Push Notifications',
26
+ name: 'PUSH',
27
+ type: 'checkbox'
28
+ }
29
+ ];
30
+ const useSignUpForm = (loading, error, signUp, callback, checkConfig, hidePassword = false, optionalFields, notificationChannels, passwordRequirements, tpls) => {
31
+ const submitRef = (0, react_1.useRef)(null);
32
+ const [data, setData] = (0, react_1.useState)(initState);
33
+ const [comms, setComms] = (0, react_1.useState)([]);
34
+ const [errors, setErrors] = (0, react_1.useState)({});
35
+ const [submitting, setSubmitting] = (0, react_1.useState)(false);
36
+ const { displayed, required } = checkConfig || {};
37
+ const hasPunchh = tpls === 'PUNCHH';
38
+ const companyDisplayed = displayed && displayed.customer.includes('company');
39
+ const companyRequired = required && required.customer.includes('company');
40
+ const showCompany = companyDisplayed || companyRequired;
41
+ const toRemove = [];
42
+ if (!showCompany)
43
+ toRemove.push('company');
44
+ if (hidePassword)
45
+ toRemove.push('password');
46
+ if (optionalFields && !optionalFields.includes('birth_date'))
47
+ toRemove.push('birth_date');
48
+ if (optionalFields && !optionalFields.includes('gender'))
49
+ toRemove.push('gender');
50
+ if (!hasPunchh)
51
+ toRemove.push('birth_date');
52
+ const allFields = [
53
+ {
54
+ label: 'First Name',
55
+ name: 'first_name',
56
+ type: 'text',
57
+ required: true
58
+ },
59
+ {
60
+ label: 'Last Name',
61
+ name: 'last_name',
62
+ type: 'text',
63
+ required: true
64
+ },
65
+ {
66
+ label: 'Email',
67
+ name: 'email',
68
+ type: 'email',
69
+ required: true,
70
+ autoComplete: 'email'
71
+ },
72
+ {
73
+ label: `Password${passwordRequirements || ''}`,
74
+ name: 'password',
75
+ type: 'password',
76
+ required: true,
77
+ autoComplete: 'new-password'
78
+ },
79
+ { label: 'Phone', name: 'phone', type: 'tel', required: true },
80
+ {
81
+ label: 'Birth Date',
82
+ name: 'birth_date',
83
+ type: 'date',
84
+ required: true
85
+ },
86
+ {
87
+ label: 'Company',
88
+ name: 'company',
89
+ type: 'text',
90
+ required: companyRequired
91
+ },
92
+ { label: 'Birth Date (mm/dd/yyyy)', name: 'birth_date', type: 'tel' },
93
+ {
94
+ label: 'Gender',
95
+ name: 'gender',
96
+ type: 'select',
97
+ showLabel: true,
98
+ options: useProfileForm_1.genderOptions
99
+ }
100
+ ];
101
+ const fields = allFields.filter(i => !toRemove.includes(i.name));
102
+ const notificationFields = notificationChannelFields.filter(i => notificationChannels === null || notificationChannels === void 0 ? void 0 : notificationChannels.includes(i.name));
103
+ (0, react_1.useEffect)(() => {
104
+ return () => {
105
+ setData(initState);
106
+ setErrors({});
107
+ };
108
+ }, []);
109
+ (0, react_1.useEffect)(() => {
110
+ if (loading === 'idle') {
111
+ setSubmitting(false);
112
+ if (error) {
113
+ const errs = (0, utils_1.makeFormErrors)(error);
114
+ if (errs.birth_date) {
115
+ errs.birth_date =
116
+ 'Invalid date. Please enter in mm/dd/yyyy format or leave blank.';
117
+ }
118
+ setErrors(errs);
119
+ }
120
+ }
121
+ }, [loading, error]);
122
+ const handleChange = (name, value) => {
123
+ const inputValue = name === 'phone'
124
+ ? (0, utils_1.makePhone)((value !== null && value !== void 0 ? value : ''))
125
+ : name === 'birth_date'
126
+ ? (0, utils_1.makeBirthDate)(value)
127
+ : value;
128
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
129
+ };
130
+ const handleComms = (name, value) => {
131
+ const other = comms.filter(i => i !== name);
132
+ const updated = value ? [...other, name] : other;
133
+ setComms(updated);
134
+ };
135
+ const handleSubmit = (evt) => {
136
+ var _a, _b;
137
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
138
+ setErrors({});
139
+ setSubmitting(true);
140
+ const values = Object.assign(Object.assign({}, data), { communications: comms });
141
+ if (values.birth_date) {
142
+ values.birth_date = (0, utils_1.slashesToDashes)(values.birth_date);
143
+ }
144
+ signUp(values, callback);
145
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
146
+ };
147
+ return {
148
+ submitRef,
149
+ data,
150
+ comms,
151
+ errors,
152
+ submitting,
153
+ fields,
154
+ notificationFields,
155
+ handleChange,
156
+ handleComms,
157
+ handleSubmit
158
+ };
159
+ };
160
+ exports.useSignUpForm = useSignUpForm;
@@ -1,23 +1,23 @@
1
- /// <reference types="react" />
2
- import { CheckoutFormCustomer, CustomerCreate, FormFields, RequestError, RequestStatus } from '@open-tender/types';
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
- submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- fields: FormFields;
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
- };
16
- errors: Record<string, string>;
17
- disabled: boolean;
18
- guestDisabled: boolean;
19
- submitting: boolean;
20
- handleChange: (name: string, value: string | number | boolean) => void;
21
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
22
- handleGuest: () => void;
23
- };
1
+ /// <reference types="react" />
2
+ import { CheckoutFormCustomer, ConfigBrand, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
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, tpls?: ConfigBrand['tpls']) => {
4
+ submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
+ inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
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
+ };
16
+ errors: Record<string, string>;
17
+ disabled: boolean;
18
+ guestDisabled: boolean;
19
+ submitting: boolean;
20
+ handleChange: (name: string, value: string | number | boolean) => void;
21
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
22
+ handleGuest: () => void;
23
+ };
@@ -1,113 +1,124 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSignUpGuestForm = void 0;
4
- const react_1 = require("react");
5
- const utils_1 = require("../utils");
6
- const initialData = {
7
- first_name: '',
8
- last_name: '',
9
- phone: '',
10
- password: ''
11
- };
12
- const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, hasThanx) => {
13
- const submitRef = (0, react_1.useRef)(null);
14
- const inputRef = (0, react_1.useRef)(null);
15
- const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
16
- const [data, setData] = (0, react_1.useState)(initData);
17
- const [errors, setErrors] = (0, react_1.useState)({});
18
- const [submitting, setSubmitting] = (0, react_1.useState)(false);
19
- const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
20
- const isIncomplete = hasThanx ? guestIncomplete : (0, utils_1.checkEmpty)(data);
21
- const isLoading = loading === 'pending';
22
- const disabled = isIncomplete || isLoading;
23
- const guestDisabled = guestIncomplete || isLoading;
24
- const allFields = [
25
- {
26
- label: 'Email',
27
- name: 'email',
28
- type: 'email',
29
- required: true,
30
- disabled: true
31
- },
32
- {
33
- label: 'First Name',
34
- name: 'first_name',
35
- type: 'text',
36
- required: true
37
- },
38
- {
39
- label: 'Last Name',
40
- name: 'last_name',
41
- type: 'text',
42
- required: true
43
- },
44
- { label: 'Phone', name: 'phone', type: 'tel', required: true },
45
- {
46
- label: 'Password',
47
- name: 'password',
48
- type: 'password',
49
- autoComplete: 'new-password'
50
- }
51
- ];
52
- const fields = hasThanx
53
- ? allFields.filter(i => i.name !== 'password')
54
- : allFields;
55
- const handleChange = (name, value) => {
56
- const val = name === 'phone' ? (0, utils_1.makePhone)(value) : value;
57
- setData(Object.assign(Object.assign({}, data), { [name]: val }));
58
- };
59
- const handleSubmit = (evt) => {
60
- var _a, _b;
61
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
62
- if (!disabled) {
63
- setErrors({});
64
- setSubmitting(true);
65
- signUp(Object.assign(Object.assign({}, data), { email }));
66
- ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
67
- }
68
- };
69
- const handleGuest = () => {
70
- if (!guestDisabled) {
71
- setErrors({});
72
- setSubmitting(true);
73
- submitGuest(Object.assign(Object.assign({}, guestData), { email }));
74
- }
75
- };
76
- (0, react_1.useEffect)(() => {
77
- var _a, _b;
78
- if (loading === 'idle') {
79
- setSubmitting(false);
80
- if (error) {
81
- const errs = (0, utils_1.makeFormErrors)(error);
82
- if (errs.form.includes('parameters')) {
83
- errs.form = 'There are one or more errors below';
84
- }
85
- setErrors(errs);
86
- ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
87
- }
88
- else if (guestErrors) {
89
- setErrors(guestErrors);
90
- }
91
- }
92
- }, [loading, error, guestErrors]);
93
- (0, react_1.useEffect)(() => {
94
- return () => {
95
- setData(Object.assign(Object.assign({}, initialData), { email: '' }));
96
- setErrors({});
97
- };
98
- }, []);
99
- return {
100
- submitRef,
101
- inputRef,
102
- fields,
103
- data,
104
- errors,
105
- disabled,
106
- guestDisabled,
107
- submitting,
108
- handleChange,
109
- handleSubmit,
110
- handleGuest
111
- };
112
- };
113
- exports.useSignUpGuestForm = useSignUpGuestForm;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSignUpGuestForm = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("../utils");
6
+ const initialData = {
7
+ first_name: '',
8
+ last_name: '',
9
+ phone: '',
10
+ password: ''
11
+ };
12
+ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, submitGuest, tpls) => {
13
+ const submitRef = (0, react_1.useRef)(null);
14
+ const inputRef = (0, react_1.useRef)(null);
15
+ const initData = Object.assign(Object.assign(Object.assign({}, initialData), guest), { email });
16
+ const [data, setData] = (0, react_1.useState)(initData);
17
+ const [errors, setErrors] = (0, react_1.useState)({});
18
+ const [submitting, setSubmitting] = (0, react_1.useState)(false);
19
+ const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
20
+ const hasThanx = tpls === 'THANX';
21
+ const hasPunchh = tpls === 'PUNCHH';
22
+ const isIncomplete = hasThanx ? guestIncomplete : (0, utils_1.checkEmpty)(data);
23
+ const isLoading = loading === 'pending';
24
+ const disabled = isIncomplete || isLoading;
25
+ const guestDisabled = guestIncomplete || isLoading;
26
+ const toRemove = [];
27
+ if (!hasPunchh)
28
+ toRemove.push('birth_date');
29
+ if (hasThanx)
30
+ toRemove.push('password');
31
+ const allFields = [
32
+ {
33
+ label: 'Email',
34
+ name: 'email',
35
+ type: 'email',
36
+ required: true,
37
+ disabled: true
38
+ },
39
+ {
40
+ label: 'First Name',
41
+ name: 'first_name',
42
+ type: 'text',
43
+ required: true
44
+ },
45
+ {
46
+ label: 'Last Name',
47
+ name: 'last_name',
48
+ type: 'text',
49
+ required: true
50
+ },
51
+ { label: 'Phone', name: 'phone', type: 'tel', required: true },
52
+ {
53
+ label: 'Birth Date',
54
+ name: 'birth_date',
55
+ type: 'date',
56
+ required: false
57
+ },
58
+ {
59
+ label: 'Password',
60
+ name: 'password',
61
+ type: 'password',
62
+ autoComplete: 'new-password'
63
+ }
64
+ ];
65
+ const fields = allFields.filter(i => !toRemove.includes(i.name));
66
+ const handleChange = (name, value) => {
67
+ const val = name === 'phone' ? (0, utils_1.makePhone)(value) : value;
68
+ setData(Object.assign(Object.assign({}, data), { [name]: val }));
69
+ };
70
+ const handleSubmit = (evt) => {
71
+ var _a, _b;
72
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
73
+ if (!disabled) {
74
+ setErrors({});
75
+ setSubmitting(true);
76
+ signUp(Object.assign(Object.assign({}, data), { email }));
77
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
78
+ }
79
+ };
80
+ const handleGuest = () => {
81
+ if (!guestDisabled) {
82
+ setErrors({});
83
+ setSubmitting(true);
84
+ submitGuest(Object.assign(Object.assign({}, guestData), { email }));
85
+ }
86
+ };
87
+ (0, react_1.useEffect)(() => {
88
+ var _a, _b;
89
+ if (loading === 'idle') {
90
+ setSubmitting(false);
91
+ if (error) {
92
+ const errs = (0, utils_1.makeFormErrors)(error);
93
+ if (errs.form.includes('parameters')) {
94
+ errs.form = 'There are one or more errors below';
95
+ }
96
+ setErrors(errs);
97
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
98
+ }
99
+ else if (guestErrors) {
100
+ setErrors(guestErrors);
101
+ }
102
+ }
103
+ }, [loading, error, guestErrors]);
104
+ (0, react_1.useEffect)(() => {
105
+ return () => {
106
+ setData(Object.assign(Object.assign({}, initialData), { email: '' }));
107
+ setErrors({});
108
+ };
109
+ }, []);
110
+ return {
111
+ submitRef,
112
+ inputRef,
113
+ fields,
114
+ data,
115
+ errors,
116
+ disabled,
117
+ guestDisabled,
118
+ submitting,
119
+ handleChange,
120
+ handleSubmit,
121
+ handleGuest
122
+ };
123
+ };
124
+ exports.useSignUpGuestForm = useSignUpGuestForm;
@@ -1,12 +1,12 @@
1
- /// <reference types="react" />
2
- import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password: string) => void, callback?: () => void) => {
4
- submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
- inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
- fields: FormFields;
7
- data: LoginData;
8
- errors: Record<string, string>;
9
- submitting: boolean;
10
- handleChange: (name: string, value: string | number | boolean) => void;
11
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
- };
1
+ /// <reference types="react" />
2
+ import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
+ export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password: string) => void, callback?: () => void) => {
4
+ submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
+ inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
+ fields: FormFields;
7
+ data: LoginData;
8
+ errors: Record<string, string>;
9
+ submitting: boolean;
10
+ handleChange: (name: string, value: string | number | boolean) => void;
11
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
+ };