@open-tender/utils 0.0.33 → 0.0.34
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.
- package/dist/cjs/hooks/index.d.ts +14 -0
- package/dist/cjs/hooks/index.js +14 -0
- package/dist/cjs/hooks/useAddressForm.d.ts +13 -0
- package/dist/cjs/hooks/useAddressForm.js +54 -0
- package/dist/cjs/hooks/useAllergenForm.d.ts +9 -0
- package/dist/cjs/hooks/useAllergenForm.js +44 -0
- package/dist/cjs/hooks/useCreditCard.d.ts +14 -0
- package/dist/cjs/hooks/useCreditCard.js +53 -0
- package/dist/cjs/hooks/useCurbside.d.ts +10 -0
- package/dist/cjs/hooks/useCurbside.js +37 -0
- package/dist/cjs/hooks/useDineInForm.d.ts +7 -0
- package/dist/cjs/hooks/useDineInForm.js +25 -0
- package/dist/cjs/hooks/useDonationForm.d.ts +25 -0
- package/dist/cjs/hooks/useDonationForm.js +155 -0
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +15 -0
- package/dist/cjs/hooks/useGiftCardAssignForm.js +38 -0
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +31 -0
- package/dist/cjs/hooks/useGiftCardForm.d.ts +13 -0
- package/dist/cjs/hooks/useGiftCardForm.js +48 -0
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +23 -0
- package/dist/cjs/hooks/useGiftCardsForm.js +146 -0
- package/dist/cjs/hooks/useLatLng.d.ts +8 -0
- package/dist/cjs/hooks/useLatLng.js +13 -0
- package/dist/cjs/hooks/useLoyaltyPoints.d.ts +2 -0
- package/dist/cjs/hooks/useLoyaltyPoints.js +18 -0
- package/dist/cjs/hooks/useOrderRating.d.ts +11 -0
- package/dist/cjs/hooks/useOrderRating.js +32 -0
- package/dist/cjs/hooks/useProfileForm.d.ts +29 -0
- package/dist/cjs/hooks/useProfileForm.js +75 -0
- package/dist/esm/hooks/index.d.ts +14 -0
- package/dist/esm/hooks/index.js +14 -0
- package/dist/esm/hooks/useAddressForm.d.ts +13 -0
- package/dist/esm/hooks/useAddressForm.js +50 -0
- package/dist/esm/hooks/useAllergenForm.d.ts +9 -0
- package/dist/esm/hooks/useAllergenForm.js +42 -0
- package/dist/esm/hooks/useCreditCard.d.ts +14 -0
- package/dist/esm/hooks/useCreditCard.js +51 -0
- package/dist/esm/hooks/useCurbside.d.ts +10 -0
- package/dist/esm/hooks/useCurbside.js +35 -0
- package/dist/esm/hooks/useDineInForm.d.ts +7 -0
- package/dist/esm/hooks/useDineInForm.js +23 -0
- package/dist/esm/hooks/useDonationForm.d.ts +25 -0
- package/dist/esm/hooks/useDonationForm.js +153 -0
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +15 -0
- package/dist/esm/hooks/useGiftCardAssignForm.js +36 -0
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +9 -0
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +29 -0
- package/dist/esm/hooks/useGiftCardForm.d.ts +13 -0
- package/dist/esm/hooks/useGiftCardForm.js +46 -0
- package/dist/esm/hooks/useGiftCardsForm.d.ts +23 -0
- package/dist/esm/hooks/useGiftCardsForm.js +144 -0
- package/dist/esm/hooks/useLatLng.d.ts +8 -0
- package/dist/esm/hooks/useLatLng.js +11 -0
- package/dist/esm/hooks/useLoyaltyPoints.d.ts +2 -0
- package/dist/esm/hooks/useLoyaltyPoints.js +16 -0
- package/dist/esm/hooks/useOrderRating.d.ts +11 -0
- package/dist/esm/hooks/useOrderRating.js +30 -0
- package/dist/esm/hooks/useProfileForm.d.ts +29 -0
- package/dist/esm/hooks/useProfileForm.js +73 -0
- 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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
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",
|