@open-tender/utils 0.0.33 → 0.0.35

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 (63) hide show
  1. package/dist/cjs/hooks/index.d.ts +14 -0
  2. package/dist/cjs/hooks/index.js +14 -0
  3. package/dist/cjs/hooks/useAddressForm.d.ts +13 -0
  4. package/dist/cjs/hooks/useAddressForm.js +54 -0
  5. package/dist/cjs/hooks/useAllergenForm.d.ts +9 -0
  6. package/dist/cjs/hooks/useAllergenForm.js +44 -0
  7. package/dist/cjs/hooks/useCreditCard.d.ts +14 -0
  8. package/dist/cjs/hooks/useCreditCard.js +53 -0
  9. package/dist/cjs/hooks/useCurbside.d.ts +10 -0
  10. package/dist/cjs/hooks/useCurbside.js +37 -0
  11. package/dist/cjs/hooks/useDineInForm.d.ts +7 -0
  12. package/dist/cjs/hooks/useDineInForm.js +25 -0
  13. package/dist/cjs/hooks/useDonationForm.d.ts +25 -0
  14. package/dist/cjs/hooks/useDonationForm.js +155 -0
  15. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +15 -0
  16. package/dist/cjs/hooks/useGiftCardAssignForm.js +38 -0
  17. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
  18. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +31 -0
  19. package/dist/cjs/hooks/useGiftCardForm.d.ts +13 -0
  20. package/dist/cjs/hooks/useGiftCardForm.js +48 -0
  21. package/dist/cjs/hooks/useGiftCardsForm.d.ts +23 -0
  22. package/dist/cjs/hooks/useGiftCardsForm.js +146 -0
  23. package/dist/cjs/hooks/useLatLng.d.ts +8 -0
  24. package/dist/cjs/hooks/useLatLng.js +13 -0
  25. package/dist/cjs/hooks/useLoyaltyPoints.d.ts +2 -0
  26. package/dist/cjs/hooks/useLoyaltyPoints.js +18 -0
  27. package/dist/cjs/hooks/useOrderRating.d.ts +11 -0
  28. package/dist/cjs/hooks/useOrderRating.js +32 -0
  29. package/dist/cjs/hooks/useProfileForm.d.ts +29 -0
  30. package/dist/cjs/hooks/useProfileForm.js +75 -0
  31. package/dist/cjs/utils/helpers.d.ts +1 -1
  32. package/dist/esm/hooks/index.d.ts +14 -0
  33. package/dist/esm/hooks/index.js +14 -0
  34. package/dist/esm/hooks/useAddressForm.d.ts +13 -0
  35. package/dist/esm/hooks/useAddressForm.js +50 -0
  36. package/dist/esm/hooks/useAllergenForm.d.ts +9 -0
  37. package/dist/esm/hooks/useAllergenForm.js +42 -0
  38. package/dist/esm/hooks/useCreditCard.d.ts +14 -0
  39. package/dist/esm/hooks/useCreditCard.js +51 -0
  40. package/dist/esm/hooks/useCurbside.d.ts +10 -0
  41. package/dist/esm/hooks/useCurbside.js +35 -0
  42. package/dist/esm/hooks/useDineInForm.d.ts +7 -0
  43. package/dist/esm/hooks/useDineInForm.js +23 -0
  44. package/dist/esm/hooks/useDonationForm.d.ts +25 -0
  45. package/dist/esm/hooks/useDonationForm.js +153 -0
  46. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +15 -0
  47. package/dist/esm/hooks/useGiftCardAssignForm.js +36 -0
  48. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
  49. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +29 -0
  50. package/dist/esm/hooks/useGiftCardForm.d.ts +13 -0
  51. package/dist/esm/hooks/useGiftCardForm.js +46 -0
  52. package/dist/esm/hooks/useGiftCardsForm.d.ts +23 -0
  53. package/dist/esm/hooks/useGiftCardsForm.js +144 -0
  54. package/dist/esm/hooks/useLatLng.d.ts +8 -0
  55. package/dist/esm/hooks/useLatLng.js +11 -0
  56. package/dist/esm/hooks/useLoyaltyPoints.d.ts +2 -0
  57. package/dist/esm/hooks/useLoyaltyPoints.js +16 -0
  58. package/dist/esm/hooks/useOrderRating.d.ts +11 -0
  59. package/dist/esm/hooks/useOrderRating.js +30 -0
  60. package/dist/esm/hooks/useProfileForm.d.ts +29 -0
  61. package/dist/esm/hooks/useProfileForm.js +73 -0
  62. package/dist/esm/utils/helpers.d.ts +1 -1
  63. package/package.json +4 -2
@@ -0,0 +1,73 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { makeBirthDate, makePhone, slashesToDashes } from '../utils';
3
+ const useProfileForm = (profile, loading, error, update) => {
4
+ const [data, setData] = useState({});
5
+ const [submitting, setSubmitting] = useState(false);
6
+ const errMsg = error ? 'There are one or more errors below.' : null;
7
+ const errors = error || {};
8
+ const fields = [
9
+ {
10
+ label: 'First Name',
11
+ name: 'first_name',
12
+ type: 'default',
13
+ required: true,
14
+ },
15
+ { label: 'Last Name', name: 'last_name', type: 'default', required: true },
16
+ {
17
+ label: 'Email',
18
+ name: 'email',
19
+ type: 'email-address',
20
+ required: true,
21
+ autoComplete: 'email',
22
+ },
23
+ { label: 'Phone', name: 'phone', type: 'number-pad', required: true },
24
+ { label: 'Company', name: 'company', type: 'default' },
25
+ {
26
+ label: 'Birth Date (mm/dd/yyyy)',
27
+ name: 'birth_date',
28
+ type: 'number-pad',
29
+ },
30
+ ];
31
+ useEffect(() => {
32
+ if (loading === 'idle') {
33
+ setSubmitting(false);
34
+ }
35
+ }, [loading]);
36
+ useEffect(() => {
37
+ if (errors.birth_date) {
38
+ errors.birth_date = 'Invalid date. Please enter in mm/dd/yyyy format.';
39
+ }
40
+ }, [errors]);
41
+ useEffect(() => {
42
+ setData(profile);
43
+ }, [profile]);
44
+ const handleChange = (id, type, value, checked) => {
45
+ const inputValue = type === 'checkbox'
46
+ ? checked
47
+ : id === 'phone'
48
+ ? makePhone(value)
49
+ : id === 'birth_date'
50
+ ? makeBirthDate(value)
51
+ : value;
52
+ setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
53
+ };
54
+ const handleSubmit = () => {
55
+ setSubmitting(true);
56
+ const updatedData = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
57
+ updatedData.birth_date = data.birth_date
58
+ ? slashesToDashes(data.birth_date)
59
+ : null;
60
+ updatedData.gender = data.gender || null;
61
+ update(updatedData);
62
+ };
63
+ return {
64
+ data,
65
+ errors,
66
+ submitting,
67
+ fields,
68
+ errMsg,
69
+ handleChange,
70
+ handleSubmit,
71
+ };
72
+ };
73
+ export default useProfileForm;
@@ -3,7 +3,7 @@ export declare const isString: (str: any) => boolean;
3
3
  export declare const isObject: (obj: any) => boolean;
4
4
  export declare const isEmpty: (obj?: Record<string | number, unknown> | null) => boolean;
5
5
  export declare const isNum: (s: string) => boolean;
6
- export declare const contains: (arr: Array<any>, values: Array<any>) => boolean;
6
+ export declare const contains: (arr: Array<any> | string, values: Array<any>) => boolean;
7
7
  export declare const slugify: (text: string) => string;
8
8
  export declare const stripTags: (s: string) => string;
9
9
  export declare const serialize: (obj: Record<string | number, string | number | boolean>) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
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",
@@ -34,6 +34,7 @@
34
34
  "license": "MIT",
35
35
  "private": false,
36
36
  "devDependencies": {
37
+ "@open-tender/cloud": "^0.0.79",
37
38
  "@babel/core": "^7.19.1",
38
39
  "@emotion/react": "^11.10.4",
39
40
  "@reduxjs/toolkit": "^1.8.5",
@@ -54,7 +55,8 @@
54
55
  },
55
56
  "peerDependencies": {
56
57
  "@reduxjs/toolkit": "^1.8.5",
57
- "react": "^18.2.0"
58
+ "react": "^18.2.0",
59
+ "@open-tender/cloud": "^0.0.79"
58
60
  },
59
61
  "dependencies": {
60
62
  "@open-tender/types": "^0.0.91",