@open-tender/utils 0.0.56 → 0.0.59

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/types.d.ts +4 -0
  2. package/dist/cjs/hooks/types.js +2 -0
  3. package/dist/cjs/hooks/useAddressForm.d.ts +2 -5
  4. package/dist/cjs/hooks/useAddressForm.js +3 -3
  5. package/dist/cjs/hooks/useAllergenForm.d.ts +5 -2
  6. package/dist/cjs/hooks/useAllergenForm.js +8 -4
  7. package/dist/cjs/hooks/useCartGuestForm.d.ts +21 -0
  8. package/dist/cjs/hooks/useCartGuestForm.js +46 -0
  9. package/dist/cjs/hooks/useCheckoutLoginForm.d.ts +12 -0
  10. package/dist/cjs/hooks/useCheckoutLoginForm.js +41 -0
  11. package/dist/cjs/hooks/useCommunicationPreferences.d.ts +0 -0
  12. package/dist/cjs/hooks/useCommunicationPreferences.js +1 -0
  13. package/dist/cjs/hooks/useCreditCard.d.ts +8 -11
  14. package/dist/cjs/hooks/useCreditCard.js +61 -41
  15. package/dist/cjs/hooks/useDineInForm.d.ts +8 -3
  16. package/dist/cjs/hooks/useDineInForm.js +8 -2
  17. package/dist/cjs/hooks/useDonationForm.d.ts +4 -1
  18. package/dist/cjs/hooks/useDonationForm.js +17 -3
  19. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +5 -7
  20. package/dist/cjs/hooks/useGiftCardAssignForm.js +11 -3
  21. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
  22. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +8 -0
  23. package/dist/cjs/hooks/useGiftCardForm.d.ts +9 -5
  24. package/dist/cjs/hooks/useGiftCardForm.js +13 -4
  25. package/dist/cjs/hooks/useGiftCardsForm.d.ts +30 -11
  26. package/dist/cjs/hooks/useGiftCardsForm.js +72 -31
  27. package/dist/cjs/hooks/useGuestForm.d.ts +13 -0
  28. package/dist/cjs/hooks/useGuestForm.js +41 -0
  29. package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +13 -0
  30. package/dist/cjs/hooks/useOrderFulfillmentForm.js +40 -0
  31. package/dist/cjs/hooks/useOrderRatingForm.d.ts +13 -0
  32. package/dist/cjs/hooks/useOrderRatingForm.js +33 -0
  33. package/dist/cjs/hooks/useProfileForm.d.ts +18 -23
  34. package/dist/cjs/hooks/useProfileForm.js +27 -28
  35. package/dist/cjs/hooks/useResetPasswordForm.d.ts +20 -0
  36. package/dist/cjs/hooks/useResetPasswordForm.js +66 -0
  37. package/dist/cjs/hooks/useSendResetForm.d.ts +12 -0
  38. package/dist/cjs/hooks/useSendResetForm.js +36 -0
  39. package/dist/cjs/hooks/useSignUpForm.d.ts +21 -0
  40. package/dist/cjs/hooks/useSignUpForm.js +91 -0
  41. package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -0
  42. package/dist/cjs/hooks/useSignUpGuestForm.js +74 -0
  43. package/dist/cjs/hooks/useSigninForm.d.ts +12 -0
  44. package/dist/cjs/hooks/useSigninForm.js +41 -0
  45. package/dist/cjs/utils/cart.js +2 -2
  46. package/dist/esm/hooks/types.d.ts +4 -0
  47. package/dist/esm/hooks/types.js +1 -0
  48. package/dist/esm/hooks/useAddressForm.d.ts +2 -5
  49. package/dist/esm/hooks/useAddressForm.js +3 -3
  50. package/dist/esm/hooks/useAllergenForm.d.ts +5 -2
  51. package/dist/esm/hooks/useAllergenForm.js +9 -5
  52. package/dist/esm/hooks/useCartGuestForm.d.ts +21 -0
  53. package/dist/esm/hooks/useCartGuestForm.js +44 -0
  54. package/dist/esm/hooks/useCheckoutLoginForm.d.ts +12 -0
  55. package/dist/esm/hooks/useCheckoutLoginForm.js +39 -0
  56. package/dist/esm/hooks/useCommunicationPreferences.d.ts +0 -0
  57. package/dist/esm/hooks/useCommunicationPreferences.js +1 -0
  58. package/dist/esm/hooks/useCreditCard.d.ts +8 -11
  59. package/dist/esm/hooks/useCreditCard.js +62 -42
  60. package/dist/esm/hooks/useDineInForm.d.ts +8 -3
  61. package/dist/esm/hooks/useDineInForm.js +9 -3
  62. package/dist/esm/hooks/useDonationForm.d.ts +4 -1
  63. package/dist/esm/hooks/useDonationForm.js +17 -3
  64. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +5 -7
  65. package/dist/esm/hooks/useGiftCardAssignForm.js +12 -4
  66. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
  67. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +9 -1
  68. package/dist/esm/hooks/useGiftCardForm.d.ts +9 -5
  69. package/dist/esm/hooks/useGiftCardForm.js +14 -5
  70. package/dist/esm/hooks/useGiftCardsForm.d.ts +30 -11
  71. package/dist/esm/hooks/useGiftCardsForm.js +73 -32
  72. package/dist/esm/hooks/useGuestForm.d.ts +13 -0
  73. package/dist/esm/hooks/useGuestForm.js +39 -0
  74. package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +13 -0
  75. package/dist/esm/hooks/useOrderFulfillmentForm.js +38 -0
  76. package/dist/esm/hooks/useOrderRatingForm.d.ts +13 -0
  77. package/dist/esm/hooks/useOrderRatingForm.js +31 -0
  78. package/dist/esm/hooks/useProfileForm.d.ts +18 -23
  79. package/dist/esm/hooks/useProfileForm.js +28 -29
  80. package/dist/esm/hooks/useResetPasswordForm.d.ts +20 -0
  81. package/dist/esm/hooks/useResetPasswordForm.js +64 -0
  82. package/dist/esm/hooks/useSendResetForm.d.ts +12 -0
  83. package/dist/esm/hooks/useSendResetForm.js +34 -0
  84. package/dist/esm/hooks/useSignUpForm.d.ts +21 -0
  85. package/dist/esm/hooks/useSignUpForm.js +89 -0
  86. package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -0
  87. package/dist/esm/hooks/useSignUpGuestForm.js +72 -0
  88. package/dist/esm/hooks/useSigninForm.d.ts +12 -0
  89. package/dist/esm/hooks/useSigninForm.js +39 -0
  90. package/dist/esm/utils/cart.js +2 -2
  91. package/package.json +2 -2
@@ -0,0 +1,89 @@
1
+ import { useRef, useState, useEffect } from 'react';
2
+ import { makePhone } from '@open-tender/utils';
3
+ const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}, hasThanx = false) => {
4
+ const { displayed, required } = checkConfig || {};
5
+ const companyDisplayed = displayed && displayed.customer.includes('company');
6
+ const companyRequired = required && required.customer.includes('company');
7
+ const submitRef = useRef(null);
8
+ const [data, setData] = useState({});
9
+ const [errors, setErrors] = useState({});
10
+ const [submitting, setSubmitting] = useState(false);
11
+ const errMsg = error ? 'There are one or more errors below.' : null;
12
+ let fields = [
13
+ {
14
+ label: 'First Name',
15
+ name: 'first_name',
16
+ type: 'text',
17
+ required: true,
18
+ },
19
+ {
20
+ label: 'Last Name',
21
+ name: 'last_name',
22
+ type: 'text',
23
+ required: true,
24
+ },
25
+ {
26
+ label: 'Email',
27
+ name: 'email',
28
+ type: 'email',
29
+ required: true,
30
+ autoComplete: 'email',
31
+ },
32
+ {
33
+ label: 'Password',
34
+ name: 'password',
35
+ type: 'password',
36
+ required: true,
37
+ autoComplete: 'new-password',
38
+ },
39
+ { label: 'Phone', name: 'phone', type: 'tel', required: true },
40
+ ];
41
+ if (companyDisplayed || companyRequired) {
42
+ const company = {
43
+ label: 'Company',
44
+ name: 'company',
45
+ type: 'text',
46
+ required: companyRequired,
47
+ };
48
+ fields = [...fields, company];
49
+ }
50
+ const formfields = hasThanx
51
+ ? fields.filter((i) => i.name !== 'password')
52
+ : fields;
53
+ useEffect(() => {
54
+ return () => {
55
+ setData({});
56
+ setErrors({});
57
+ };
58
+ }, []);
59
+ useEffect(() => {
60
+ if (loading === 'idle') {
61
+ setSubmitting(false);
62
+ if (error) {
63
+ setErrors(error);
64
+ }
65
+ }
66
+ }, [loading, error]);
67
+ const handleChange = (name, type, value, checked) => {
68
+ const inputValue = type === 'checkbox' ? checked : name === 'phone' ? makePhone(value !== null && value !== void 0 ? value : "") : value;
69
+ setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
70
+ };
71
+ const handleSubmit = () => {
72
+ var _a, _b;
73
+ setErrors({});
74
+ setSubmitting(true);
75
+ signUp(data, callback);
76
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
77
+ };
78
+ return {
79
+ submitRef,
80
+ data,
81
+ errors,
82
+ submitting,
83
+ formfields,
84
+ errMsg,
85
+ handleChange,
86
+ handleSubmit,
87
+ };
88
+ };
89
+ export default useSignUpForm;
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import { GuestData, RequestStatus } from '@open-tender/types';
3
+ import { Field } from './types';
4
+ declare const useSignUpGuestForm: <InputRef extends Field, SubmitRef extends Field>(email: string, guest: Partial<GuestData>, loading: RequestStatus, error: any, signUp: (data: any) => void, submitGuest: (data: Partial<GuestData>) => void, hasThanx?: boolean) => {
5
+ submitRef: import("react").MutableRefObject<SubmitRef | null>;
6
+ inputRef: import("react").MutableRefObject<InputRef | null>;
7
+ data: {
8
+ first_name?: string | undefined;
9
+ email?: string | undefined;
10
+ last_name?: string | undefined;
11
+ phone?: string | undefined;
12
+ password?: string | undefined;
13
+ };
14
+ disabled: boolean;
15
+ guestDisabled: boolean;
16
+ errors: {};
17
+ errMsg: string | null;
18
+ submitting: boolean;
19
+ handleChange: (id: string, value: string) => void;
20
+ handleSubmit: () => void;
21
+ handleGuest: () => void;
22
+ };
23
+ export default useSignUpGuestForm;
@@ -0,0 +1,72 @@
1
+ import { useRef, useState, useEffect } from 'react';
2
+ import { checkEmpty, checkGuestData, makePhone } from '@open-tender/utils';
3
+ const initialData = {
4
+ first_name: '',
5
+ last_name: '',
6
+ phone: '',
7
+ password: '',
8
+ };
9
+ const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, hasThanx) => {
10
+ const submitRef = useRef(null);
11
+ const inputRef = useRef(null);
12
+ const initData = Object.assign(Object.assign({}, initialData), guest);
13
+ const [data, setData] = useState(initData);
14
+ const [errors, setErrors] = useState({});
15
+ const [submitting, setSubmitting] = useState(false);
16
+ const { guestData, guestIncomplete } = checkGuestData(data, email);
17
+ const isIncomplete = hasThanx ? guestIncomplete : checkEmpty(data);
18
+ const isLoading = loading === 'pending';
19
+ const disabled = isIncomplete || isLoading;
20
+ const guestDisabled = guestIncomplete || isLoading;
21
+ const errMsg = (error === null || error === void 0 ? void 0 : error.form) ? 'There are one or more errors below' : null;
22
+ const handleChange = (id, value) => {
23
+ const val = id === 'phone' ? makePhone(value) : value;
24
+ setData(Object.assign(Object.assign({}, data), { [id]: val }));
25
+ };
26
+ useEffect(() => {
27
+ return () => {
28
+ setData({});
29
+ setErrors({});
30
+ };
31
+ }, []);
32
+ useEffect(() => {
33
+ var _a, _b;
34
+ if (loading === 'idle') {
35
+ setSubmitting(false);
36
+ if (error) {
37
+ setErrors(error);
38
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
39
+ }
40
+ }
41
+ }, [loading, error]);
42
+ const handleSubmit = () => {
43
+ var _a, _b;
44
+ if (!disabled) {
45
+ setErrors({});
46
+ setSubmitting(true);
47
+ signUp(Object.assign(Object.assign({}, data), { email }));
48
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
49
+ }
50
+ };
51
+ const handleGuest = () => {
52
+ if (!guestDisabled) {
53
+ setErrors({});
54
+ setSubmitting(true);
55
+ submitGuest(Object.assign(Object.assign({}, guestData), { email }));
56
+ }
57
+ };
58
+ return {
59
+ submitRef,
60
+ inputRef,
61
+ data,
62
+ disabled,
63
+ guestDisabled,
64
+ errors,
65
+ errMsg,
66
+ submitting,
67
+ handleChange,
68
+ handleSubmit,
69
+ handleGuest,
70
+ };
71
+ };
72
+ export default useSignUpGuestForm;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { LoginData, RequestStatus } from '@open-tender/types';
3
+ import { Field } from './types';
4
+ declare const useSignInForm: <InputRef extends Field, SubmitRef extends Field>(email: string, loading: RequestStatus, error: any, login: (email?: string, password?: string) => void, callback?: () => void) => {
5
+ submitRef: import("react").MutableRefObject<SubmitRef | null>;
6
+ inputRef: import("react").MutableRefObject<InputRef | null>;
7
+ data: Partial<LoginData>;
8
+ submitting: boolean;
9
+ handleChange: (name: string, value: string) => void;
10
+ handleSubmit: () => void;
11
+ };
12
+ export default useSignInForm;
@@ -0,0 +1,39 @@
1
+ import { useState, useEffect, useRef } from 'react';
2
+ const useSignInForm = (email, loading, error, login, callback) => {
3
+ const submitRef = useRef(null);
4
+ const inputRef = useRef(null);
5
+ const [hasSubmit, setHasSubmit] = useState(false);
6
+ const [data, setData] = useState({ email });
7
+ const submitting = loading === 'pending';
8
+ useEffect(() => {
9
+ var _a, _b;
10
+ if (loading === 'idle' && hasSubmit) {
11
+ if (error) {
12
+ setHasSubmit(false);
13
+ ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
14
+ }
15
+ else if (callback) {
16
+ callback();
17
+ }
18
+ }
19
+ }, [loading, error, hasSubmit, callback]);
20
+ const handleChange = (name, value) => {
21
+ setData(Object.assign(Object.assign({}, data), { [name]: value }));
22
+ };
23
+ const handleSubmit = () => {
24
+ var _a, _b;
25
+ setHasSubmit(true);
26
+ const { email, password } = data;
27
+ login(email, password);
28
+ ((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
29
+ };
30
+ return {
31
+ submitRef,
32
+ inputRef,
33
+ data,
34
+ submitting,
35
+ handleChange,
36
+ handleSubmit,
37
+ };
38
+ };
39
+ export default useSignInForm;
@@ -241,8 +241,8 @@ export const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints
241
241
  description: item.description,
242
242
  imageUrl: item.large_image_url,
243
243
  slug: item.slug,
244
- allergens: convertStringToArray(item.allergens.join()),
245
- tags: convertStringToArray(item.tags.join()),
244
+ allergens: convertStringToArray(Array.from(item.allergens).join()),
245
+ tags: convertStringToArray(Array.from(item.tags).join()),
246
246
  ingredients: item.ingredients,
247
247
  nutritionalInfo: item.nutritional_info,
248
248
  cals: isNaN(cals !== null && cals !== void 0 ? cals : 0) ? null : cals,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.56",
3
+ "version": "0.0.59",
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",
@@ -59,7 +59,7 @@
59
59
  "react": "^18.2.0"
60
60
  },
61
61
  "dependencies": {
62
- "@open-tender/types": "^0.0.128",
62
+ "@open-tender/types": "^0.0.130",
63
63
  "date-fns": "^2.29.3",
64
64
  "date-fns-tz": "^1.3.7"
65
65
  }