@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.
- package/dist/cjs/hooks/types.d.ts +4 -0
- package/dist/cjs/hooks/types.js +2 -0
- package/dist/cjs/hooks/useAddressForm.d.ts +2 -5
- package/dist/cjs/hooks/useAddressForm.js +3 -3
- package/dist/cjs/hooks/useAllergenForm.d.ts +5 -2
- package/dist/cjs/hooks/useAllergenForm.js +8 -4
- package/dist/cjs/hooks/useCartGuestForm.d.ts +21 -0
- package/dist/cjs/hooks/useCartGuestForm.js +46 -0
- package/dist/cjs/hooks/useCheckoutLoginForm.d.ts +12 -0
- package/dist/cjs/hooks/useCheckoutLoginForm.js +41 -0
- package/dist/cjs/hooks/useCommunicationPreferences.d.ts +0 -0
- package/dist/cjs/hooks/useCommunicationPreferences.js +1 -0
- package/dist/cjs/hooks/useCreditCard.d.ts +8 -11
- package/dist/cjs/hooks/useCreditCard.js +61 -41
- package/dist/cjs/hooks/useDineInForm.d.ts +8 -3
- package/dist/cjs/hooks/useDineInForm.js +8 -2
- package/dist/cjs/hooks/useDonationForm.d.ts +4 -1
- package/dist/cjs/hooks/useDonationForm.js +17 -3
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +5 -7
- package/dist/cjs/hooks/useGiftCardAssignForm.js +11 -3
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +8 -0
- package/dist/cjs/hooks/useGiftCardForm.d.ts +9 -5
- package/dist/cjs/hooks/useGiftCardForm.js +13 -4
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +30 -11
- package/dist/cjs/hooks/useGiftCardsForm.js +72 -31
- package/dist/cjs/hooks/useGuestForm.d.ts +13 -0
- package/dist/cjs/hooks/useGuestForm.js +41 -0
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +13 -0
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +40 -0
- package/dist/cjs/hooks/useOrderRatingForm.d.ts +13 -0
- package/dist/cjs/hooks/useOrderRatingForm.js +33 -0
- package/dist/cjs/hooks/useProfileForm.d.ts +18 -23
- package/dist/cjs/hooks/useProfileForm.js +27 -28
- package/dist/cjs/hooks/useResetPasswordForm.d.ts +20 -0
- package/dist/cjs/hooks/useResetPasswordForm.js +66 -0
- package/dist/cjs/hooks/useSendResetForm.d.ts +12 -0
- package/dist/cjs/hooks/useSendResetForm.js +36 -0
- package/dist/cjs/hooks/useSignUpForm.d.ts +21 -0
- package/dist/cjs/hooks/useSignUpForm.js +91 -0
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -0
- package/dist/cjs/hooks/useSignUpGuestForm.js +74 -0
- package/dist/cjs/hooks/useSigninForm.d.ts +12 -0
- package/dist/cjs/hooks/useSigninForm.js +41 -0
- package/dist/cjs/utils/cart.js +2 -2
- package/dist/esm/hooks/types.d.ts +4 -0
- package/dist/esm/hooks/types.js +1 -0
- package/dist/esm/hooks/useAddressForm.d.ts +2 -5
- package/dist/esm/hooks/useAddressForm.js +3 -3
- package/dist/esm/hooks/useAllergenForm.d.ts +5 -2
- package/dist/esm/hooks/useAllergenForm.js +9 -5
- package/dist/esm/hooks/useCartGuestForm.d.ts +21 -0
- package/dist/esm/hooks/useCartGuestForm.js +44 -0
- package/dist/esm/hooks/useCheckoutLoginForm.d.ts +12 -0
- package/dist/esm/hooks/useCheckoutLoginForm.js +39 -0
- package/dist/esm/hooks/useCommunicationPreferences.d.ts +0 -0
- package/dist/esm/hooks/useCommunicationPreferences.js +1 -0
- package/dist/esm/hooks/useCreditCard.d.ts +8 -11
- package/dist/esm/hooks/useCreditCard.js +62 -42
- package/dist/esm/hooks/useDineInForm.d.ts +8 -3
- package/dist/esm/hooks/useDineInForm.js +9 -3
- package/dist/esm/hooks/useDonationForm.d.ts +4 -1
- package/dist/esm/hooks/useDonationForm.js +17 -3
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +5 -7
- package/dist/esm/hooks/useGiftCardAssignForm.js +12 -4
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +9 -1
- package/dist/esm/hooks/useGiftCardForm.d.ts +9 -5
- package/dist/esm/hooks/useGiftCardForm.js +14 -5
- package/dist/esm/hooks/useGiftCardsForm.d.ts +30 -11
- package/dist/esm/hooks/useGiftCardsForm.js +73 -32
- package/dist/esm/hooks/useGuestForm.d.ts +13 -0
- package/dist/esm/hooks/useGuestForm.js +39 -0
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +13 -0
- package/dist/esm/hooks/useOrderFulfillmentForm.js +38 -0
- package/dist/esm/hooks/useOrderRatingForm.d.ts +13 -0
- package/dist/esm/hooks/useOrderRatingForm.js +31 -0
- package/dist/esm/hooks/useProfileForm.d.ts +18 -23
- package/dist/esm/hooks/useProfileForm.js +28 -29
- package/dist/esm/hooks/useResetPasswordForm.d.ts +20 -0
- package/dist/esm/hooks/useResetPasswordForm.js +64 -0
- package/dist/esm/hooks/useSendResetForm.d.ts +12 -0
- package/dist/esm/hooks/useSendResetForm.js +34 -0
- package/dist/esm/hooks/useSignUpForm.d.ts +21 -0
- package/dist/esm/hooks/useSignUpForm.js +89 -0
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -0
- package/dist/esm/hooks/useSignUpGuestForm.js +72 -0
- package/dist/esm/hooks/useSigninForm.d.ts +12 -0
- package/dist/esm/hooks/useSigninForm.js +39 -0
- package/dist/esm/utils/cart.js +2 -2
- package/package.json +2 -2
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { CreditCards, CustomerGiftCard, RequestStatus } from '@open-tender/types';
|
|
2
|
-
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useGiftCardForm: <InputRef extends Field, SubmitRef extends Field>(giftCard: CustomerGiftCard, creditCards: CreditCards, loading: RequestStatus, error: any, update: (id: number, data: Partial<CustomerGiftCard>, callback: () => void) => void, add: (data: Partial<CustomerGiftCard>, callback: () => void) => void, callback: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
3
7
|
options: {
|
|
4
|
-
|
|
8
|
+
name: string;
|
|
5
9
|
value: number | undefined;
|
|
6
10
|
}[];
|
|
7
|
-
errors:
|
|
8
|
-
data:
|
|
11
|
+
errors: {};
|
|
12
|
+
data: Partial<CustomerGiftCard>;
|
|
9
13
|
submitting: boolean;
|
|
10
|
-
handleChange: (
|
|
14
|
+
handleChange: (name: number, type: string, value: string | null, checked: boolean | null) => void;
|
|
11
15
|
handleSubmit: () => void;
|
|
12
16
|
};
|
|
13
17
|
export default useGiftCardForm;
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, callback) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
5
7
|
const customerCardId = creditCards[0].customer_card_id;
|
|
6
8
|
const [data, setData] = (0, react_1.useState)({ customer_card_id: customerCardId });
|
|
7
9
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
8
10
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
9
|
-
const options = creditCards.map(i => {
|
|
11
|
+
const options = creditCards.map((i) => {
|
|
10
12
|
return {
|
|
11
|
-
|
|
13
|
+
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
12
14
|
value: i.customer_card_id,
|
|
13
15
|
};
|
|
14
16
|
});
|
|
15
17
|
(0, react_1.useEffect)(() => {
|
|
18
|
+
var _a, _b;
|
|
16
19
|
if (loading === 'idle') {
|
|
17
20
|
setSubmitting(false);
|
|
18
21
|
if (error) {
|
|
@@ -20,13 +23,16 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
20
23
|
error.amount = 'Please enter a positive dollar amount';
|
|
21
24
|
}
|
|
22
25
|
setErrors(error);
|
|
26
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
}, [loading, error]);
|
|
26
|
-
const handleChange = (
|
|
27
|
-
|
|
30
|
+
const handleChange = (name, type, value, checked) => {
|
|
31
|
+
const inputValue = type === 'checkbox' ? checked : value;
|
|
32
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
28
33
|
};
|
|
29
34
|
const handleSubmit = () => {
|
|
35
|
+
var _a, _b;
|
|
30
36
|
setSubmitting(true);
|
|
31
37
|
if (!data.customer_card_id) {
|
|
32
38
|
data.customer_card_id = customerCardId;
|
|
@@ -35,8 +41,11 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
35
41
|
giftCard
|
|
36
42
|
? update(giftCard.gift_card_id, data, callback)
|
|
37
43
|
: add(data, callback);
|
|
44
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
38
45
|
};
|
|
39
46
|
return {
|
|
47
|
+
submitRef,
|
|
48
|
+
inputRef,
|
|
40
49
|
options,
|
|
41
50
|
errors,
|
|
42
51
|
data,
|
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import { CardType, CreditCard, CreditCardData, CreditCards,
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CardType, CreditCard, CreditCardData, CreditCards, Customer, PurchaseGiftCardData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
interface CreditCardOption {
|
|
5
|
+
name: string;
|
|
6
|
+
value?: number;
|
|
7
|
+
}
|
|
8
|
+
interface PurchaseData {
|
|
9
|
+
credit_card: Partial<CreditCardData>;
|
|
10
|
+
email: string;
|
|
11
|
+
gift_cards: Array<Partial<PurchaseGiftCardData>>;
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
}
|
|
16
|
+
declare const useGiftCardsForm: <InputRef extends Field, SubmitRef extends Field>(purchase: (data: PurchaseData) => void, reset: () => void, loading: RequestStatus, error: any, success: boolean, setAlert: (data: {
|
|
17
|
+
type: string;
|
|
18
|
+
args?: any;
|
|
19
|
+
}) => void, customer: Partial<Customer> | undefined, creditCards: CreditCards | undefined, recaptchaKey: string | null | undefined, initState: PurchaseGiftCardData, cardData: CreditCardData, cardType: CardType, windowRef?: Window) => {
|
|
20
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
21
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
22
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
23
|
+
creditCardOptions: CreditCardOption[];
|
|
5
24
|
handleName: (value: string) => void;
|
|
6
25
|
handleEmail: (value: string) => void;
|
|
7
|
-
handleChange: (
|
|
26
|
+
handleChange: (name: string, value: string) => void;
|
|
8
27
|
handleQuantity: (index: number, quantity: number) => void;
|
|
9
28
|
handleAddAnother: () => void;
|
|
10
|
-
handleCreditCard: (value:
|
|
29
|
+
handleCreditCard: (value: number) => void;
|
|
11
30
|
handleSubmit: () => void;
|
|
12
31
|
handleReset: () => void;
|
|
13
|
-
name: string |
|
|
14
|
-
email: string |
|
|
32
|
+
name: string | null;
|
|
33
|
+
email: string | null;
|
|
15
34
|
cards: PurchaseGiftCardData[];
|
|
16
35
|
isNewCard: boolean;
|
|
17
36
|
newCardErrors: {};
|
|
18
|
-
creditCard: Partial<
|
|
19
|
-
setCreditCard: Dispatch<import("react").SetStateAction<Partial<
|
|
20
|
-
errors:
|
|
37
|
+
creditCard: CreditCard & Partial<CreditCardData>;
|
|
38
|
+
setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCard & Partial<CreditCardData>>>;
|
|
39
|
+
errors: {};
|
|
21
40
|
submitting: boolean;
|
|
22
41
|
};
|
|
23
42
|
export default useGiftCardsForm;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
const utils_1 = require("
|
|
5
|
-
const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [],
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
4
|
+
const utils_1 = require("@open-tender/utils");
|
|
5
|
+
const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [], recaptchaKey = null, initState, cardData, cardType, windowRef) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
9
|
+
const recaptchaRef = (0, react_1.useRef)(null);
|
|
10
|
+
const [name, setName] = (0, react_1.useState)(null);
|
|
11
|
+
const [email, setEmail] = (0, react_1.useState)(null);
|
|
10
12
|
const [cards, setCards] = (0, react_1.useState)([initState]);
|
|
11
13
|
const [isNewCard, setIsNewCard] = (0, react_1.useState)(true);
|
|
12
14
|
const [creditCard, setCreditCard] = (0, react_1.useState)({});
|
|
13
15
|
const [creditCardOptions, setCreditCardOptions] = (0, react_1.useState)([]);
|
|
14
16
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
15
17
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
16
|
-
const url = null;
|
|
18
|
+
const url = (_b = (_a = windowRef === null || windowRef === void 0 ? void 0 : windowRef.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : "";
|
|
17
19
|
const newCardErrors = (0, react_1.useMemo)(() => errors
|
|
18
20
|
? Object.entries(errors)
|
|
19
21
|
.filter(([key]) => key !== 'form')
|
|
@@ -24,14 +26,20 @@ _recaptchaKey = null, initState, cardData, cardType) => {
|
|
|
24
26
|
setSubmitting(false);
|
|
25
27
|
setAlert({ type: 'close' });
|
|
26
28
|
if (error) {
|
|
29
|
+
if (recaptchaRef.current)
|
|
30
|
+
recaptchaRef.current.reset();
|
|
27
31
|
setErrors(error);
|
|
32
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
33
|
+
}
|
|
34
|
+
else if (success) {
|
|
35
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
|
-
}, [loading, error, setAlert, success]);
|
|
38
|
+
}, [windowRef, loading, error, setAlert, success]);
|
|
31
39
|
(0, react_1.useEffect)(() => {
|
|
32
|
-
if (creditCards.length
|
|
33
|
-
const options = creditCards.map(i => ({
|
|
34
|
-
|
|
40
|
+
if (creditCards.length) {
|
|
41
|
+
const options = creditCards.map((i) => ({
|
|
42
|
+
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
35
43
|
value: i.customer_card_id,
|
|
36
44
|
}));
|
|
37
45
|
setCreditCardOptions(options);
|
|
@@ -41,17 +49,18 @@ _recaptchaKey = null, initState, cardData, cardType) => {
|
|
|
41
49
|
setCreditCard(defaultCard);
|
|
42
50
|
setIsNewCard(false);
|
|
43
51
|
}
|
|
44
|
-
}, [creditCards
|
|
52
|
+
}, [creditCards]);
|
|
45
53
|
(0, react_1.useEffect)(() => {
|
|
54
|
+
var _a;
|
|
46
55
|
if (customer) {
|
|
47
|
-
setEmail(customer.email);
|
|
56
|
+
setEmail((_a = customer.email) !== null && _a !== void 0 ? _a : null);
|
|
48
57
|
setName(`${customer.first_name} ${customer.last_name}`);
|
|
49
58
|
}
|
|
50
59
|
}, [customer]);
|
|
51
60
|
const makeGiftCards = (giftCards) => {
|
|
52
61
|
return giftCards.reduce((arr, card) => {
|
|
53
|
-
const { amount, quantity, email
|
|
54
|
-
const giftCard = !
|
|
62
|
+
const { amount, quantity, email } = card;
|
|
63
|
+
const giftCard = !email || !email.length ? { amount, quantity } : card;
|
|
55
64
|
return [...arr, giftCard];
|
|
56
65
|
}, []);
|
|
57
66
|
};
|
|
@@ -61,8 +70,8 @@ _recaptchaKey = null, initState, cardData, cardType) => {
|
|
|
61
70
|
const handleEmail = (value) => {
|
|
62
71
|
setEmail(value);
|
|
63
72
|
};
|
|
64
|
-
const handleChange = (
|
|
65
|
-
const [field, index] =
|
|
73
|
+
const handleChange = (name, value) => {
|
|
74
|
+
const [field, index] = name.split('-');
|
|
66
75
|
const newCards = cards.map((card, idx) => {
|
|
67
76
|
return idx === parseInt(index) ? Object.assign(Object.assign({}, card), { [field]: value }) : card;
|
|
68
77
|
});
|
|
@@ -71,38 +80,70 @@ _recaptchaKey = null, initState, cardData, cardType) => {
|
|
|
71
80
|
const handleQuantity = (index, quantity) => {
|
|
72
81
|
const newCards = quantity > 0
|
|
73
82
|
? cards.map((card, idx) => {
|
|
74
|
-
return idx ===
|
|
83
|
+
return idx === parseInt(`${index}`)
|
|
84
|
+
? Object.assign(Object.assign({}, card), { quantity: quantity }) : card;
|
|
75
85
|
})
|
|
76
|
-
: cards.filter((
|
|
86
|
+
: cards.filter((_, idx) => idx !== index);
|
|
77
87
|
setCards(newCards);
|
|
78
88
|
};
|
|
79
89
|
const handleAddAnother = () => {
|
|
80
90
|
setCards([...cards, initState]);
|
|
81
91
|
};
|
|
82
92
|
const handleCreditCard = (value) => {
|
|
83
|
-
const customerCardId = parseInt(value);
|
|
93
|
+
const customerCardId = parseInt(`${value}`);
|
|
84
94
|
setCreditCard({ customer_card_id: customerCardId });
|
|
85
95
|
};
|
|
86
96
|
const purchaseWithCaptcha = (credit_card) => {
|
|
97
|
+
var _a;
|
|
87
98
|
const alert = {
|
|
88
99
|
type: 'working',
|
|
89
100
|
args: { text: 'Submitting your purchase...' },
|
|
90
101
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
if (recaptchaKey) {
|
|
103
|
+
try {
|
|
104
|
+
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
105
|
+
if (!token) {
|
|
106
|
+
setSubmitting(false);
|
|
107
|
+
setErrors({
|
|
108
|
+
form: 'Please complete the recaptcha before submitting',
|
|
109
|
+
});
|
|
110
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
setSubmitting(true);
|
|
114
|
+
setAlert(alert);
|
|
115
|
+
const gift_cards = makeGiftCards(cards);
|
|
116
|
+
purchase({ token, credit_card, name: name !== null && name !== void 0 ? name : "", email: email !== null && email !== void 0 ? email : "", url, gift_cards });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
setSubmitting(false);
|
|
121
|
+
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
122
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
setSubmitting(true);
|
|
127
|
+
setAlert(alert);
|
|
128
|
+
const gift_cards = makeGiftCards(cards);
|
|
129
|
+
purchase({ credit_card, name: name !== null && name !== void 0 ? name : "", email: email !== null && email !== void 0 ? email : "", url, gift_cards });
|
|
130
|
+
}
|
|
95
131
|
};
|
|
96
132
|
const handleSubmit = () => {
|
|
133
|
+
var _a, _b, _c;
|
|
97
134
|
if (!name || !email) {
|
|
98
135
|
setErrors({ form: 'Both name and email are required' });
|
|
136
|
+
if (inputRef.current)
|
|
137
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && inputRef.current.focus();
|
|
138
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
99
139
|
}
|
|
100
140
|
else {
|
|
101
141
|
if (isNewCard) {
|
|
102
|
-
const { card, errors
|
|
103
|
-
if (
|
|
104
|
-
setErrors(Object.assign(Object.assign({},
|
|
142
|
+
const { card, errors } = (0, utils_1.validateCreditCard)(cardData, cardType);
|
|
143
|
+
if (errors) {
|
|
144
|
+
setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
|
|
105
145
|
setSubmitting(false);
|
|
146
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
106
147
|
}
|
|
107
148
|
else {
|
|
108
149
|
purchaseWithCaptcha(card);
|
|
@@ -111,18 +152,18 @@ _recaptchaKey = null, initState, cardData, cardType) => {
|
|
|
111
152
|
else {
|
|
112
153
|
purchaseWithCaptcha(creditCard);
|
|
113
154
|
}
|
|
155
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
114
156
|
}
|
|
115
157
|
};
|
|
116
158
|
const handleReset = () => {
|
|
117
|
-
if (!customer) {
|
|
118
|
-
setName(undefined);
|
|
119
|
-
setEmail(undefined);
|
|
120
|
-
}
|
|
121
159
|
setCards([initState]);
|
|
122
160
|
setErrors({});
|
|
123
161
|
reset();
|
|
124
162
|
};
|
|
125
163
|
return {
|
|
164
|
+
inputRef,
|
|
165
|
+
submitRef,
|
|
166
|
+
recaptchaRef,
|
|
126
167
|
creditCardOptions,
|
|
127
168
|
handleName,
|
|
128
169
|
handleEmail,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GuestData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useGuestForm: <TnputRef extends Field, SubmitRef extends Field>(email: string, loading: RequestStatus, errors: any, checkGuest: (email?: string) => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<TnputRef | null>;
|
|
7
|
+
data: Partial<GuestData>;
|
|
8
|
+
errMsg: any;
|
|
9
|
+
submitting: boolean;
|
|
10
|
+
handleChange: (name: string, value: string) => void;
|
|
11
|
+
handleSubmit: () => void;
|
|
12
|
+
};
|
|
13
|
+
export default useGuestForm;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useGuestForm = (email, loading, errors, checkGuest) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
7
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
8
|
+
const submitting = loading === 'pending';
|
|
9
|
+
const errMsg = errors ? errors.email || errors.form : null;
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (loading === 'idle') {
|
|
13
|
+
if (errMsg)
|
|
14
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
15
|
+
}
|
|
16
|
+
}, [loading, errMsg]);
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
if (email && data.email === undefined) {
|
|
19
|
+
setData({ email });
|
|
20
|
+
}
|
|
21
|
+
}, [email, data.email]);
|
|
22
|
+
const handleChange = (name, value) => {
|
|
23
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
24
|
+
};
|
|
25
|
+
const handleSubmit = () => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { email } = data;
|
|
28
|
+
checkGuest(email);
|
|
29
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
submitRef,
|
|
33
|
+
inputRef,
|
|
34
|
+
data,
|
|
35
|
+
errMsg,
|
|
36
|
+
submitting,
|
|
37
|
+
handleChange,
|
|
38
|
+
handleSubmit,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.default = useGuestForm;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ConfigFulfillment, OrderFulfillment, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useOrderFulfillmentForm: <SubmitRef extends Field>(orderId: number, fulfillment: Partial<OrderFulfillment>, loading: RequestStatus, error: any, update: (orderId: number, data: Partial<OrderFulfillment>) => void, settings?: ConfigFulfillment, showAllFields?: boolean) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
fields: import("@open-tender/types").ConfigFulfillmentField[] | undefined;
|
|
7
|
+
data: Partial<OrderFulfillment>;
|
|
8
|
+
errors: any;
|
|
9
|
+
submitting: boolean;
|
|
10
|
+
handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
11
|
+
handleSubmit: () => void;
|
|
12
|
+
};
|
|
13
|
+
export default useOrderFulfillmentForm;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
7
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
8
|
+
const errors = error || {};
|
|
9
|
+
const empty = Object.values(fulfillment).every((i) => !i);
|
|
10
|
+
const fields = !empty && !showAllFields
|
|
11
|
+
? settings === null || settings === void 0 ? void 0 : settings.fields.filter((i) => i.name.startsWith('arrival'))
|
|
12
|
+
: settings === null || settings === void 0 ? void 0 : settings.fields;
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (loading === 'idle')
|
|
15
|
+
setSubmitting(false);
|
|
16
|
+
}, [loading]);
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
setData(fulfillment);
|
|
19
|
+
}, [fulfillment]);
|
|
20
|
+
const handleChange = (name, type, value, checked) => {
|
|
21
|
+
const inputValue = type === 'checkbox' ? checked : value;
|
|
22
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
23
|
+
};
|
|
24
|
+
const handleSubmit = () => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
setSubmitting(true);
|
|
27
|
+
update(orderId, Object.assign(Object.assign({}, data), { has_arrived: true }));
|
|
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
|
+
fields,
|
|
33
|
+
data,
|
|
34
|
+
errors,
|
|
35
|
+
submitting,
|
|
36
|
+
handleChange,
|
|
37
|
+
handleSubmit,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.default = useOrderFulfillmentForm;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OrderRating } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useOrderRatingForm: <SubmitRef extends Field>(orderId: number, orderRating: OrderRating, updateRating: (orderId: number, rating: Partial<OrderRating>) => void, callback?: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
stars: number[];
|
|
7
|
+
rating: number;
|
|
8
|
+
handleRating: (star: number) => void;
|
|
9
|
+
comments: string;
|
|
10
|
+
handleComments: (value: string) => void;
|
|
11
|
+
handleSubmit: () => void;
|
|
12
|
+
};
|
|
13
|
+
export default useOrderRatingForm;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useOrderRatingForm = (orderId, orderRating, updateRating, callback) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const [rating, setRating] = (0, react_1.useState)(orderRating.rating || 0);
|
|
7
|
+
const [comments, setComments] = (0, react_1.useState)(orderRating.comments || '');
|
|
8
|
+
const stars = [1, 2, 3, 4, 5];
|
|
9
|
+
const handleRating = (star) => {
|
|
10
|
+
setRating(star);
|
|
11
|
+
};
|
|
12
|
+
const handleComments = (value) => {
|
|
13
|
+
setComments(value);
|
|
14
|
+
};
|
|
15
|
+
const handleSubmit = () => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const data = { rating, comments };
|
|
18
|
+
updateRating(orderId, data);
|
|
19
|
+
if (callback)
|
|
20
|
+
callback();
|
|
21
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
submitRef,
|
|
25
|
+
stars,
|
|
26
|
+
rating,
|
|
27
|
+
handleRating,
|
|
28
|
+
comments,
|
|
29
|
+
handleComments,
|
|
30
|
+
handleSubmit,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.default = useOrderRatingForm;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ConfigBrand, Profile, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
interface ProfileFormField {
|
|
5
|
+
label: string;
|
|
6
|
+
name: keyof Profile;
|
|
7
|
+
type: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
autoComplete?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const useProfileForm: <SubmitRef extends Field>(profile: Partial<Profile>, loading: RequestStatus, error: any, update: (data: Partial<Profile>) => void, optIns?: Partial<ConfigBrand>) => {
|
|
12
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
13
|
+
accepts_marketing: import("@open-tender/types").ConfigAcceptMarketing | undefined;
|
|
14
|
+
order_notifications: import("@open-tender/types").ConfigOrderNotifications | undefined;
|
|
15
|
+
data: Partial<Profile>;
|
|
4
16
|
errors: any;
|
|
5
17
|
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
|
-
})[];
|
|
18
|
+
fields: Partial<ProfileFormField>[];
|
|
25
19
|
errMsg: string | null;
|
|
26
|
-
handleChange: (
|
|
20
|
+
handleChange: (name: string, type: string, value?: string, checked?: boolean) => void;
|
|
21
|
+
handleRadio: (name: string, value: string) => void;
|
|
27
22
|
handleSubmit: () => void;
|
|
28
23
|
};
|
|
29
24
|
export default useProfileForm;
|
|
@@ -2,58 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const useProfileForm = (profile, loading, error, update) => {
|
|
5
|
+
const useProfileForm = (profile, loading, error, update, optIns = {}) => {
|
|
6
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
7
|
+
const { accepts_marketing, order_notifications } = optIns;
|
|
6
8
|
const [data, setData] = (0, react_1.useState)({});
|
|
7
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
8
10
|
const errMsg = error ? 'There are one or more errors below.' : null;
|
|
9
11
|
const errors = error || {};
|
|
10
12
|
const fields = [
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
name: 'first_name',
|
|
14
|
-
type: 'default',
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
{ label: 'Last Name', name: 'last_name', type: 'default', required: true },
|
|
13
|
+
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
14
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true },
|
|
18
15
|
{
|
|
19
16
|
label: 'Email',
|
|
20
17
|
name: 'email',
|
|
21
|
-
type: 'email
|
|
18
|
+
type: 'email',
|
|
22
19
|
required: true,
|
|
23
20
|
autoComplete: 'email',
|
|
24
21
|
},
|
|
25
|
-
{ label: 'Phone', name: 'phone', type: '
|
|
26
|
-
{ label: 'Company', name: 'company', type: '
|
|
27
|
-
{
|
|
28
|
-
label: 'Birth Date (mm/dd/yyyy)',
|
|
29
|
-
name: 'birth_date',
|
|
30
|
-
type: 'number-pad',
|
|
31
|
-
},
|
|
22
|
+
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
23
|
+
{ label: 'Company', name: 'company', type: 'text' },
|
|
32
24
|
];
|
|
33
25
|
(0, react_1.useEffect)(() => {
|
|
34
26
|
if (loading === 'idle') {
|
|
35
27
|
setSubmitting(false);
|
|
28
|
+
if (error) {
|
|
29
|
+
//handle form inputs[0] focus
|
|
30
|
+
}
|
|
36
31
|
}
|
|
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]);
|
|
32
|
+
}, [loading, error]);
|
|
43
33
|
(0, react_1.useEffect)(() => {
|
|
44
34
|
setData(profile);
|
|
45
35
|
}, [profile]);
|
|
46
|
-
const handleChange = (
|
|
36
|
+
const handleChange = (name, type, value, checked) => {
|
|
47
37
|
const inputValue = type === 'checkbox'
|
|
48
38
|
? checked
|
|
49
|
-
:
|
|
50
|
-
? (0, utils_1.makePhone)(value)
|
|
51
|
-
:
|
|
52
|
-
? (0, utils_1.makeBirthDate)(value)
|
|
39
|
+
: name === 'phone'
|
|
40
|
+
? (0, utils_1.makePhone)(value !== null && value !== void 0 ? value : '')
|
|
41
|
+
: name === 'birth_date'
|
|
42
|
+
? (0, utils_1.makeBirthDate)(value !== null && value !== void 0 ? value : '')
|
|
53
43
|
: value;
|
|
54
|
-
setData(Object.assign(Object.assign({}, data), { [
|
|
44
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
45
|
+
};
|
|
46
|
+
const handleRadio = (name, value) => {
|
|
47
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
55
48
|
};
|
|
56
49
|
const handleSubmit = () => {
|
|
50
|
+
var _a, _b;
|
|
57
51
|
setSubmitting(true);
|
|
58
52
|
const updatedData = fields.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: data[i.name] })), {});
|
|
59
53
|
updatedData.birth_date = data.birth_date
|
|
@@ -61,14 +55,19 @@ const useProfileForm = (profile, loading, error, update) => {
|
|
|
61
55
|
: null;
|
|
62
56
|
updatedData.gender = data.gender || null;
|
|
63
57
|
update(updatedData);
|
|
58
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
64
59
|
};
|
|
65
60
|
return {
|
|
61
|
+
submitRef,
|
|
62
|
+
accepts_marketing,
|
|
63
|
+
order_notifications,
|
|
66
64
|
data,
|
|
67
65
|
errors,
|
|
68
66
|
submitting,
|
|
69
67
|
fields,
|
|
70
68
|
errMsg,
|
|
71
69
|
handleChange,
|
|
70
|
+
handleRadio,
|
|
72
71
|
handleSubmit,
|
|
73
72
|
};
|
|
74
73
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RequestStatus, ResetPasswordData } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
interface ResetPasswordFormField {
|
|
5
|
+
label: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const useResetPasswordForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, error: any, reset: (newPassword: string, callback: () => void) => void, resetForm: () => void, resetToken: () => void) => {
|
|
11
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
12
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
13
|
+
fields: ResetPasswordFormField[];
|
|
14
|
+
data: Partial<ResetPasswordData>;
|
|
15
|
+
errors: {};
|
|
16
|
+
submitting: boolean;
|
|
17
|
+
handleChange: (name: string, value: string) => void;
|
|
18
|
+
handleSubmit: () => void;
|
|
19
|
+
};
|
|
20
|
+
export default useResetPasswordForm;
|