@open-tender/utils 0.3.10 → 0.4.1
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/.DS_Store +0 -0
- package/dist/cjs/hooks/useSignUpGuestForm.js +3 -2
- package/dist/cjs/utils/cart.d.ts +2 -0
- package/dist/cjs/utils/checkout.d.ts +8 -3
- package/dist/cjs/utils/rewards.d.ts +1 -19
- package/dist/cjs/utils/rewards.js +1 -34
- package/dist/esm/hooks/useSignUpGuestForm.js +3 -2
- package/dist/esm/utils/cart.d.ts +2 -0
- package/dist/esm/utils/checkout.d.ts +8 -3
- package/dist/esm/utils/rewards.d.ts +1 -19
- package/dist/esm/utils/rewards.js +0 -31
- package/package.json +2 -2
package/dist/.DS_Store
CHANGED
|
Binary file
|
|
@@ -46,7 +46,6 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
46
46
|
label: 'Password',
|
|
47
47
|
name: 'password',
|
|
48
48
|
type: 'password',
|
|
49
|
-
required: true,
|
|
50
49
|
autoComplete: 'new-password'
|
|
51
50
|
}
|
|
52
51
|
];
|
|
@@ -80,7 +79,9 @@ const useSignUpGuestForm = (email, guest, loading, error, guestErrors, signUp, s
|
|
|
80
79
|
setSubmitting(false);
|
|
81
80
|
if (error) {
|
|
82
81
|
const errs = (0, utils_1.makeFormErrors)(error);
|
|
83
|
-
errs.form
|
|
82
|
+
if (errs.form.includes('parameters')) {
|
|
83
|
+
errs.form = 'There are one or more errors below';
|
|
84
|
+
}
|
|
84
85
|
setErrors(errs);
|
|
85
86
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
86
87
|
}
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
|
71
71
|
masked: string;
|
|
72
72
|
amount: `${number}.${number}`;
|
|
73
73
|
credit_card: import("@open-tender/types").CreditCard;
|
|
74
|
+
tender_status: import("@open-tender/types").TenderStatus;
|
|
74
75
|
tender_type: import("@open-tender/types").TenderType;
|
|
75
76
|
} | {
|
|
76
77
|
house_account_id: number;
|
|
@@ -80,6 +81,7 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
|
80
81
|
house_account_id: number;
|
|
81
82
|
name: string;
|
|
82
83
|
};
|
|
84
|
+
tender_status: import("@open-tender/types").TenderStatus;
|
|
83
85
|
tender_type: import("@open-tender/types").TenderType;
|
|
84
86
|
})[] | undefined;
|
|
85
87
|
tip: `${number}.${number}`;
|
|
@@ -5,27 +5,30 @@ export declare const adjustTenders: (tenders: CheckoutTenders, isPaid: boolean,
|
|
|
5
5
|
export declare const updateTenders: (tenders: CheckoutTenders, total: Money) => ({
|
|
6
6
|
amount: string;
|
|
7
7
|
acct: string;
|
|
8
|
-
cvv: string;
|
|
9
8
|
card_type_name: import("@open-tender/types").CardTypeName;
|
|
9
|
+
cvv: string;
|
|
10
10
|
exp: string;
|
|
11
11
|
is_default: boolean;
|
|
12
12
|
last4: string;
|
|
13
13
|
masked: string;
|
|
14
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
14
15
|
tender_type: import("@open-tender/types").TenderType;
|
|
15
16
|
zip: string;
|
|
16
17
|
} | {
|
|
17
18
|
amount: string;
|
|
18
|
-
tender_type: import("@open-tender/types").TenderType;
|
|
19
19
|
card_type: import("@open-tender/types").CardType;
|
|
20
20
|
card_type_name: import("@open-tender/types").CardTypeName;
|
|
21
21
|
customer_card_id: number;
|
|
22
|
+
is_default: boolean;
|
|
22
23
|
last4: string;
|
|
23
24
|
masked: string;
|
|
24
|
-
|
|
25
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
26
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
25
27
|
} | {
|
|
26
28
|
amount: string;
|
|
27
29
|
balance?: `${number}.${number}` | undefined;
|
|
28
30
|
card_number: string;
|
|
31
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
29
32
|
tender_type: import("@open-tender/types").TenderType;
|
|
30
33
|
} | {
|
|
31
34
|
amount: string;
|
|
@@ -37,9 +40,11 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
37
40
|
pin?: string | undefined;
|
|
38
41
|
revenue_centers?: number[] | undefined;
|
|
39
42
|
service_type?: import("@open-tender/types").ServiceType | null | undefined;
|
|
43
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
40
44
|
tender_type?: import("@open-tender/types").TenderType | undefined;
|
|
41
45
|
} | {
|
|
42
46
|
amount: string;
|
|
47
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
43
48
|
tender_type: import("@open-tender/types").TenderType;
|
|
44
49
|
token: any;
|
|
45
50
|
})[] | null;
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import { Discounts,
|
|
1
|
+
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
-
export declare const makeStatus: (tiers: LoyaltyTier[], status: LoyaltyStatus, points: LoyaltyPoints) => {
|
|
4
|
-
progress: number;
|
|
5
|
-
progressMsg: string;
|
|
6
|
-
tiers: {
|
|
7
|
-
points: LoyaltyPoints;
|
|
8
|
-
percentage: number;
|
|
9
|
-
color: string;
|
|
10
|
-
value: string;
|
|
11
|
-
description: string;
|
|
12
|
-
discount: import("@open-tender/types").LoyaltyDiscount | null;
|
|
13
|
-
hex_code: string;
|
|
14
|
-
is_current_tier: true;
|
|
15
|
-
name: string;
|
|
16
|
-
threshold: string;
|
|
17
|
-
tier_no: number;
|
|
18
|
-
}[];
|
|
19
|
-
} | null;
|
|
20
|
-
export declare const makeProgress: (loyalty_type: LoyaltyType, spend: LoyaltySpend, redemption: LoyaltyRedemption) => number | null;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const helpers_1 = require("./helpers");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
3
|
+
exports.makeValidDeals = void 0;
|
|
6
4
|
const datetimes_1 = require("./datetimes");
|
|
7
5
|
const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
8
6
|
if (!deals || !deals.length)
|
|
@@ -36,34 +34,3 @@ const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
|
36
34
|
return deals;
|
|
37
35
|
};
|
|
38
36
|
exports.makeValidDeals = makeValidDeals;
|
|
39
|
-
const makeStatus = (tiers, status, points) => {
|
|
40
|
-
if (!tiers)
|
|
41
|
-
return null;
|
|
42
|
-
const highest = parseFloat(tiers[tiers.length - 1].threshold);
|
|
43
|
-
const total = highest * 1.2;
|
|
44
|
-
const progress = Math.min((parseFloat(status.progress) / total) * 100, 100);
|
|
45
|
-
const progressTiers = tiers.map(i => (Object.assign(Object.assign({}, i), { points, percentage: (parseFloat(i.threshold) / total) * 100, color: `#${i.hex_code}`, value: !points
|
|
46
|
-
? `${(0, helpers_1.formatDollars)(i.threshold, '', 0)}`
|
|
47
|
-
: `${(0, helpers_1.formatQuantity)(i.threshold)}` })));
|
|
48
|
-
const daysMsg = status.days === 7300 ? 'all-time' : `last ${status.days} days`;
|
|
49
|
-
const progressAmt = !points
|
|
50
|
-
? (0, helpers_1.formatDollars)(status.progress, '', 0)
|
|
51
|
-
: (0, helpers_1.formatQuantity)(status.progress);
|
|
52
|
-
const progressMsg = !points
|
|
53
|
-
? `${progressAmt} spent ${daysMsg}`
|
|
54
|
-
: `${progressAmt} ${points.name.toLowerCase()} earned ${daysMsg}`;
|
|
55
|
-
return { progress, progressMsg, tiers: progressTiers };
|
|
56
|
-
};
|
|
57
|
-
exports.makeStatus = makeStatus;
|
|
58
|
-
const makeProgress = (loyalty_type, spend, redemption) => {
|
|
59
|
-
var _a;
|
|
60
|
-
if (!spend || !redemption || !loyalty_type)
|
|
61
|
-
return null;
|
|
62
|
-
const currentSpend = parseFloat((_a = spend.current) !== null && _a !== void 0 ? _a : '0');
|
|
63
|
-
const threshold = parseFloat(redemption.threshold);
|
|
64
|
-
const progress = loyalty_type === constants_1.loyaltyType.CREDIT
|
|
65
|
-
? (currentSpend / threshold) * 100
|
|
66
|
-
: null;
|
|
67
|
-
return progress;
|
|
68
|
-
};
|
|
69
|
-
exports.makeProgress = makeProgress;
|
|
@@ -43,7 +43,6 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
43
43
|
label: 'Password',
|
|
44
44
|
name: 'password',
|
|
45
45
|
type: 'password',
|
|
46
|
-
required: true,
|
|
47
46
|
autoComplete: 'new-password'
|
|
48
47
|
}
|
|
49
48
|
];
|
|
@@ -77,7 +76,9 @@ export const useSignUpGuestForm = (email, guest, loading, error, guestErrors, si
|
|
|
77
76
|
setSubmitting(false);
|
|
78
77
|
if (error) {
|
|
79
78
|
const errs = makeFormErrors(error);
|
|
80
|
-
errs.form
|
|
79
|
+
if (errs.form.includes('parameters')) {
|
|
80
|
+
errs.form = 'There are one or more errors below';
|
|
81
|
+
}
|
|
81
82
|
setErrors(errs);
|
|
82
83
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
83
84
|
}
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
|
71
71
|
masked: string;
|
|
72
72
|
amount: `${number}.${number}`;
|
|
73
73
|
credit_card: import("@open-tender/types").CreditCard;
|
|
74
|
+
tender_status: import("@open-tender/types").TenderStatus;
|
|
74
75
|
tender_type: import("@open-tender/types").TenderType;
|
|
75
76
|
} | {
|
|
76
77
|
house_account_id: number;
|
|
@@ -80,6 +81,7 @@ export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
|
80
81
|
house_account_id: number;
|
|
81
82
|
name: string;
|
|
82
83
|
};
|
|
84
|
+
tender_status: import("@open-tender/types").TenderStatus;
|
|
83
85
|
tender_type: import("@open-tender/types").TenderType;
|
|
84
86
|
})[] | undefined;
|
|
85
87
|
tip: `${number}.${number}`;
|
|
@@ -5,27 +5,30 @@ export declare const adjustTenders: (tenders: CheckoutTenders, isPaid: boolean,
|
|
|
5
5
|
export declare const updateTenders: (tenders: CheckoutTenders, total: Money) => ({
|
|
6
6
|
amount: string;
|
|
7
7
|
acct: string;
|
|
8
|
-
cvv: string;
|
|
9
8
|
card_type_name: import("@open-tender/types").CardTypeName;
|
|
9
|
+
cvv: string;
|
|
10
10
|
exp: string;
|
|
11
11
|
is_default: boolean;
|
|
12
12
|
last4: string;
|
|
13
13
|
masked: string;
|
|
14
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
14
15
|
tender_type: import("@open-tender/types").TenderType;
|
|
15
16
|
zip: string;
|
|
16
17
|
} | {
|
|
17
18
|
amount: string;
|
|
18
|
-
tender_type: import("@open-tender/types").TenderType;
|
|
19
19
|
card_type: import("@open-tender/types").CardType;
|
|
20
20
|
card_type_name: import("@open-tender/types").CardTypeName;
|
|
21
21
|
customer_card_id: number;
|
|
22
|
+
is_default: boolean;
|
|
22
23
|
last4: string;
|
|
23
24
|
masked: string;
|
|
24
|
-
|
|
25
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
26
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
25
27
|
} | {
|
|
26
28
|
amount: string;
|
|
27
29
|
balance?: `${number}.${number}` | undefined;
|
|
28
30
|
card_number: string;
|
|
31
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
29
32
|
tender_type: import("@open-tender/types").TenderType;
|
|
30
33
|
} | {
|
|
31
34
|
amount: string;
|
|
@@ -37,9 +40,11 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
37
40
|
pin?: string | undefined;
|
|
38
41
|
revenue_centers?: number[] | undefined;
|
|
39
42
|
service_type?: import("@open-tender/types").ServiceType | null | undefined;
|
|
43
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
40
44
|
tender_type?: import("@open-tender/types").TenderType | undefined;
|
|
41
45
|
} | {
|
|
42
46
|
amount: string;
|
|
47
|
+
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
43
48
|
tender_type: import("@open-tender/types").TenderType;
|
|
44
49
|
token: any;
|
|
45
50
|
})[] | null;
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import { Discounts,
|
|
1
|
+
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
-
export declare const makeStatus: (tiers: LoyaltyTier[], status: LoyaltyStatus, points: LoyaltyPoints) => {
|
|
4
|
-
progress: number;
|
|
5
|
-
progressMsg: string;
|
|
6
|
-
tiers: {
|
|
7
|
-
points: LoyaltyPoints;
|
|
8
|
-
percentage: number;
|
|
9
|
-
color: string;
|
|
10
|
-
value: string;
|
|
11
|
-
description: string;
|
|
12
|
-
discount: import("@open-tender/types").LoyaltyDiscount | null;
|
|
13
|
-
hex_code: string;
|
|
14
|
-
is_current_tier: true;
|
|
15
|
-
name: string;
|
|
16
|
-
threshold: string;
|
|
17
|
-
tier_no: number;
|
|
18
|
-
}[];
|
|
19
|
-
} | null;
|
|
20
|
-
export declare const makeProgress: (loyalty_type: LoyaltyType, spend: LoyaltySpend, redemption: LoyaltyRedemption) => number | null;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { formatDollars, formatQuantity } from './helpers';
|
|
2
|
-
import { loyaltyType } from './constants';
|
|
3
1
|
import { getMinutesfromDate, time24ToMinutes } from './datetimes';
|
|
4
2
|
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
5
3
|
if (!deals || !deals.length)
|
|
@@ -32,32 +30,3 @@ export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) =
|
|
|
32
30
|
});
|
|
33
31
|
return deals;
|
|
34
32
|
};
|
|
35
|
-
export const makeStatus = (tiers, status, points) => {
|
|
36
|
-
if (!tiers)
|
|
37
|
-
return null;
|
|
38
|
-
const highest = parseFloat(tiers[tiers.length - 1].threshold);
|
|
39
|
-
const total = highest * 1.2;
|
|
40
|
-
const progress = Math.min((parseFloat(status.progress) / total) * 100, 100);
|
|
41
|
-
const progressTiers = tiers.map(i => (Object.assign(Object.assign({}, i), { points, percentage: (parseFloat(i.threshold) / total) * 100, color: `#${i.hex_code}`, value: !points
|
|
42
|
-
? `${formatDollars(i.threshold, '', 0)}`
|
|
43
|
-
: `${formatQuantity(i.threshold)}` })));
|
|
44
|
-
const daysMsg = status.days === 7300 ? 'all-time' : `last ${status.days} days`;
|
|
45
|
-
const progressAmt = !points
|
|
46
|
-
? formatDollars(status.progress, '', 0)
|
|
47
|
-
: formatQuantity(status.progress);
|
|
48
|
-
const progressMsg = !points
|
|
49
|
-
? `${progressAmt} spent ${daysMsg}`
|
|
50
|
-
: `${progressAmt} ${points.name.toLowerCase()} earned ${daysMsg}`;
|
|
51
|
-
return { progress, progressMsg, tiers: progressTiers };
|
|
52
|
-
};
|
|
53
|
-
export const makeProgress = (loyalty_type, spend, redemption) => {
|
|
54
|
-
var _a;
|
|
55
|
-
if (!spend || !redemption || !loyalty_type)
|
|
56
|
-
return null;
|
|
57
|
-
const currentSpend = parseFloat((_a = spend.current) !== null && _a !== void 0 ? _a : '0');
|
|
58
|
-
const threshold = parseFloat(redemption.threshold);
|
|
59
|
-
const progress = loyalty_type === loyaltyType.CREDIT
|
|
60
|
-
? (currentSpend / threshold) * 100
|
|
61
|
-
: null;
|
|
62
|
-
return progress;
|
|
63
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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,7 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.
|
|
39
|
+
"@open-tender/types": "^0.4.1",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|