@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.
- 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/cjs/utils/helpers.d.ts +1 -1
- 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/dist/esm/utils/helpers.d.ts +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
import { CardType, CreditCard, CreditCardData, CreditCards, Profile, PurchaseGiftCardData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
declare const useGiftCardsForm: (purchase: (data: any) => void, reset: () => void, loading: RequestStatus, error: any, success: boolean, setAlert: Dispatch<any>, customer: Partial<Profile> | undefined, creditCards: CreditCards | undefined, _recaptchaKey: string | null | undefined, initState: PurchaseGiftCardData, cardData: CreditCardData, cardType: CardType) => {
|
|
4
|
+
creditCardOptions: any[];
|
|
5
|
+
handleName: (value: string) => void;
|
|
6
|
+
handleEmail: (value: string) => void;
|
|
7
|
+
handleChange: (id: string, value: unknown) => void;
|
|
8
|
+
handleQuantity: (index: number, quantity: number) => void;
|
|
9
|
+
handleAddAnother: () => void;
|
|
10
|
+
handleCreditCard: (value: string) => void;
|
|
11
|
+
handleSubmit: () => void;
|
|
12
|
+
handleReset: () => void;
|
|
13
|
+
name: string | undefined;
|
|
14
|
+
email: string | undefined;
|
|
15
|
+
cards: PurchaseGiftCardData[];
|
|
16
|
+
isNewCard: boolean;
|
|
17
|
+
newCardErrors: {};
|
|
18
|
+
creditCard: Partial<CreditCard>;
|
|
19
|
+
setCreditCard: Dispatch<import("react").SetStateAction<Partial<CreditCard>>>;
|
|
20
|
+
errors: any;
|
|
21
|
+
submitting: boolean;
|
|
22
|
+
};
|
|
23
|
+
export default useGiftCardsForm;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [],
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
_recaptchaKey = null, initState, cardData, cardType) => {
|
|
8
|
+
const [name, setName] = (0, react_1.useState)(undefined);
|
|
9
|
+
const [email, setEmail] = (0, react_1.useState)(undefined);
|
|
10
|
+
const [cards, setCards] = (0, react_1.useState)([initState]);
|
|
11
|
+
const [isNewCard, setIsNewCard] = (0, react_1.useState)(true);
|
|
12
|
+
const [creditCard, setCreditCard] = (0, react_1.useState)({});
|
|
13
|
+
const [creditCardOptions, setCreditCardOptions] = (0, react_1.useState)([]);
|
|
14
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
15
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
16
|
+
const url = null;
|
|
17
|
+
const newCardErrors = (0, react_1.useMemo)(() => errors
|
|
18
|
+
? Object.entries(errors)
|
|
19
|
+
.filter(([key]) => key !== 'form')
|
|
20
|
+
.reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {})
|
|
21
|
+
: {}, [errors]);
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
if (loading === 'idle') {
|
|
24
|
+
setSubmitting(false);
|
|
25
|
+
setAlert({ type: 'close' });
|
|
26
|
+
if (error) {
|
|
27
|
+
setErrors(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, [loading, error, setAlert, success]);
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
if (creditCards.length && loading !== 'pending') {
|
|
33
|
+
const options = creditCards.map(i => ({
|
|
34
|
+
label: `${i.card_type_name} ending in ${i.last4}`,
|
|
35
|
+
value: i.customer_card_id,
|
|
36
|
+
}));
|
|
37
|
+
setCreditCardOptions(options);
|
|
38
|
+
const defaultCard = creditCards.length
|
|
39
|
+
? { customer_card_id: creditCards[0].customer_card_id }
|
|
40
|
+
: {};
|
|
41
|
+
setCreditCard(defaultCard);
|
|
42
|
+
setIsNewCard(false);
|
|
43
|
+
}
|
|
44
|
+
}, [creditCards, loading]);
|
|
45
|
+
(0, react_1.useEffect)(() => {
|
|
46
|
+
if (customer) {
|
|
47
|
+
setEmail(customer.email);
|
|
48
|
+
setName(`${customer.first_name} ${customer.last_name}`);
|
|
49
|
+
}
|
|
50
|
+
}, [customer]);
|
|
51
|
+
const makeGiftCards = (giftCards) => {
|
|
52
|
+
return giftCards.reduce((arr, card) => {
|
|
53
|
+
const { amount, quantity, email: mail } = card;
|
|
54
|
+
const giftCard = !mail || !mail.length ? { amount, quantity } : card;
|
|
55
|
+
return [...arr, giftCard];
|
|
56
|
+
}, []);
|
|
57
|
+
};
|
|
58
|
+
const handleName = (value) => {
|
|
59
|
+
setName(value);
|
|
60
|
+
};
|
|
61
|
+
const handleEmail = (value) => {
|
|
62
|
+
setEmail(value);
|
|
63
|
+
};
|
|
64
|
+
const handleChange = (id, value) => {
|
|
65
|
+
const [field, index] = id.split('-');
|
|
66
|
+
const newCards = cards.map((card, idx) => {
|
|
67
|
+
return idx === parseInt(index) ? Object.assign(Object.assign({}, card), { [field]: value }) : card;
|
|
68
|
+
});
|
|
69
|
+
setCards(newCards);
|
|
70
|
+
};
|
|
71
|
+
const handleQuantity = (index, quantity) => {
|
|
72
|
+
const newCards = quantity > 0
|
|
73
|
+
? cards.map((card, idx) => {
|
|
74
|
+
return idx === index ? Object.assign(Object.assign({}, card), { quantity: quantity }) : card;
|
|
75
|
+
})
|
|
76
|
+
: cards.filter((_i, idx) => idx !== index);
|
|
77
|
+
setCards(newCards);
|
|
78
|
+
};
|
|
79
|
+
const handleAddAnother = () => {
|
|
80
|
+
setCards([...cards, initState]);
|
|
81
|
+
};
|
|
82
|
+
const handleCreditCard = (value) => {
|
|
83
|
+
const customerCardId = parseInt(value);
|
|
84
|
+
setCreditCard({ customer_card_id: customerCardId });
|
|
85
|
+
};
|
|
86
|
+
const purchaseWithCaptcha = (credit_card) => {
|
|
87
|
+
const alert = {
|
|
88
|
+
type: 'working',
|
|
89
|
+
args: { text: 'Submitting your purchase...' },
|
|
90
|
+
};
|
|
91
|
+
setSubmitting(true);
|
|
92
|
+
setAlert(alert);
|
|
93
|
+
const gift_cards = makeGiftCards(cards);
|
|
94
|
+
purchase({ credit_card, name, email, url, gift_cards });
|
|
95
|
+
};
|
|
96
|
+
const handleSubmit = () => {
|
|
97
|
+
if (!name || !email) {
|
|
98
|
+
setErrors({ form: 'Both name and email are required' });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (isNewCard) {
|
|
102
|
+
const { card, errors: errs } = (0, utils_1.validateCreditCard)(cardData, cardType);
|
|
103
|
+
if (errs) {
|
|
104
|
+
setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
|
|
105
|
+
setSubmitting(false);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
purchaseWithCaptcha(card);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
purchaseWithCaptcha(creditCard);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const handleReset = () => {
|
|
117
|
+
if (!customer) {
|
|
118
|
+
setName(undefined);
|
|
119
|
+
setEmail(undefined);
|
|
120
|
+
}
|
|
121
|
+
setCards([initState]);
|
|
122
|
+
setErrors({});
|
|
123
|
+
reset();
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
creditCardOptions,
|
|
127
|
+
handleName,
|
|
128
|
+
handleEmail,
|
|
129
|
+
handleChange,
|
|
130
|
+
handleQuantity,
|
|
131
|
+
handleAddAnother,
|
|
132
|
+
handleCreditCard,
|
|
133
|
+
handleSubmit,
|
|
134
|
+
handleReset,
|
|
135
|
+
name,
|
|
136
|
+
email,
|
|
137
|
+
cards,
|
|
138
|
+
isNewCard,
|
|
139
|
+
newCardErrors,
|
|
140
|
+
creditCard,
|
|
141
|
+
setCreditCard,
|
|
142
|
+
errors,
|
|
143
|
+
submitting,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
exports.default = useGiftCardsForm;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_redux_1 = require("react-redux");
|
|
4
|
+
const cloud_1 = require("@open-tender/cloud");
|
|
5
|
+
const useLatLng = () => {
|
|
6
|
+
// geoLatLng will be null if we don't have the user's geolocation
|
|
7
|
+
const geoLatLng = (0, react_redux_1.useSelector)(cloud_1.selectGeoLatLng);
|
|
8
|
+
// address will be null if we don't have the user's address
|
|
9
|
+
const { address } = (0, react_redux_1.useSelector)(cloud_1.selectOrder);
|
|
10
|
+
// make sure we always return an object with lat and lng attributes
|
|
11
|
+
return address || geoLatLng || { lat: null, lng: null };
|
|
12
|
+
};
|
|
13
|
+
exports.default = useLatLng;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const react_redux_1 = require("react-redux");
|
|
5
|
+
const cloud_1 = require("@open-tender/cloud");
|
|
6
|
+
const useLoyaltyPoints = () => {
|
|
7
|
+
const dispatch = (0, cloud_1.useAppDispatch)();
|
|
8
|
+
const { profile } = (0, react_redux_1.useSelector)(cloud_1.selectCustomer);
|
|
9
|
+
const { customer_id } = profile || {};
|
|
10
|
+
const pointsProgram = (0, react_redux_1.useSelector)(cloud_1.selectPointsProgram);
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
if (customer_id) {
|
|
13
|
+
dispatch((0, cloud_1.fetchCustomerLoyalty)());
|
|
14
|
+
}
|
|
15
|
+
}, [customer_id, dispatch]);
|
|
16
|
+
return pointsProgram || null;
|
|
17
|
+
};
|
|
18
|
+
exports.default = useLoyaltyPoints;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OrderRating } from '@open-tender/types';
|
|
2
|
+
declare const useOrderRatingForm: (orderId: number, orderRating: OrderRating, updateRating: (id: number, data: Partial<OrderRating>) => void) => {
|
|
3
|
+
rating: number;
|
|
4
|
+
handleRating: (star: number) => void;
|
|
5
|
+
comments: string;
|
|
6
|
+
handleComments: (inputComments: string) => void;
|
|
7
|
+
handleSubmit: () => void;
|
|
8
|
+
handleClose: () => void;
|
|
9
|
+
stars: number[];
|
|
10
|
+
};
|
|
11
|
+
export default useOrderRatingForm;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useOrderRatingForm = (orderId, orderRating, updateRating) => {
|
|
5
|
+
const [rating, setRating] = (0, react_1.useState)((orderRating && orderRating.rating) || 0);
|
|
6
|
+
const [comments, setComments] = (0, react_1.useState)((orderRating && orderRating.comments) || '');
|
|
7
|
+
const stars = [1, 2, 3, 4, 5];
|
|
8
|
+
const handleRating = (star) => {
|
|
9
|
+
setRating(star);
|
|
10
|
+
};
|
|
11
|
+
const handleComments = (inputComments) => {
|
|
12
|
+
setComments(inputComments);
|
|
13
|
+
};
|
|
14
|
+
const handleSubmit = () => {
|
|
15
|
+
const data = { rating, comments };
|
|
16
|
+
updateRating(orderId, data);
|
|
17
|
+
};
|
|
18
|
+
const handleClose = () => {
|
|
19
|
+
setComments((orderRating && orderRating.comments) || '');
|
|
20
|
+
setRating((orderRating && orderRating.rating) || 0);
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
rating,
|
|
24
|
+
handleRating,
|
|
25
|
+
comments,
|
|
26
|
+
handleComments,
|
|
27
|
+
handleSubmit,
|
|
28
|
+
handleClose,
|
|
29
|
+
stars,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.default = useOrderRatingForm;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Profile, RequestStatus } from '@open-tender/types';
|
|
2
|
+
declare const useProfileForm: (profile: Partial<Profile>, loading: RequestStatus, error: any, update: (data: Partial<Profile>) => void) => {
|
|
3
|
+
data: any;
|
|
4
|
+
errors: any;
|
|
5
|
+
submitting: boolean;
|
|
6
|
+
fields: ({
|
|
7
|
+
label: string;
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
required: boolean;
|
|
11
|
+
autoComplete?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
label: string;
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
required: boolean;
|
|
17
|
+
autoComplete: string;
|
|
18
|
+
} | {
|
|
19
|
+
label: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
required?: undefined;
|
|
23
|
+
autoComplete?: undefined;
|
|
24
|
+
})[];
|
|
25
|
+
errMsg: string | null;
|
|
26
|
+
handleChange: (id: string, type: string | null, value: string, checked: boolean | null) => void;
|
|
27
|
+
handleSubmit: () => void;
|
|
28
|
+
};
|
|
29
|
+
export default useProfileForm;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const useProfileForm = (profile, loading, error, update) => {
|
|
6
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
7
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
8
|
+
const errMsg = error ? 'There are one or more errors below.' : null;
|
|
9
|
+
const errors = error || {};
|
|
10
|
+
const fields = [
|
|
11
|
+
{
|
|
12
|
+
label: 'First Name',
|
|
13
|
+
name: 'first_name',
|
|
14
|
+
type: 'default',
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
{ label: 'Last Name', name: 'last_name', type: 'default', required: true },
|
|
18
|
+
{
|
|
19
|
+
label: 'Email',
|
|
20
|
+
name: 'email',
|
|
21
|
+
type: 'email-address',
|
|
22
|
+
required: true,
|
|
23
|
+
autoComplete: 'email',
|
|
24
|
+
},
|
|
25
|
+
{ label: 'Phone', name: 'phone', type: 'number-pad', required: true },
|
|
26
|
+
{ label: 'Company', name: 'company', type: 'default' },
|
|
27
|
+
{
|
|
28
|
+
label: 'Birth Date (mm/dd/yyyy)',
|
|
29
|
+
name: 'birth_date',
|
|
30
|
+
type: 'number-pad',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
(0, react_1.useEffect)(() => {
|
|
34
|
+
if (loading === 'idle') {
|
|
35
|
+
setSubmitting(false);
|
|
36
|
+
}
|
|
37
|
+
}, [loading]);
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
if (errors.birth_date) {
|
|
40
|
+
errors.birth_date = 'Invalid date. Please enter in mm/dd/yyyy format.';
|
|
41
|
+
}
|
|
42
|
+
}, [errors]);
|
|
43
|
+
(0, react_1.useEffect)(() => {
|
|
44
|
+
setData(profile);
|
|
45
|
+
}, [profile]);
|
|
46
|
+
const handleChange = (id, type, value, checked) => {
|
|
47
|
+
const inputValue = type === 'checkbox'
|
|
48
|
+
? checked
|
|
49
|
+
: id === 'phone'
|
|
50
|
+
? (0, utils_1.makePhone)(value)
|
|
51
|
+
: id === 'birth_date'
|
|
52
|
+
? (0, utils_1.makeBirthDate)(value)
|
|
53
|
+
: value;
|
|
54
|
+
setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
|
|
55
|
+
};
|
|
56
|
+
const handleSubmit = () => {
|
|
57
|
+
setSubmitting(true);
|
|
58
|
+
const updatedData = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
|
|
59
|
+
updatedData.birth_date = data.birth_date
|
|
60
|
+
? (0, utils_1.slashesToDashes)(data.birth_date)
|
|
61
|
+
: null;
|
|
62
|
+
updatedData.gender = data.gender || null;
|
|
63
|
+
update(updatedData);
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
data,
|
|
67
|
+
errors,
|
|
68
|
+
submitting,
|
|
69
|
+
fields,
|
|
70
|
+
errMsg,
|
|
71
|
+
handleChange,
|
|
72
|
+
handleSubmit,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.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
|
|
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;
|
|
@@ -1 +1,15 @@
|
|
|
1
1
|
export * from './menu';
|
|
2
|
+
export * from './useAddressForm';
|
|
3
|
+
export * from './useAllergenForm';
|
|
4
|
+
export * from './useCreditCard';
|
|
5
|
+
export * from './useCurbside';
|
|
6
|
+
export * from './useDineInForm';
|
|
7
|
+
export * from './useDonationForm';
|
|
8
|
+
export * from './useGiftCardAssignForm';
|
|
9
|
+
export * from './useGiftCardAssignOtherForm';
|
|
10
|
+
export * from './useGiftCardForm';
|
|
11
|
+
export * from './useGiftCardsForm';
|
|
12
|
+
export * from './useLatLng';
|
|
13
|
+
export * from './useLoyaltyPoints';
|
|
14
|
+
export * from './useOrderRating';
|
|
15
|
+
export * from './useProfileForm';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
1
|
export * from './menu';
|
|
2
|
+
export * from './useAddressForm';
|
|
3
|
+
export * from './useAllergenForm';
|
|
4
|
+
export * from './useCreditCard';
|
|
5
|
+
export * from './useCurbside';
|
|
6
|
+
export * from './useDineInForm';
|
|
7
|
+
export * from './useDonationForm';
|
|
8
|
+
export * from './useGiftCardAssignForm';
|
|
9
|
+
export * from './useGiftCardAssignOtherForm';
|
|
10
|
+
export * from './useGiftCardForm';
|
|
11
|
+
export * from './useGiftCardsForm';
|
|
12
|
+
export * from './useLatLng';
|
|
13
|
+
export * from './useLoyaltyPoints';
|
|
14
|
+
export * from './useOrderRating';
|
|
15
|
+
export * from './useProfileForm';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address, RequestStatus } from '@open-tender/types';
|
|
2
|
+
export declare const useAddressForm: (address: Address, loading: RequestStatus, error: any, update: (addressId: number, updatedData: Address, callback: () => void) => void, callback: () => void) => {
|
|
3
|
+
fields: {
|
|
4
|
+
label: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}[];
|
|
8
|
+
data: Address;
|
|
9
|
+
errors: any;
|
|
10
|
+
submitting: boolean;
|
|
11
|
+
handleChange: (id: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
12
|
+
handleSubmit: () => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { makePhone } from '../utils';
|
|
3
|
+
export const useAddressForm = (address, loading, error, update, callback) => {
|
|
4
|
+
const [data, setData] = useState(address);
|
|
5
|
+
const [errors, setErrors] = useState({});
|
|
6
|
+
const [submitting, setSubmitting] = useState(false);
|
|
7
|
+
const fields = [
|
|
8
|
+
{ label: 'Company', name: 'company', type: 'default' },
|
|
9
|
+
{ label: 'Contact Person', name: 'contact', type: 'default' },
|
|
10
|
+
{ label: 'Contact Phone', name: 'phone', type: 'phone-pad' },
|
|
11
|
+
{ label: 'Description', name: 'description', type: 'default' },
|
|
12
|
+
{ label: 'Notes', name: 'notes', type: 'default' },
|
|
13
|
+
{ label: 'Is Default', name: 'is_default', type: 'checkbox' },
|
|
14
|
+
];
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (loading === 'idle') {
|
|
17
|
+
setSubmitting(false);
|
|
18
|
+
if (error) {
|
|
19
|
+
setErrors(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, [loading, error]);
|
|
23
|
+
const handleChange = (id, type, value, checked) => {
|
|
24
|
+
const inputValue = type === 'checkbox'
|
|
25
|
+
? checked
|
|
26
|
+
: id === 'phone'
|
|
27
|
+
? makePhone(value !== null && value !== void 0 ? value : '')
|
|
28
|
+
: value;
|
|
29
|
+
setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
|
|
30
|
+
};
|
|
31
|
+
const handleSubmit = () => {
|
|
32
|
+
setSubmitting(true);
|
|
33
|
+
const updatedData = Object.assign({}, data);
|
|
34
|
+
delete updatedData.customer_address_id;
|
|
35
|
+
delete updatedData.created_at;
|
|
36
|
+
delete updatedData.last_used_at;
|
|
37
|
+
const addressId = data.customer_address_id;
|
|
38
|
+
if (addressId) {
|
|
39
|
+
update(addressId, updatedData, callback);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
fields,
|
|
44
|
+
data,
|
|
45
|
+
errors,
|
|
46
|
+
submitting,
|
|
47
|
+
handleChange,
|
|
48
|
+
handleSubmit,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Allergen, Allergens } from '@open-tender/types';
|
|
2
|
+
declare const useAllergenForm: (allergens: Allergens, selectedAllergens: Allergens, isLoading: boolean | undefined, error: any, setAllergens: (allergens: Allergens) => void, updateAllergens: (allergen: Partial<Allergen>[]) => void, callback?: () => void) => {
|
|
3
|
+
submitting: boolean;
|
|
4
|
+
allergenIds: number[];
|
|
5
|
+
formError: any;
|
|
6
|
+
handleChange: (id: string, checked?: boolean) => void;
|
|
7
|
+
handleSubmit: () => void;
|
|
8
|
+
};
|
|
9
|
+
export default useAllergenForm;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error = null, setAllergens, updateAllergens, callback) => {
|
|
3
|
+
const [data, setData] = useState([]);
|
|
4
|
+
const [submitting, setSubmitting] = useState(false);
|
|
5
|
+
const allergenIds = data.map(i => i.allergen_id);
|
|
6
|
+
const formError = error ? error.detail || error.message : null;
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
// uses isLoading boolean because loading state is based on
|
|
9
|
+
// both brand allergens and customer allergens loading
|
|
10
|
+
if (!isLoading) {
|
|
11
|
+
setSubmitting(false);
|
|
12
|
+
}
|
|
13
|
+
}, [isLoading]);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setData(selectedAllergens || []);
|
|
16
|
+
}, [selectedAllergens, allergens]);
|
|
17
|
+
const handleChange = (id, checked) => {
|
|
18
|
+
const newData = checked
|
|
19
|
+
? [...data, { allergen_id: parseInt(id) }]
|
|
20
|
+
: data.filter(i => i.allergen_id !== parseInt(id));
|
|
21
|
+
setData(newData);
|
|
22
|
+
};
|
|
23
|
+
const handleSubmit = () => {
|
|
24
|
+
setSubmitting(updateAllergens !== null);
|
|
25
|
+
const newData = data.map(i => ({ allergen_id: i.allergen_id }));
|
|
26
|
+
setAllergens(data);
|
|
27
|
+
if (updateAllergens) {
|
|
28
|
+
updateAllergens(newData);
|
|
29
|
+
}
|
|
30
|
+
else if (callback) {
|
|
31
|
+
callback();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
submitting,
|
|
36
|
+
allergenIds,
|
|
37
|
+
formError,
|
|
38
|
+
handleChange,
|
|
39
|
+
handleSubmit,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export default useAllergenForm;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CreditCardData } from '@open-tender/types';
|
|
3
|
+
declare const useCreditCard: (initState?: CreditCardData, cardErrors?: any, disabled?: boolean) => {
|
|
4
|
+
data: CreditCardData;
|
|
5
|
+
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
6
|
+
errors: any;
|
|
7
|
+
disabled: boolean | undefined;
|
|
8
|
+
setErrors: import("react").Dispatch<any>;
|
|
9
|
+
handleChange: (name: keyof CreditCardData, value: string) => void;
|
|
10
|
+
handleBlur: (name: keyof CreditCardData) => void;
|
|
11
|
+
handleReset: () => void;
|
|
12
|
+
isComplete: boolean;
|
|
13
|
+
};
|
|
14
|
+
export default useCreditCard;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { formatCard, formatCardField, getCardType, isEmpty, validateCreditCard } from '../utils';
|
|
3
|
+
const defaultState = {
|
|
4
|
+
acct: '',
|
|
5
|
+
exp: '',
|
|
6
|
+
cvv: '',
|
|
7
|
+
zip: '',
|
|
8
|
+
is_default: false,
|
|
9
|
+
};
|
|
10
|
+
const useCreditCard = (initState, cardErrors, disabled) => {
|
|
11
|
+
const [initCard, initCardType] = formatCard(initState !== null && initState !== void 0 ? initState : defaultState);
|
|
12
|
+
const [data, setData] = useState(initCard || defaultState);
|
|
13
|
+
const [cardType, setCardType] = useState(initCardType || 'OTHER');
|
|
14
|
+
const [errors, setErrors] = useState(cardErrors !== null && cardErrors !== void 0 ? cardErrors : {});
|
|
15
|
+
const { acct, exp, cvv, zip } = data;
|
|
16
|
+
const isComplete = acct && exp && cvv && zip && !isEmpty(errors) ? true : false;
|
|
17
|
+
const handleChange = (name, value) => {
|
|
18
|
+
if (name === 'acct') {
|
|
19
|
+
const currentType = getCardType(value.replace(/\s/g, ''));
|
|
20
|
+
setCardType(currentType);
|
|
21
|
+
}
|
|
22
|
+
const val = name === 'is_default' ? value : formatCardField(name, value);
|
|
23
|
+
setData(Object.assign(Object.assign({}, data), { [name]: val }));
|
|
24
|
+
};
|
|
25
|
+
const handleBlur = (name) => {
|
|
26
|
+
const { errors: validationErrors } = validateCreditCard(data, cardType);
|
|
27
|
+
if (validationErrors) {
|
|
28
|
+
const error = validationErrors[name];
|
|
29
|
+
setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
setErrors(Object.assign(Object.assign({}, errors), { [name]: null }));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const handleReset = () => {
|
|
36
|
+
setData(defaultState);
|
|
37
|
+
setErrors({});
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
data,
|
|
41
|
+
cardType,
|
|
42
|
+
errors,
|
|
43
|
+
disabled,
|
|
44
|
+
setErrors,
|
|
45
|
+
handleChange,
|
|
46
|
+
handleBlur,
|
|
47
|
+
handleReset,
|
|
48
|
+
isComplete,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export default useCreditCard;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConfigFulfillment, OrderFulfillment, RequestStatus } from '@open-tender/types';
|
|
2
|
+
declare const useCurbside: (orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error: any, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
|
|
3
|
+
fields: import("@open-tender/types").ConfigFulfillmentField[] | undefined;
|
|
4
|
+
data: Partial<OrderFulfillment>;
|
|
5
|
+
errors: any;
|
|
6
|
+
submitting: boolean;
|
|
7
|
+
handleChange: (name: keyof OrderFulfillment, value: string) => void;
|
|
8
|
+
handleSubmit: () => void;
|
|
9
|
+
};
|
|
10
|
+
export default useCurbside;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { isEmpty } from '../utils';
|
|
3
|
+
const useCurbside = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
4
|
+
const [data, setData] = useState({});
|
|
5
|
+
const [submitting, setSubmitting] = useState(false);
|
|
6
|
+
const errors = error || {};
|
|
7
|
+
const empty = Object.values(fulfillment).every(i => !i);
|
|
8
|
+
const fields = !empty && !showAllFields
|
|
9
|
+
? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
10
|
+
: settings === null || settings === void 0 ? void 0 : settings.fields;
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (loading === 'idle')
|
|
13
|
+
setSubmitting(false);
|
|
14
|
+
}, [loading]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!isEmpty(fulfillment))
|
|
17
|
+
setData(fulfillment);
|
|
18
|
+
}, [fulfillment]);
|
|
19
|
+
const handleChange = (name, value) => {
|
|
20
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
21
|
+
};
|
|
22
|
+
const handleSubmit = () => {
|
|
23
|
+
setSubmitting(true);
|
|
24
|
+
update(orderId, Object.assign(Object.assign({}, data), { has_arrived: true }));
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
fields,
|
|
28
|
+
data,
|
|
29
|
+
errors,
|
|
30
|
+
submitting,
|
|
31
|
+
handleChange,
|
|
32
|
+
handleSubmit,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export default useCurbside;
|