@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,51 +1,71 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const handleChange = (name, value) => {
|
|
18
|
-
if (name === 'acct') {
|
|
19
|
-
const currentType = getCardType(value.replace(/\s/g, ''));
|
|
20
|
-
setCardType(currentType);
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { validateCreditCard } from '@open-tender/utils';
|
|
3
|
+
const useCreditCardForm = (loading, error, data, cardType, setErrors, addCard, callback, recaptchaKey, revenue_center_id, windowRef) => {
|
|
4
|
+
const submitRef = useRef(null);
|
|
5
|
+
const recaptchaRef = useRef(null);
|
|
6
|
+
const [submitting, setSubmitting] = useState(false);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (loading === 'idle') {
|
|
9
|
+
setSubmitting(false);
|
|
10
|
+
if (error) {
|
|
11
|
+
if (recaptchaRef.current)
|
|
12
|
+
recaptchaRef.current.reset();
|
|
13
|
+
setErrors(error);
|
|
14
|
+
if (windowRef)
|
|
15
|
+
windowRef.scrollTo({ top: 0 });
|
|
16
|
+
}
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const { errors:
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
}, [windowRef, loading, error, setErrors]);
|
|
19
|
+
const handleSubmit = () => {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
setErrors({});
|
|
22
|
+
const { card, errors: cardErrors } = validateCreditCard(data, cardType);
|
|
23
|
+
if (cardErrors) {
|
|
24
|
+
setErrors(cardErrors);
|
|
25
|
+
setSubmitting(false);
|
|
26
|
+
if (windowRef)
|
|
27
|
+
windowRef.scrollTo({ top: 0 });
|
|
30
28
|
}
|
|
31
29
|
else {
|
|
32
|
-
|
|
30
|
+
const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
|
|
31
|
+
if (recaptchaKey) {
|
|
32
|
+
try {
|
|
33
|
+
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
34
|
+
if (!token) {
|
|
35
|
+
setSubmitting(false);
|
|
36
|
+
setErrors({
|
|
37
|
+
form: 'Please complete the recaptcha before submitting',
|
|
38
|
+
});
|
|
39
|
+
if (windowRef)
|
|
40
|
+
windowRef.scrollTo({ top: 0 });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
setSubmitting(true);
|
|
44
|
+
addCard(Object.assign(Object.assign({}, cardRc), { token }), callback);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
setSubmitting(false);
|
|
49
|
+
setErrors({
|
|
50
|
+
form: 'Please complete the recaptcha before submitting',
|
|
51
|
+
});
|
|
52
|
+
if (windowRef)
|
|
53
|
+
windowRef.scrollTo({ top: 0 });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
setSubmitting(true);
|
|
58
|
+
addCard(cardRc, callback);
|
|
59
|
+
}
|
|
33
60
|
}
|
|
34
|
-
|
|
35
|
-
const handleReset = () => {
|
|
36
|
-
setData(defaultState);
|
|
37
|
-
setErrors({});
|
|
61
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
38
62
|
};
|
|
39
63
|
return {
|
|
64
|
+
submitRef,
|
|
65
|
+
recaptchaRef,
|
|
40
66
|
data,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
disabled,
|
|
44
|
-
setErrors,
|
|
45
|
-
handleChange,
|
|
46
|
-
handleBlur,
|
|
47
|
-
handleReset,
|
|
48
|
-
isComplete,
|
|
67
|
+
submitting,
|
|
68
|
+
handleSubmit,
|
|
49
69
|
};
|
|
50
70
|
};
|
|
51
|
-
export default
|
|
71
|
+
export default useCreditCardForm;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GuestData } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useDineInForm: <InputRef extends Field, SubmitRef extends Field>(initialData: Partial<GuestData> | undefined, submitGuest: (data: any) => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
7
|
+
data: Partial<GuestData>;
|
|
3
8
|
errMsg: string | null;
|
|
4
|
-
handleChange: (
|
|
9
|
+
handleChange: (name: string, value: string) => void;
|
|
5
10
|
handleSubmit: () => void;
|
|
6
11
|
};
|
|
7
12
|
export default useDineInForm;
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
2
|
const useDineInForm = (initialData = {}, submitGuest) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
3
5
|
const [data, setData] = useState(initialData);
|
|
4
6
|
const [errMsg, setErrMsg] = useState(null);
|
|
5
|
-
const handleChange = (
|
|
6
|
-
setData(Object.assign(Object.assign({}, data), { [
|
|
7
|
+
const handleChange = (name, value) => {
|
|
8
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
7
9
|
};
|
|
8
10
|
const handleSubmit = () => {
|
|
11
|
+
var _a, _b;
|
|
9
12
|
if (!data.first_name || !data.last_name) {
|
|
10
13
|
setErrMsg('Both first and last name are required');
|
|
11
14
|
}
|
|
12
15
|
else {
|
|
13
16
|
submitGuest({ customer: data });
|
|
14
17
|
}
|
|
18
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
15
19
|
};
|
|
16
20
|
return {
|
|
21
|
+
submitRef,
|
|
22
|
+
inputRef,
|
|
17
23
|
data,
|
|
18
24
|
errMsg,
|
|
19
25
|
handleChange,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Dispatch } from 'react';
|
|
2
2
|
import { CardType, CreditCard, CreditCardData, CreditCards, Profile, PurchaseDonationRequest, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
3
4
|
interface CreditCardOption {
|
|
4
5
|
label: string;
|
|
5
6
|
value: unknown;
|
|
6
7
|
}
|
|
7
|
-
declare const useDonationsForm: (purchase: (data: PurchaseDonationRequest, callback?: () => void) => void, reset: () => void, setAlert: Dispatch<any>, loading: RequestStatus, error: any, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType) => {
|
|
8
|
+
declare const useDonationsForm: <InputRef extends Field, SubmitRef extends Field>(purchase: (data: PurchaseDonationRequest, callback?: () => void) => void, reset: () => void, setAlert: Dispatch<any>, loading: RequestStatus, error: any, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowref?: Window) => {
|
|
9
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
10
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
8
11
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
9
12
|
amount: string | null;
|
|
10
13
|
handleAmount: (value: string) => void;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useMemo, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { makeNumeric, validateCreditCard } from '../utils';
|
|
3
|
-
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType) => {
|
|
3
|
+
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowref) => {
|
|
4
|
+
const submitRef = useRef(null);
|
|
5
|
+
const inputRef = useRef(null);
|
|
4
6
|
const recaptchaRef = useRef(null);
|
|
5
7
|
const [amount, setAmount] = useState('');
|
|
6
8
|
const [email, setEmail] = useState('');
|
|
@@ -18,6 +20,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
18
20
|
.reduce((obj, [key, value]) => (Object.assign(Object.assign({}, obj), { [key]: value })), {})
|
|
19
21
|
: {}, [errors]);
|
|
20
22
|
useEffect(() => {
|
|
23
|
+
var _a, _b;
|
|
21
24
|
if (loading === 'idle') {
|
|
22
25
|
setSubmitting(false);
|
|
23
26
|
setAlert({ type: 'close' });
|
|
@@ -25,12 +28,14 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
25
28
|
if (recaptchaRef.current)
|
|
26
29
|
recaptchaRef.current.reset();
|
|
27
30
|
setErrors(error);
|
|
31
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
32
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
28
33
|
}
|
|
29
34
|
else if (success) {
|
|
30
|
-
|
|
35
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
|
-
}, [loading, error, setAlert, success]);
|
|
38
|
+
}, [windowref, loading, error, setAlert, success]);
|
|
34
39
|
useEffect(() => {
|
|
35
40
|
if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
|
|
36
41
|
const options = creditCards.map(i => ({
|
|
@@ -70,6 +75,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
70
75
|
if (!token) {
|
|
71
76
|
setSubmitting(false);
|
|
72
77
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
78
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
73
79
|
}
|
|
74
80
|
else {
|
|
75
81
|
setSubmitting(true);
|
|
@@ -85,6 +91,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
85
91
|
catch (err) {
|
|
86
92
|
setSubmitting(false);
|
|
87
93
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
94
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
else {
|
|
@@ -99,8 +106,11 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
99
106
|
}
|
|
100
107
|
};
|
|
101
108
|
const handleSubmit = () => {
|
|
109
|
+
var _a, _b, _c;
|
|
102
110
|
if (!amount || !email) {
|
|
103
111
|
setErrors({ form: 'Both amount and email are required' });
|
|
112
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && inputRef.current.focus();
|
|
113
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
104
114
|
}
|
|
105
115
|
else {
|
|
106
116
|
if (isNewCard) {
|
|
@@ -109,6 +119,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
109
119
|
if (errs) {
|
|
110
120
|
setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
|
|
111
121
|
setSubmitting(false);
|
|
122
|
+
windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
|
|
112
123
|
}
|
|
113
124
|
else {
|
|
114
125
|
purchaseWithCaptcha(card);
|
|
@@ -118,6 +129,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
118
129
|
else {
|
|
119
130
|
purchaseWithCaptcha(creditCard);
|
|
120
131
|
}
|
|
132
|
+
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
121
133
|
}
|
|
122
134
|
};
|
|
123
135
|
const handleReset = () => {
|
|
@@ -132,6 +144,8 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
132
144
|
reset();
|
|
133
145
|
};
|
|
134
146
|
return {
|
|
147
|
+
inputRef,
|
|
148
|
+
submitRef,
|
|
135
149
|
recaptchaRef,
|
|
136
150
|
amount,
|
|
137
151
|
handleAmount,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { RequestStatus } from '@open-tender/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
callback: () => void;
|
|
7
|
-
}
|
|
8
|
-
declare const useGiftCardAssignForm: ({ loading, error, assign, callback, }: useGiftCardAssignFormProps) => {
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useGiftCardAssignForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, error: any, assign: (card_number: number, callback: () => void) => void, callback: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
9
7
|
cardNumber: string;
|
|
10
8
|
errors: any;
|
|
11
9
|
submitting: boolean;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
const useGiftCardAssignForm = (
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
const useGiftCardAssignForm = (loading, error, assign, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
3
5
|
const [cardNumber, setCardNumber] = useState('');
|
|
4
6
|
const [errors, setErrors] = useState({});
|
|
5
7
|
const [submitting, setSubmitting] = useState(false);
|
|
6
8
|
useEffect(() => {
|
|
9
|
+
var _a, _b;
|
|
7
10
|
if (loading === 'idle') {
|
|
8
11
|
setSubmitting(false);
|
|
9
12
|
if (error) {
|
|
10
13
|
setErrors(error);
|
|
14
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}, [loading, error]);
|
|
@@ -15,17 +19,21 @@ const useGiftCardAssignForm = ({ loading, error, assign, callback, }) => {
|
|
|
15
19
|
setCardNumber(value);
|
|
16
20
|
};
|
|
17
21
|
const handleSubmit = () => {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
18
23
|
setSubmitting(true);
|
|
19
24
|
const card_number = parseInt(cardNumber);
|
|
20
25
|
if (isNaN(card_number)) {
|
|
21
26
|
setErrors({ card_number: 'Card numbers must be all digits' });
|
|
22
|
-
|
|
27
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
23
28
|
}
|
|
24
29
|
else {
|
|
25
|
-
assign(
|
|
30
|
+
assign(card_number, callback);
|
|
31
|
+
((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur) && ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur());
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
return {
|
|
35
|
+
submitRef,
|
|
36
|
+
inputRef,
|
|
29
37
|
cardNumber,
|
|
30
38
|
errors,
|
|
31
39
|
submitting,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { RequestStatus } from '@open-tender/types';
|
|
2
|
-
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useGiftCardAssignOtherForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, error: any, giftCardId: number, assign: (id: number, email: string, callback: () => void) => void, callback: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
3
7
|
email: string;
|
|
4
8
|
errors: any;
|
|
5
9
|
submitting: boolean;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
3
5
|
const [email, setEmail] = useState('');
|
|
4
6
|
const [errors, setErrors] = useState({});
|
|
5
7
|
const [submitting, setSubmitting] = useState(false);
|
|
6
8
|
useEffect(() => {
|
|
9
|
+
var _a, _b;
|
|
7
10
|
if (loading === 'idle') {
|
|
8
11
|
setSubmitting(false);
|
|
9
12
|
if (error) {
|
|
10
13
|
setErrors(error);
|
|
14
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
}, [loading, error]);
|
|
@@ -15,10 +19,14 @@ const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback
|
|
|
15
19
|
setEmail(value);
|
|
16
20
|
};
|
|
17
21
|
const handleSubmit = () => {
|
|
22
|
+
var _a, _b;
|
|
18
23
|
setSubmitting(true);
|
|
19
24
|
assign(giftCardId, email, callback);
|
|
25
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
20
26
|
};
|
|
21
27
|
return {
|
|
28
|
+
submitRef,
|
|
29
|
+
inputRef,
|
|
22
30
|
email,
|
|
23
31
|
errors,
|
|
24
32
|
submitting,
|
|
@@ -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;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
3
5
|
const customerCardId = creditCards[0].customer_card_id;
|
|
4
6
|
const [data, setData] = useState({ customer_card_id: customerCardId });
|
|
5
7
|
const [errors, setErrors] = useState({});
|
|
6
8
|
const [submitting, setSubmitting] = useState(false);
|
|
7
|
-
const options = creditCards.map(i => {
|
|
9
|
+
const options = creditCards.map((i) => {
|
|
8
10
|
return {
|
|
9
|
-
|
|
11
|
+
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
10
12
|
value: i.customer_card_id,
|
|
11
13
|
};
|
|
12
14
|
});
|
|
13
15
|
useEffect(() => {
|
|
16
|
+
var _a, _b;
|
|
14
17
|
if (loading === 'idle') {
|
|
15
18
|
setSubmitting(false);
|
|
16
19
|
if (error) {
|
|
@@ -18,13 +21,16 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
18
21
|
error.amount = 'Please enter a positive dollar amount';
|
|
19
22
|
}
|
|
20
23
|
setErrors(error);
|
|
24
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
}, [loading, error]);
|
|
24
|
-
const handleChange = (
|
|
25
|
-
|
|
28
|
+
const handleChange = (name, type, value, checked) => {
|
|
29
|
+
const inputValue = type === 'checkbox' ? checked : value;
|
|
30
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
26
31
|
};
|
|
27
32
|
const handleSubmit = () => {
|
|
33
|
+
var _a, _b;
|
|
28
34
|
setSubmitting(true);
|
|
29
35
|
if (!data.customer_card_id) {
|
|
30
36
|
data.customer_card_id = customerCardId;
|
|
@@ -33,8 +39,11 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
33
39
|
giftCard
|
|
34
40
|
? update(giftCard.gift_card_id, data, callback)
|
|
35
41
|
: add(data, callback);
|
|
42
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
36
43
|
};
|
|
37
44
|
return {
|
|
45
|
+
submitRef,
|
|
46
|
+
inputRef,
|
|
38
47
|
options,
|
|
39
48
|
errors,
|
|
40
49
|
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;
|