@open-tender/utils 0.1.9 → 0.1.11
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/useCreditCard.d.ts +3 -3
- package/dist/cjs/hooks/useCreditCard.js +10 -15
- package/dist/cjs/hooks/useDonationForm.d.ts +13 -14
- package/dist/cjs/hooks/useDonationForm.js +17 -17
- package/dist/cjs/hooks/useGiftCardForm.d.ts +1 -1
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +12 -22
- package/dist/cjs/hooks/useGiftCardsForm.js +17 -15
- package/dist/cjs/utils/cards.d.ts +2 -2
- package/dist/cjs/utils/cards.js +2 -2
- package/dist/cjs/utils/cart.d.ts +32 -24
- package/dist/cjs/utils/cart.js +30 -87
- package/dist/cjs/utils/checkout.d.ts +38 -19
- package/dist/cjs/utils/checkout.js +13 -2
- package/dist/cjs/utils/datetimes.d.ts +10 -109
- package/dist/cjs/utils/datetimes.js +15 -149
- package/dist/cjs/utils/index.d.ts +0 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/maps.d.ts +10 -10
- package/dist/cjs/utils/maps.js +4 -5
- package/dist/cjs/utils/orders.d.ts +1 -20
- package/dist/cjs/utils/orders.js +83 -72
- package/dist/cjs/utils/revenueCenters.d.ts +2 -2
- package/dist/cjs/utils/revenueCenters.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +3 -3
- package/dist/esm/hooks/useCreditCard.js +10 -15
- package/dist/esm/hooks/useDonationForm.d.ts +13 -14
- package/dist/esm/hooks/useDonationForm.js +17 -17
- package/dist/esm/hooks/useGiftCardForm.d.ts +1 -1
- package/dist/esm/hooks/useGiftCardsForm.d.ts +12 -22
- package/dist/esm/hooks/useGiftCardsForm.js +17 -15
- package/dist/esm/utils/cards.d.ts +2 -2
- package/dist/esm/utils/cards.js +2 -2
- package/dist/esm/utils/cart.d.ts +32 -24
- package/dist/esm/utils/cart.js +29 -85
- package/dist/esm/utils/checkout.d.ts +38 -19
- package/dist/esm/utils/checkout.js +11 -1
- package/dist/esm/utils/datetimes.d.ts +10 -109
- package/dist/esm/utils/datetimes.js +14 -142
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/maps.d.ts +10 -10
- package/dist/esm/utils/maps.js +4 -5
- package/dist/esm/utils/orders.d.ts +1 -20
- package/dist/esm/utils/orders.js +82 -68
- package/dist/esm/utils/revenueCenters.d.ts +2 -2
- package/dist/esm/utils/revenueCenters.js +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { CardType,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export 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, windowref?: Window) => {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, DonationPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
|
+
type: string;
|
|
5
|
+
args?: unknown;
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
10
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
11
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
12
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -19,11 +16,13 @@ export declare const useDonationsForm: (purchase: (data: PurchaseDonationRequest
|
|
|
19
16
|
newCardErrors: {};
|
|
20
17
|
submitting: boolean;
|
|
21
18
|
isNewCard: boolean;
|
|
22
|
-
creditCard:
|
|
23
|
-
creditCardOptions:
|
|
19
|
+
creditCard: CreditCardSaved | null;
|
|
20
|
+
creditCardOptions: {
|
|
21
|
+
name: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
}[];
|
|
24
24
|
handleCreditCard: (value: string) => void;
|
|
25
|
-
handleSubmit: (
|
|
25
|
+
handleSubmit: () => void;
|
|
26
26
|
handleReset: () => void;
|
|
27
|
-
setErrors: Dispatch<any>;
|
|
27
|
+
setErrors: import("react").Dispatch<any>;
|
|
28
28
|
};
|
|
29
|
-
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useMemo, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { makeNumeric, validateCreditCard } from '../utils';
|
|
3
|
-
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType,
|
|
3
|
+
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const recaptchaRef = useRef(null);
|
|
7
7
|
const [amount, setAmount] = useState('');
|
|
8
8
|
const [email, setEmail] = useState('');
|
|
9
9
|
const [isNewCard, setIsNewCard] = useState(true);
|
|
10
|
-
const [creditCard, setCreditCard] = useState(
|
|
10
|
+
const [creditCard, setCreditCard] = useState(null);
|
|
11
11
|
const [creditCardOptions, setCreditCardOptions] = useState([]);
|
|
12
12
|
const [errors, setErrors] = useState({});
|
|
13
13
|
const [submitting, setSubmitting] = useState(false);
|
|
@@ -29,30 +29,30 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
29
29
|
recaptchaRef.current.reset();
|
|
30
30
|
setErrors(error);
|
|
31
31
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
32
|
-
|
|
32
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
33
33
|
}
|
|
34
34
|
else if (success) {
|
|
35
|
-
|
|
35
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
}, [
|
|
38
|
+
}, [windowRef, loading, error, setAlert, success]);
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
|
|
41
41
|
const options = creditCards.map(i => ({
|
|
42
|
-
|
|
42
|
+
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
43
43
|
value: i.customer_card_id
|
|
44
44
|
}));
|
|
45
45
|
setCreditCardOptions(options);
|
|
46
46
|
const defaultCard = creditCards.length
|
|
47
47
|
? { customer_card_id: creditCards[0].customer_card_id }
|
|
48
|
-
:
|
|
48
|
+
: null;
|
|
49
49
|
setCreditCard(defaultCard);
|
|
50
50
|
setIsNewCard(false);
|
|
51
51
|
}
|
|
52
52
|
}, [creditCards, loading]);
|
|
53
53
|
useEffect(() => {
|
|
54
|
-
setEmail((customer === null || customer === void 0 ? void 0 : customer.email)
|
|
55
|
-
}, [customer]);
|
|
54
|
+
setEmail((customer === null || customer === void 0 ? void 0 : customer.email) || '');
|
|
55
|
+
}, [customer === null || customer === void 0 ? void 0 : customer.email]);
|
|
56
56
|
const handleAmount = (value) => {
|
|
57
57
|
const cleanValue = makeNumeric(value);
|
|
58
58
|
setAmount(cleanValue);
|
|
@@ -75,7 +75,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
75
75
|
if (!token) {
|
|
76
76
|
setSubmitting(false);
|
|
77
77
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
78
|
-
|
|
78
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
81
|
setSubmitting(true);
|
|
@@ -91,7 +91,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
91
91
|
catch (err) {
|
|
92
92
|
setSubmitting(false);
|
|
93
93
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
94
|
-
|
|
94
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
@@ -105,13 +105,12 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
|
-
const handleSubmit = (
|
|
108
|
+
const handleSubmit = () => {
|
|
109
109
|
var _a, _b, _c;
|
|
110
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
111
110
|
if (!amount || !email) {
|
|
112
111
|
setErrors({ form: 'Both amount and email are required' });
|
|
113
112
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && inputRef.current.focus();
|
|
114
|
-
|
|
113
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
116
|
if (isNewCard) {
|
|
@@ -120,7 +119,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
120
119
|
if (errs) {
|
|
121
120
|
setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
|
|
122
121
|
setSubmitting(false);
|
|
123
|
-
|
|
122
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
124
123
|
}
|
|
125
124
|
else {
|
|
126
125
|
purchaseWithCaptcha(card);
|
|
@@ -128,7 +127,8 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
129
|
else {
|
|
131
|
-
|
|
130
|
+
if (creditCard)
|
|
131
|
+
purchaseWithCaptcha(creditCard);
|
|
132
132
|
}
|
|
133
133
|
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
134
134
|
}
|
|
@@ -140,7 +140,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
140
140
|
setEmail(null);
|
|
141
141
|
if (!customer)
|
|
142
142
|
setIsNewCard(true);
|
|
143
|
-
setCreditCard(
|
|
143
|
+
setCreditCard(null);
|
|
144
144
|
setCreditCardOptions([]);
|
|
145
145
|
reset();
|
|
146
146
|
};
|
|
@@ -5,7 +5,7 @@ export declare const useGiftCardForm: (giftCard: CustomerGiftCard, creditCards:
|
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
options: {
|
|
7
7
|
name: string;
|
|
8
|
-
value: number
|
|
8
|
+
value: number;
|
|
9
9
|
}[];
|
|
10
10
|
errors: {};
|
|
11
11
|
data: Partial<CustomerGiftCard>;
|
|
@@ -1,41 +1,31 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType,
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
value?: number;
|
|
6
|
-
}
|
|
7
|
-
interface PurchaseData {
|
|
8
|
-
credit_card: Partial<CreditCardData>;
|
|
9
|
-
email: string;
|
|
10
|
-
gift_cards: Array<Partial<PurchaseGiftCardData>>;
|
|
11
|
-
name: string;
|
|
12
|
-
url: string;
|
|
13
|
-
token?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const useGiftCardsForm: (purchase: (data: PurchaseData) => void, reset: () => void, loading: RequestStatus, error: any, success: boolean, setAlert: (data: {
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => void, reset: () => void, setAlert: (data: {
|
|
16
4
|
type: string;
|
|
17
|
-
args?:
|
|
18
|
-
}) => void,
|
|
5
|
+
args?: unknown;
|
|
6
|
+
}) => void, loading: RequestStatus, error: any, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
19
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
20
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
21
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
22
|
-
creditCardOptions:
|
|
10
|
+
creditCardOptions: {
|
|
11
|
+
name: string;
|
|
12
|
+
value: unknown;
|
|
13
|
+
}[];
|
|
23
14
|
handleName: (value: string) => void;
|
|
24
15
|
handleEmail: (value: string) => void;
|
|
25
16
|
handleChange: (name: string, value: string) => void;
|
|
26
17
|
handleQuantity: (index: number, quantity: number) => void;
|
|
27
18
|
handleAddAnother: () => void;
|
|
28
19
|
handleCreditCard: (value: number) => void;
|
|
29
|
-
handleSubmit: (
|
|
20
|
+
handleSubmit: () => void;
|
|
30
21
|
handleReset: () => void;
|
|
31
22
|
name: string | null;
|
|
32
23
|
email: string | null;
|
|
33
|
-
cards:
|
|
24
|
+
cards: GiftCardPurchaseData[];
|
|
34
25
|
isNewCard: boolean;
|
|
35
26
|
newCardErrors: {};
|
|
36
|
-
creditCard:
|
|
37
|
-
setCreditCard: import("react").Dispatch<import("react").SetStateAction<
|
|
27
|
+
creditCard: CreditCardSaved | null;
|
|
28
|
+
setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCardSaved | null>>;
|
|
38
29
|
errors: {};
|
|
39
30
|
submitting: boolean;
|
|
40
31
|
};
|
|
41
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
2
2
|
import { validateCreditCard } from '../utils';
|
|
3
|
-
export const useGiftCardsForm = (purchase, reset, loading, error, success,
|
|
3
|
+
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
4
4
|
var _a, _b;
|
|
5
5
|
const submitRef = useRef(null);
|
|
6
6
|
const inputRef = useRef(null);
|
|
@@ -9,7 +9,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
|
|
|
9
9
|
const [email, setEmail] = useState(null);
|
|
10
10
|
const [cards, setCards] = useState([initState]);
|
|
11
11
|
const [isNewCard, setIsNewCard] = useState(true);
|
|
12
|
-
const [creditCard, setCreditCard] = useState(
|
|
12
|
+
const [creditCard, setCreditCard] = useState(null);
|
|
13
13
|
const [creditCardOptions, setCreditCardOptions] = useState([]);
|
|
14
14
|
const [errors, setErrors] = useState({});
|
|
15
15
|
const [submitting, setSubmitting] = useState(false);
|
|
@@ -35,7 +35,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
|
|
|
35
35
|
}
|
|
36
36
|
}, [windowRef, loading, error, setAlert, success]);
|
|
37
37
|
useEffect(() => {
|
|
38
|
-
if (creditCards.length) {
|
|
38
|
+
if (creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) {
|
|
39
39
|
const options = creditCards.map(i => ({
|
|
40
40
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
41
41
|
value: i.customer_card_id
|
|
@@ -43,7 +43,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
|
|
|
43
43
|
setCreditCardOptions(options);
|
|
44
44
|
const defaultCard = creditCards.length
|
|
45
45
|
? { customer_card_id: creditCards[0].customer_card_id }
|
|
46
|
-
:
|
|
46
|
+
: null;
|
|
47
47
|
setCreditCard(defaultCard);
|
|
48
48
|
setIsNewCard(false);
|
|
49
49
|
}
|
|
@@ -140,9 +140,8 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
const handleSubmit = (
|
|
143
|
+
const handleSubmit = () => {
|
|
144
144
|
var _a, _b, _c;
|
|
145
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
146
145
|
if (!name || !email) {
|
|
147
146
|
setErrors({ form: 'Both name and email are required' });
|
|
148
147
|
if (inputRef.current)
|
|
@@ -151,18 +150,21 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
|
|
|
151
150
|
}
|
|
152
151
|
else {
|
|
153
152
|
if (isNewCard) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
153
|
+
if (cardData && cardType) {
|
|
154
|
+
const { card, errors } = validateCreditCard(cardData, cardType);
|
|
155
|
+
if (errors) {
|
|
156
|
+
setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
|
|
157
|
+
setSubmitting(false);
|
|
158
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
purchaseWithCaptcha(card);
|
|
162
|
+
}
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
else {
|
|
165
|
-
|
|
166
|
+
if (creditCard)
|
|
167
|
+
purchaseWithCaptcha(creditCard);
|
|
166
168
|
}
|
|
167
169
|
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
168
170
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CardType, CreditCardData,
|
|
1
|
+
import { CardType, CreditCardData, CreditCardValidate } from '@open-tender/types';
|
|
2
2
|
export declare const cardNames: {
|
|
3
3
|
VISA: string;
|
|
4
4
|
MC: string;
|
|
@@ -17,4 +17,4 @@ export declare const makeNumeric: (str: string) => string;
|
|
|
17
17
|
export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
|
|
18
18
|
export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
|
|
19
19
|
export declare const formatCard: (card: CreditCardData) => [CreditCardData | null, CardType | null];
|
|
20
|
-
export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) =>
|
|
20
|
+
export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => CreditCardValidate;
|
package/dist/esm/utils/cards.js
CHANGED
|
@@ -137,8 +137,8 @@ export const validateCreditCard = (card, cardType) => {
|
|
|
137
137
|
errors.zip = 'Zip code must be only numbers';
|
|
138
138
|
}
|
|
139
139
|
if (!isEmpty(errors)) {
|
|
140
|
-
return { card, errors };
|
|
140
|
+
return { card, cardType, errors };
|
|
141
141
|
}
|
|
142
142
|
card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
|
|
143
|
-
return { card, errors: null };
|
|
143
|
+
return { card, cardType, errors: null };
|
|
144
144
|
};
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
|
|
3
3
|
export declare const makeModifierNames: (item: CartItem) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
@@ -47,7 +47,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
47
47
|
}[];
|
|
48
48
|
cartCounts: Record<string, number>;
|
|
49
49
|
};
|
|
50
|
-
export declare const rehydrateCheckoutForm: (order:
|
|
50
|
+
export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
51
51
|
details: {
|
|
52
52
|
cart_id: number | null | undefined;
|
|
53
53
|
eating_utensils: boolean | undefined;
|
|
@@ -56,18 +56,33 @@ export declare const rehydrateCheckoutForm: (order: Partial<Order>) => {
|
|
|
56
56
|
serving_utensils: boolean | undefined;
|
|
57
57
|
tax_exempt_id: string | null | undefined;
|
|
58
58
|
};
|
|
59
|
-
customer:
|
|
60
|
-
address:
|
|
61
|
-
surcharges:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
customer: CheckoutFormCustomer;
|
|
60
|
+
address: CheckoutFormAddress;
|
|
61
|
+
surcharges: OrderCreateSurcharges;
|
|
62
|
+
discounts: OrderCreateDiscounts;
|
|
63
|
+
promoCodes: CheckoutPromoCodes;
|
|
64
|
+
tenders: (import("@open-tender/types").OrderTenderGiftCard | {
|
|
65
|
+
card_type: import("@open-tender/types").CardType;
|
|
66
|
+
card_type_name: import("@open-tender/types").CardTypeName;
|
|
67
|
+
customer_card_id: number;
|
|
68
|
+
has_profile?: boolean | undefined;
|
|
69
|
+
is_default?: boolean | undefined;
|
|
70
|
+
last4: string;
|
|
71
|
+
masked: string;
|
|
72
|
+
amount: `${number}.${number}`;
|
|
73
|
+
credit_card: import("@open-tender/types").CreditCard;
|
|
74
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
75
|
+
} | {
|
|
76
|
+
house_account_id: number;
|
|
77
|
+
name: string;
|
|
78
|
+
amount: `${number}.${number}`;
|
|
79
|
+
house_account: {
|
|
80
|
+
house_account_id: number;
|
|
81
|
+
name: string;
|
|
82
|
+
};
|
|
83
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
84
|
+
})[] | undefined;
|
|
85
|
+
tip: `${number}.${number}`;
|
|
71
86
|
};
|
|
72
87
|
export declare const makeGuestLookup: (cartGuests: GroupOrderGuests) => Record<string, GroupOrderGuest>;
|
|
73
88
|
export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner: CartOwner, cartGuests: GroupOrderGuests) => ({
|
|
@@ -113,7 +128,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
|
|
|
113
128
|
cart_guest_id?: number | undefined;
|
|
114
129
|
customer_id?: number | undefined;
|
|
115
130
|
})[];
|
|
116
|
-
export declare const makeItemImageUrl: (images:
|
|
131
|
+
export declare const makeItemImageUrl: (images: Images) => any;
|
|
117
132
|
export declare const makeDisplayItemGroups: (optionGroups: OrderItemGroups) => {
|
|
118
133
|
options: DisplayItem[];
|
|
119
134
|
id: number;
|
|
@@ -163,13 +178,6 @@ export declare const makeSimpleCart: <C extends {
|
|
|
163
178
|
made_for: string;
|
|
164
179
|
notes: string;
|
|
165
180
|
}[];
|
|
166
|
-
export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
|
|
167
|
-
id: number;
|
|
168
|
-
quantity: number;
|
|
169
|
-
groups: SimpleCartGroups;
|
|
170
|
-
made_for: string;
|
|
171
|
-
notes: string;
|
|
172
|
-
}[];
|
|
173
181
|
export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
|
|
174
182
|
newCart: (CartItem | CartItemOption | null)[];
|
|
175
183
|
errors: {
|
|
@@ -178,5 +186,5 @@ export declare const validateCart: (cart: Cart, categories: MenuCategories, sold
|
|
|
178
186
|
} | null;
|
|
179
187
|
};
|
|
180
188
|
export declare const getDefaultTip: (config: CheckoutConfig) => string | null;
|
|
181
|
-
export declare const prepareOrder: (data:
|
|
182
|
-
export declare const checkAmountRemaining: (total: Money, tenders:
|
|
189
|
+
export declare const prepareOrder: (data: OrderData) => OrderCreate;
|
|
190
|
+
export declare const checkAmountRemaining: (total: Money, tenders: CheckoutTenders) => number;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isCreditTender, isHouseAccountTender, isOrderCustomer } from '@open-tender/types';
|
|
1
2
|
import { convertStringToArray } from './helpers';
|
|
2
3
|
// TODO: refactor for nested mods
|
|
3
4
|
export const getItemOptions = (item) => {
|
|
@@ -139,6 +140,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
139
140
|
return [];
|
|
140
141
|
const groups = optionGroups.map(g => {
|
|
141
142
|
const options = g.option_items.map(o => {
|
|
143
|
+
var _a;
|
|
142
144
|
const isSoldOut = checkSoldOut(o.id, o.suspend_until, soldOut);
|
|
143
145
|
const quantity = isSoldOut
|
|
144
146
|
? 0
|
|
@@ -146,7 +148,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
146
148
|
? o.min_quantity || 1
|
|
147
149
|
: 0;
|
|
148
150
|
const cals = o.nutritional_info
|
|
149
|
-
? parseInt(o.nutritional_info.calories.toString())
|
|
151
|
+
? parseInt((_a = o.nutritional_info.calories) === null || _a === void 0 ? void 0 : _a.toString())
|
|
150
152
|
: null;
|
|
151
153
|
const groups = makeOrderItemGroups(o.option_groups, isEdit, soldOut);
|
|
152
154
|
const option = {
|
|
@@ -306,17 +308,14 @@ const rehydrateDetails = (details) => {
|
|
|
306
308
|
};
|
|
307
309
|
// TODO: maybe refactor
|
|
308
310
|
const rehydrateCustomer = (customer) => {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
return {
|
|
312
|
+
customer_id: customer.customer_id,
|
|
313
|
+
first_name: customer.first_name,
|
|
314
|
+
last_name: customer.last_name,
|
|
315
|
+
email: customer.email,
|
|
316
|
+
phone: customer.phone,
|
|
317
|
+
company: customer.company || ''
|
|
315
318
|
};
|
|
316
|
-
if (customer === null || customer === void 0 ? void 0 : customer.customer_id) {
|
|
317
|
-
newCustomer.customer_id = customer.customer_id;
|
|
318
|
-
}
|
|
319
|
-
return newCustomer;
|
|
320
319
|
};
|
|
321
320
|
// TODO: maybe refactor
|
|
322
321
|
const rehydrateAddress = (address) => {
|
|
@@ -329,26 +328,21 @@ const rehydrateAddress = (address) => {
|
|
|
329
328
|
phone: address.phone
|
|
330
329
|
};
|
|
331
330
|
};
|
|
332
|
-
// TODO: maybe refactor
|
|
333
331
|
const rehydrateSurcharges = (surcharges) => {
|
|
334
|
-
return surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.
|
|
332
|
+
return (surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.id }))) || [];
|
|
335
333
|
};
|
|
336
|
-
// TODO: maybe refactor
|
|
337
334
|
const rehydrateDiscounts = (discounts) => {
|
|
338
|
-
return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.
|
|
335
|
+
return ((discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.id, ext_id: i.ext_id }))) || []);
|
|
339
336
|
};
|
|
340
|
-
// TODO: maybe refactor
|
|
341
337
|
const rehydratePromoCodes = (discounts) => {
|
|
342
|
-
return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name);
|
|
338
|
+
return (discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name)) || [];
|
|
343
339
|
};
|
|
344
|
-
// TODO: maybe refactor
|
|
345
340
|
const rehydrateTenders = (tenders) => {
|
|
346
|
-
// const giftCards = tenders.filter((i) => i.tender_type === 'GIFT_CARD')
|
|
347
341
|
const other = tenders === null || tenders === void 0 ? void 0 : tenders.map(i => {
|
|
348
|
-
if (i
|
|
342
|
+
if (isCreditTender(i)) {
|
|
349
343
|
return Object.assign(Object.assign({}, i), i.credit_card);
|
|
350
344
|
}
|
|
351
|
-
else if (i
|
|
345
|
+
else if (isHouseAccountTender(i)) {
|
|
352
346
|
return Object.assign(Object.assign({}, i), i.house_account);
|
|
353
347
|
}
|
|
354
348
|
else {
|
|
@@ -357,18 +351,18 @@ const rehydrateTenders = (tenders) => {
|
|
|
357
351
|
});
|
|
358
352
|
return other;
|
|
359
353
|
};
|
|
360
|
-
// TODO: maybe refactor
|
|
361
354
|
export const rehydrateCheckoutForm = (order) => {
|
|
362
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
363
355
|
const form = {
|
|
364
|
-
details: rehydrateDetails(
|
|
365
|
-
customer:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
356
|
+
details: rehydrateDetails(order.details),
|
|
357
|
+
customer: isOrderCustomer(order.customer)
|
|
358
|
+
? rehydrateCustomer(order.customer)
|
|
359
|
+
: {},
|
|
360
|
+
address: rehydrateAddress(order.address),
|
|
361
|
+
surcharges: rehydrateSurcharges(order.surcharges),
|
|
362
|
+
discounts: rehydrateDiscounts(order.discounts),
|
|
363
|
+
promoCodes: rehydratePromoCodes(order.discounts),
|
|
364
|
+
tenders: rehydrateTenders(order.tenders),
|
|
365
|
+
tip: order.totals.tip
|
|
372
366
|
};
|
|
373
367
|
return form;
|
|
374
368
|
};
|
|
@@ -571,54 +565,6 @@ export const makeSimpleCart = (cart) => {
|
|
|
571
565
|
});
|
|
572
566
|
return simpleCart;
|
|
573
567
|
};
|
|
574
|
-
// const makeSimpleGroups = (groups: CartItemGroups): SimpleCartGroups => {
|
|
575
|
-
// return groups.map(g => {
|
|
576
|
-
// const options = g.options
|
|
577
|
-
// .filter(o => o.quantity !== 0)
|
|
578
|
-
// .map(o => ({
|
|
579
|
-
// id: o.id,
|
|
580
|
-
// quantity: o.quantity,
|
|
581
|
-
// groups: makeSimpleGroups(o.groups || [])
|
|
582
|
-
// }))
|
|
583
|
-
// return { id: g.id, options: options }
|
|
584
|
-
// })
|
|
585
|
-
// }
|
|
586
|
-
// export const makeSimpleCart = (cart: Cart) => {
|
|
587
|
-
// const simpleCart = cart.map(i => {
|
|
588
|
-
// return {
|
|
589
|
-
// id: i.id,
|
|
590
|
-
// quantity: i.quantity,
|
|
591
|
-
// groups: makeSimpleGroups(i.groups),
|
|
592
|
-
// made_for: i.madeFor || '',
|
|
593
|
-
// notes: i.notes || ''
|
|
594
|
-
// }
|
|
595
|
-
// })
|
|
596
|
-
// return simpleCart
|
|
597
|
-
// }
|
|
598
|
-
const makeSimpleGroupsFromOrder = (groups) => {
|
|
599
|
-
return groups.map(g => {
|
|
600
|
-
const options = g.options
|
|
601
|
-
.filter(o => o.quantity !== 0)
|
|
602
|
-
.map(o => ({
|
|
603
|
-
id: o.id,
|
|
604
|
-
quantity: o.quantity,
|
|
605
|
-
groups: makeSimpleGroupsFromOrder(o.groups || [])
|
|
606
|
-
}));
|
|
607
|
-
return { id: g.id, options: options };
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
export const makeSimpleCartFromOrder = (cart) => {
|
|
611
|
-
const simpleCart = cart.map(i => {
|
|
612
|
-
return {
|
|
613
|
-
id: i.id,
|
|
614
|
-
quantity: i.quantity,
|
|
615
|
-
groups: makeSimpleGroupsFromOrder(i.groups),
|
|
616
|
-
made_for: i.made_for || '',
|
|
617
|
-
notes: i.notes || ''
|
|
618
|
-
};
|
|
619
|
-
});
|
|
620
|
-
return simpleCart;
|
|
621
|
-
};
|
|
622
568
|
/* cart validation */
|
|
623
569
|
// TODO: refactor for nested modifiers
|
|
624
570
|
// convert menu items to order items for validation but only include
|
|
@@ -771,13 +717,11 @@ export const getDefaultTip = (config) => {
|
|
|
771
717
|
return config.gratuity.default ? config.gratuity.default.amount : null;
|
|
772
718
|
};
|
|
773
719
|
export const prepareOrder = (data) => {
|
|
774
|
-
data = data || {};
|
|
775
|
-
const requestedIso = !data.requestedAt ? 'asap' : data.requestedAt;
|
|
776
720
|
const order = {
|
|
777
|
-
revenue_center_id: data.revenueCenterId
|
|
778
|
-
service_type: data.serviceType
|
|
779
|
-
requested_at:
|
|
780
|
-
cart:
|
|
721
|
+
revenue_center_id: data.revenueCenterId,
|
|
722
|
+
service_type: data.serviceType,
|
|
723
|
+
requested_at: data.requestedAt,
|
|
724
|
+
cart: makeSimpleCart(data.cart)
|
|
781
725
|
};
|
|
782
726
|
if (data.customer)
|
|
783
727
|
order.customer = data.customer;
|