@open-tender/utils 0.4.85 → 0.4.87
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 +1 -1
- package/dist/cjs/hooks/useCreditCard.js +24 -18
- package/dist/cjs/hooks/useMenuItem.d.ts +0 -1
- package/dist/cjs/hooks/useModifier.d.ts +0 -1
- package/dist/cjs/hooks/useOrderItem.d.ts +0 -1
- package/dist/cjs/utils/cards.js +3 -1
- package/dist/cjs/utils/cart.d.ts +0 -2
- package/dist/cjs/utils/cart.js +2 -0
- package/dist/cjs/utils/menu.d.ts +0 -2
- package/dist/cjs/utils/revenueCenters.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +1 -1
- package/dist/esm/hooks/useCreditCard.js +24 -18
- package/dist/esm/hooks/useMenuItem.d.ts +0 -1
- package/dist/esm/hooks/useModifier.d.ts +0 -1
- package/dist/esm/hooks/useOrderItem.d.ts +0 -1
- package/dist/esm/utils/cards.js +3 -1
- package/dist/esm/utils/cart.d.ts +0 -2
- package/dist/esm/utils/cart.js +2 -0
- package/dist/esm/utils/menu.d.ts +0 -2
- package/dist/esm/utils/revenueCenters.js +1 -1
- package/package.json +3 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CreditCardData, CreditCardErrors } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean) => {
|
|
3
|
+
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean, requireCardholderName?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<null>;
|
|
5
5
|
data: CreditCardData;
|
|
6
6
|
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
@@ -3,31 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useCreditCard = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const index_1 = require("../index");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
is_default: false
|
|
6
|
+
const getDefaultCard = (includeAddress, requireCardholderName) => {
|
|
7
|
+
const defaultCardData = {
|
|
8
|
+
acct: '',
|
|
9
|
+
exp: '',
|
|
10
|
+
cvv: '',
|
|
11
|
+
zip: '',
|
|
12
|
+
is_default: false
|
|
13
|
+
};
|
|
14
|
+
if (includeAddress)
|
|
15
|
+
defaultCardData.addr = '';
|
|
16
|
+
if (requireCardholderName)
|
|
17
|
+
defaultCardData.cardholder_name = '';
|
|
18
|
+
return defaultCardData;
|
|
20
19
|
};
|
|
21
|
-
const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddress = false) => {
|
|
20
|
+
const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddress = false, requireCardholderName = false) => {
|
|
22
21
|
const [initCard, initCardType] = (0, index_1.formatCard)(initState);
|
|
23
22
|
const submitRef = (0, react_1.useRef)(null);
|
|
24
|
-
const defaultCard = includeAddress
|
|
23
|
+
const defaultCard = getDefaultCard(includeAddress, requireCardholderName);
|
|
25
24
|
const [data, setData] = (0, react_1.useState)(initCard || defaultCard);
|
|
26
25
|
const [cardType, setCardType] = (0, react_1.useState)(initCardType || 'OTHER');
|
|
27
26
|
const [errors, setErrors] = (0, react_1.useState)(cardErrors);
|
|
28
|
-
const { acct, addr, exp, cvv, zip } = data;
|
|
27
|
+
const { acct, addr, exp, cvv, zip, cardholder_name } = data;
|
|
29
28
|
const addrComplete = includeAddress ? addr : true;
|
|
30
|
-
const
|
|
29
|
+
const cardholderNameComplete = requireCardholderName ? cardholder_name : true;
|
|
30
|
+
const isComplete = !!(acct &&
|
|
31
|
+
exp &&
|
|
32
|
+
cvv &&
|
|
33
|
+
zip &&
|
|
34
|
+
addrComplete &&
|
|
35
|
+
cardholderNameComplete &&
|
|
36
|
+
(0, index_1.isEmpty)(errors));
|
|
31
37
|
const handleChange = (name, value) => {
|
|
32
38
|
if (name === 'acct') {
|
|
33
39
|
const currentType = (0, index_1.getCardType)(value.replace(/\s/g, ''));
|
|
@@ -48,7 +48,6 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
|
|
|
48
48
|
name: string;
|
|
49
49
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
50
50
|
points: number | null;
|
|
51
|
-
pos_ext_id: string | null;
|
|
52
51
|
price: number;
|
|
53
52
|
quantity: number;
|
|
54
53
|
shorthand: string | null;
|
|
@@ -40,7 +40,6 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
|
|
|
40
40
|
name: string;
|
|
41
41
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
42
42
|
points: number | null;
|
|
43
|
-
pos_ext_id: string | null;
|
|
44
43
|
quantity: number;
|
|
45
44
|
shorthand: string | null;
|
|
46
45
|
shortDescription: string | null;
|
|
@@ -37,7 +37,6 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavo
|
|
|
37
37
|
name: string;
|
|
38
38
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
39
39
|
points: number | null;
|
|
40
|
-
pos_ext_id: string | null;
|
|
41
40
|
price: number;
|
|
42
41
|
quantity: number;
|
|
43
42
|
shorthand: string | null;
|
package/dist/cjs/utils/cards.js
CHANGED
|
@@ -70,7 +70,7 @@ const makeAcctNumber = (str, cardType) => {
|
|
|
70
70
|
};
|
|
71
71
|
exports.makeAcctNumber = makeAcctNumber;
|
|
72
72
|
const formatCardField = (field, value) => {
|
|
73
|
-
const cleanValue = field === 'addr' ? value : (0, exports.makeNumeric)(value);
|
|
73
|
+
const cleanValue = field === 'addr' || field === 'cardholder_name' ? value : (0, exports.makeNumeric)(value);
|
|
74
74
|
switch (field) {
|
|
75
75
|
case 'acct': {
|
|
76
76
|
const currentType = (0, exports.getCardType)(value.replace(/\s/g, ''));
|
|
@@ -105,6 +105,8 @@ const formatCard = (card) => {
|
|
|
105
105
|
};
|
|
106
106
|
if ('addr' in card)
|
|
107
107
|
creditCard.addr = card.addr;
|
|
108
|
+
if ('cardholder_name' in card)
|
|
109
|
+
creditCard.cardholder_name = card.cardholder_name;
|
|
108
110
|
return [creditCard, creditCardType];
|
|
109
111
|
};
|
|
110
112
|
exports.formatCard = formatCard;
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -42,7 +42,6 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
42
42
|
name: string;
|
|
43
43
|
nutritionalInfo: NutritionalInfo | null;
|
|
44
44
|
points: number | null;
|
|
45
|
-
pos_ext_id: string | null;
|
|
46
45
|
price: number;
|
|
47
46
|
quantity: number;
|
|
48
47
|
shorthand: string | null;
|
|
@@ -138,7 +137,6 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
|
|
|
138
137
|
name: string;
|
|
139
138
|
nutritionalInfo: NutritionalInfo | null;
|
|
140
139
|
points: number | null;
|
|
141
|
-
pos_ext_id: string | null;
|
|
142
140
|
price: number;
|
|
143
141
|
quantity: number;
|
|
144
142
|
shorthand: string | null;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -229,6 +229,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
229
229
|
name: o.name,
|
|
230
230
|
nutritionalInfo: o.nutritional_info,
|
|
231
231
|
points: o.points || 0,
|
|
232
|
+
// @ts-ignore
|
|
232
233
|
pos_ext_id: o.pos_ext_id,
|
|
233
234
|
price: parseFloat(o.price),
|
|
234
235
|
quantity: quantity,
|
|
@@ -294,6 +295,7 @@ const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints = false
|
|
|
294
295
|
notes: simpleItem ? simpleItem.notes || null : null,
|
|
295
296
|
nutritionalInfo: item.nutritional_info,
|
|
296
297
|
points: hasPoints ? item.points || null : null,
|
|
298
|
+
// @ts-ignore
|
|
297
299
|
pos_ext_id: item.pos_ext_id,
|
|
298
300
|
price: parseFloat(item.price),
|
|
299
301
|
quantity: item.min_quantity || 1 * item.increment,
|
package/dist/cjs/utils/menu.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ export declare const makeOtherMenuSections: (displayedSections: MenuDisplayedSec
|
|
|
35
35
|
plu: string | null;
|
|
36
36
|
points: number | null;
|
|
37
37
|
pos_display_color: string | null;
|
|
38
|
-
pos_ext_id: string | null;
|
|
39
38
|
price: string;
|
|
40
39
|
sales_tax_override: `${number}.${number}` | null;
|
|
41
40
|
short_description: string | null;
|
|
@@ -84,7 +83,6 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
|
|
|
84
83
|
plu: string | null;
|
|
85
84
|
points: number | null;
|
|
86
85
|
pos_display_color: string | null;
|
|
87
|
-
pos_ext_id: string | null;
|
|
88
86
|
price: string;
|
|
89
87
|
sales_tax_override: `${number}.${number}` | null;
|
|
90
88
|
short_description: string | null;
|
|
@@ -95,7 +95,7 @@ const makeNotAcceptingOrdersMsg = (serviceType) => {
|
|
|
95
95
|
if (!serviceTypeName) {
|
|
96
96
|
return 'This location is not currently accepting orders.';
|
|
97
97
|
}
|
|
98
|
-
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders
|
|
98
|
+
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders.`;
|
|
99
99
|
};
|
|
100
100
|
exports.makeNotAcceptingOrdersMsg = makeNotAcceptingOrdersMsg;
|
|
101
101
|
const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMessages) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CreditCardData, CreditCardErrors } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean) => {
|
|
3
|
+
export declare const useCreditCard: (initState: CreditCardData | null, cardErrors?: CreditCardErrors, disabled?: boolean, includeAddress?: boolean, requireCardholderName?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<null>;
|
|
5
5
|
data: CreditCardData;
|
|
6
6
|
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { useRef, useState } from 'react';
|
|
2
2
|
import { formatCardField, formatCard, getCardType, isEmpty, validateCreditCard } from '../index';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
is_default: false
|
|
3
|
+
const getDefaultCard = (includeAddress, requireCardholderName) => {
|
|
4
|
+
const defaultCardData = {
|
|
5
|
+
acct: '',
|
|
6
|
+
exp: '',
|
|
7
|
+
cvv: '',
|
|
8
|
+
zip: '',
|
|
9
|
+
is_default: false
|
|
10
|
+
};
|
|
11
|
+
if (includeAddress)
|
|
12
|
+
defaultCardData.addr = '';
|
|
13
|
+
if (requireCardholderName)
|
|
14
|
+
defaultCardData.cardholder_name = '';
|
|
15
|
+
return defaultCardData;
|
|
17
16
|
};
|
|
18
|
-
export const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddress = false) => {
|
|
17
|
+
export const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddress = false, requireCardholderName = false) => {
|
|
19
18
|
const [initCard, initCardType] = formatCard(initState);
|
|
20
19
|
const submitRef = useRef(null);
|
|
21
|
-
const defaultCard = includeAddress
|
|
20
|
+
const defaultCard = getDefaultCard(includeAddress, requireCardholderName);
|
|
22
21
|
const [data, setData] = useState(initCard || defaultCard);
|
|
23
22
|
const [cardType, setCardType] = useState(initCardType || 'OTHER');
|
|
24
23
|
const [errors, setErrors] = useState(cardErrors);
|
|
25
|
-
const { acct, addr, exp, cvv, zip } = data;
|
|
24
|
+
const { acct, addr, exp, cvv, zip, cardholder_name } = data;
|
|
26
25
|
const addrComplete = includeAddress ? addr : true;
|
|
27
|
-
const
|
|
26
|
+
const cardholderNameComplete = requireCardholderName ? cardholder_name : true;
|
|
27
|
+
const isComplete = !!(acct &&
|
|
28
|
+
exp &&
|
|
29
|
+
cvv &&
|
|
30
|
+
zip &&
|
|
31
|
+
addrComplete &&
|
|
32
|
+
cardholderNameComplete &&
|
|
33
|
+
isEmpty(errors));
|
|
28
34
|
const handleChange = (name, value) => {
|
|
29
35
|
if (name === 'acct') {
|
|
30
36
|
const currentType = getCardType(value.replace(/\s/g, ''));
|
|
@@ -48,7 +48,6 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
|
|
|
48
48
|
name: string;
|
|
49
49
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
50
50
|
points: number | null;
|
|
51
|
-
pos_ext_id: string | null;
|
|
52
51
|
price: number;
|
|
53
52
|
quantity: number;
|
|
54
53
|
shorthand: string | null;
|
|
@@ -40,7 +40,6 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
|
|
|
40
40
|
name: string;
|
|
41
41
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
42
42
|
points: number | null;
|
|
43
|
-
pos_ext_id: string | null;
|
|
44
43
|
quantity: number;
|
|
45
44
|
shorthand: string | null;
|
|
46
45
|
shortDescription: string | null;
|
|
@@ -37,7 +37,6 @@ export declare const useOrderItem: (orderItem: CartItem, favorite?: MenuItemFavo
|
|
|
37
37
|
name: string;
|
|
38
38
|
nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
|
|
39
39
|
points: number | null;
|
|
40
|
-
pos_ext_id: string | null;
|
|
41
40
|
price: number;
|
|
42
41
|
quantity: number;
|
|
43
42
|
shorthand: string | null;
|
package/dist/esm/utils/cards.js
CHANGED
|
@@ -64,7 +64,7 @@ export const makeAcctNumber = (str, cardType) => {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
export const formatCardField = (field, value) => {
|
|
67
|
-
const cleanValue = field === 'addr' ? value : makeNumeric(value);
|
|
67
|
+
const cleanValue = field === 'addr' || field === 'cardholder_name' ? value : makeNumeric(value);
|
|
68
68
|
switch (field) {
|
|
69
69
|
case 'acct': {
|
|
70
70
|
const currentType = getCardType(value.replace(/\s/g, ''));
|
|
@@ -98,6 +98,8 @@ export const formatCard = (card) => {
|
|
|
98
98
|
};
|
|
99
99
|
if ('addr' in card)
|
|
100
100
|
creditCard.addr = card.addr;
|
|
101
|
+
if ('cardholder_name' in card)
|
|
102
|
+
creditCard.cardholder_name = card.cardholder_name;
|
|
101
103
|
return [creditCard, creditCardType];
|
|
102
104
|
};
|
|
103
105
|
export const validateCreditCard = (card, cardType) => {
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -42,7 +42,6 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
42
42
|
name: string;
|
|
43
43
|
nutritionalInfo: NutritionalInfo | null;
|
|
44
44
|
points: number | null;
|
|
45
|
-
pos_ext_id: string | null;
|
|
46
45
|
price: number;
|
|
47
46
|
quantity: number;
|
|
48
47
|
shorthand: string | null;
|
|
@@ -138,7 +137,6 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
|
|
|
138
137
|
name: string;
|
|
139
138
|
nutritionalInfo: NutritionalInfo | null;
|
|
140
139
|
points: number | null;
|
|
141
|
-
pos_ext_id: string | null;
|
|
142
140
|
price: number;
|
|
143
141
|
quantity: number;
|
|
144
142
|
shorthand: string | null;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -214,6 +214,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
214
214
|
name: o.name,
|
|
215
215
|
nutritionalInfo: o.nutritional_info,
|
|
216
216
|
points: o.points || 0,
|
|
217
|
+
// @ts-ignore
|
|
217
218
|
pos_ext_id: o.pos_ext_id,
|
|
218
219
|
price: parseFloat(o.price),
|
|
219
220
|
quantity: quantity,
|
|
@@ -279,6 +280,7 @@ export const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints
|
|
|
279
280
|
notes: simpleItem ? simpleItem.notes || null : null,
|
|
280
281
|
nutritionalInfo: item.nutritional_info,
|
|
281
282
|
points: hasPoints ? item.points || null : null,
|
|
283
|
+
// @ts-ignore
|
|
282
284
|
pos_ext_id: item.pos_ext_id,
|
|
283
285
|
price: parseFloat(item.price),
|
|
284
286
|
quantity: item.min_quantity || 1 * item.increment,
|
package/dist/esm/utils/menu.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ export declare const makeOtherMenuSections: (displayedSections: MenuDisplayedSec
|
|
|
35
35
|
plu: string | null;
|
|
36
36
|
points: number | null;
|
|
37
37
|
pos_display_color: string | null;
|
|
38
|
-
pos_ext_id: string | null;
|
|
39
38
|
price: string;
|
|
40
39
|
sales_tax_override: `${number}.${number}` | null;
|
|
41
40
|
short_description: string | null;
|
|
@@ -84,7 +83,6 @@ export declare const makeFlatCategories: (categories: MenuCategories) => {
|
|
|
84
83
|
plu: string | null;
|
|
85
84
|
points: number | null;
|
|
86
85
|
pos_display_color: string | null;
|
|
87
|
-
pos_ext_id: string | null;
|
|
88
86
|
price: string;
|
|
89
87
|
sales_tax_override: `${number}.${number}` | null;
|
|
90
88
|
short_description: string | null;
|
|
@@ -87,7 +87,7 @@ export const makeNotAcceptingOrdersMsg = (serviceType) => {
|
|
|
87
87
|
if (!serviceTypeName) {
|
|
88
88
|
return 'This location is not currently accepting orders.';
|
|
89
89
|
}
|
|
90
|
-
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders
|
|
90
|
+
return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders.`;
|
|
91
91
|
};
|
|
92
92
|
export const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMessages) => {
|
|
93
93
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.87",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
+
"@open-tender/types": "^0.4.126",
|
|
39
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
40
41
|
"@types/google.maps": "^3.53.5",
|
|
41
42
|
"@types/jest": "^29.5.11",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"typescript": "^4.8.2"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
|
-
"@open-tender/types": "^0.4.
|
|
61
|
+
"@open-tender/types": "^0.4.124",
|
|
61
62
|
"@reduxjs/toolkit": "^1.8.5",
|
|
62
63
|
"react": "^18.2.0"
|
|
63
64
|
},
|