@open-tender/utils 0.4.90 → 0.4.92
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/useCreditCardForm.d.ts +1 -1
- package/dist/cjs/hooks/useCreditCardForm.js +3 -1
- package/dist/cjs/hooks/useDonationForm.d.ts +1 -1
- package/dist/cjs/hooks/useDonationForm.js +11 -13
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +1 -1
- package/dist/cjs/hooks/useGiftCardsForm.js +12 -16
- package/dist/cjs/utils/loyalty.d.ts +2 -1
- package/dist/cjs/utils/loyalty.js +7 -1
- package/dist/cjs/utils/rewards.d.ts +2 -1
- package/dist/cjs/utils/rewards.js +8 -2
- package/dist/esm/hooks/useCreditCardForm.d.ts +1 -1
- package/dist/esm/hooks/useCreditCardForm.js +3 -1
- package/dist/esm/hooks/useDonationForm.d.ts +1 -1
- package/dist/esm/hooks/useDonationForm.js +11 -13
- package/dist/esm/hooks/useGiftCardsForm.d.ts +1 -1
- package/dist/esm/hooks/useGiftCardsForm.js +12 -16
- package/dist/esm/utils/loyalty.d.ts +2 -1
- package/dist/esm/utils/loyalty.js +5 -0
- package/dist/esm/utils/rewards.d.ts +2 -1
- package/dist/esm/utils/rewards.js +6 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, kountSessionId?: string | null) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
6
|
data: CreditCardData | null;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useCreditCardForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const __1 = require("../");
|
|
6
|
-
const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
|
|
6
|
+
const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
9
9
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
@@ -31,6 +31,8 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, re
|
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
|
|
34
|
+
if (kountSessionId)
|
|
35
|
+
cardRc.kount_device_session_id = kountSessionId;
|
|
34
36
|
if (recaptchaKey) {
|
|
35
37
|
try {
|
|
36
38
|
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
|
|
|
3
3
|
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useDonationsForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
6
|
+
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
9
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
@@ -72,6 +72,14 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
72
72
|
type: 'working',
|
|
73
73
|
args: { text: 'Submitting your contribution...' }
|
|
74
74
|
};
|
|
75
|
+
const formData = {
|
|
76
|
+
amount: amount,
|
|
77
|
+
email: email,
|
|
78
|
+
credit_card,
|
|
79
|
+
token: ''
|
|
80
|
+
};
|
|
81
|
+
if (kountSessionId)
|
|
82
|
+
formData.kount_device_session_id = kountSessionId;
|
|
75
83
|
if (recaptchaKey) {
|
|
76
84
|
try {
|
|
77
85
|
const token = recaptchaRef.current.getValue();
|
|
@@ -83,12 +91,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
83
91
|
else {
|
|
84
92
|
setSubmitting(true);
|
|
85
93
|
setAlert(alert);
|
|
86
|
-
purchase({
|
|
87
|
-
amount: amount,
|
|
88
|
-
email: email,
|
|
89
|
-
credit_card,
|
|
90
|
-
token: token
|
|
91
|
-
});
|
|
94
|
+
purchase(Object.assign(Object.assign({}, formData), { token }));
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
catch (err) {
|
|
@@ -100,12 +103,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
100
103
|
else {
|
|
101
104
|
setSubmitting(true);
|
|
102
105
|
setAlert(alert);
|
|
103
|
-
purchase(
|
|
104
|
-
amount: amount,
|
|
105
|
-
email: email,
|
|
106
|
-
credit_card,
|
|
107
|
-
token: ''
|
|
108
|
-
});
|
|
106
|
+
purchase(formData);
|
|
109
107
|
}
|
|
110
108
|
};
|
|
111
109
|
const handleSubmit = (evt) => {
|
|
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
|
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useGiftCardsForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url) => {
|
|
6
|
+
const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
9
|
const recaptchaRef = (0, react_1.useRef)(null);
|
|
@@ -94,6 +94,14 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
94
94
|
type: 'working',
|
|
95
95
|
args: { text: 'Submitting your purchase...' }
|
|
96
96
|
};
|
|
97
|
+
const formData = {
|
|
98
|
+
credit_card,
|
|
99
|
+
name: name !== null && name !== void 0 ? name : '',
|
|
100
|
+
email: email !== null && email !== void 0 ? email : '',
|
|
101
|
+
url: url !== null && url !== void 0 ? url : ''
|
|
102
|
+
};
|
|
103
|
+
if (kountSessionId)
|
|
104
|
+
formData.kount_device_session_id = kountSessionId;
|
|
97
105
|
if (recaptchaKey) {
|
|
98
106
|
try {
|
|
99
107
|
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
@@ -107,14 +115,8 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
107
115
|
setSubmitting(true);
|
|
108
116
|
setAlert(alert);
|
|
109
117
|
const gift_cards = makeGiftCards(cards);
|
|
110
|
-
purchase({
|
|
111
|
-
|
|
112
|
-
credit_card,
|
|
113
|
-
name: name !== null && name !== void 0 ? name : '',
|
|
114
|
-
email: email !== null && email !== void 0 ? email : '',
|
|
115
|
-
url: url !== null && url !== void 0 ? url : '',
|
|
116
|
-
gift_cards
|
|
117
|
-
});
|
|
118
|
+
purchase(Object.assign(Object.assign({}, formData), { token,
|
|
119
|
+
gift_cards }));
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
catch (err) {
|
|
@@ -126,13 +128,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
|
|
|
126
128
|
setSubmitting(true);
|
|
127
129
|
setAlert(alert);
|
|
128
130
|
const gift_cards = makeGiftCards(cards);
|
|
129
|
-
purchase({
|
|
130
|
-
credit_card,
|
|
131
|
-
name: name !== null && name !== void 0 ? name : '',
|
|
132
|
-
email: email !== null && email !== void 0 ? email : '',
|
|
133
|
-
url: url !== null && url !== void 0 ? url : '',
|
|
134
|
-
gift_cards
|
|
135
|
-
});
|
|
131
|
+
purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
|
|
136
132
|
}
|
|
137
133
|
};
|
|
138
134
|
const handleSubmit = (evt) => {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { Money } from '@open-tender/types';
|
|
1
|
+
import { Money, TPLSPointsShopReward } from '@open-tender/types';
|
|
2
2
|
export declare const roundPoints: (points?: number | Money | null) => number;
|
|
3
|
+
export declare const getIsPointShowRewardExpired: (item: TPLSPointsShopReward) => boolean;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.roundPoints = void 0;
|
|
3
|
+
exports.getIsPointShowRewardExpired = exports.roundPoints = void 0;
|
|
4
|
+
const datetimes_1 = require("./datetimes");
|
|
4
5
|
const roundPoints = (points) => {
|
|
5
6
|
if (!points || isNaN(Number(points)))
|
|
6
7
|
return 0;
|
|
7
8
|
return parseInt(parseFloat(points.toString()).toFixed(0));
|
|
8
9
|
};
|
|
9
10
|
exports.roundPoints = roundPoints;
|
|
11
|
+
const getIsPointShowRewardExpired = (item) => {
|
|
12
|
+
const { end_date } = item;
|
|
13
|
+
return end_date ? (0, datetimes_1.dateStrToDate)(end_date) < new Date() : false;
|
|
14
|
+
};
|
|
15
|
+
exports.getIsPointShowRewardExpired = getIsPointShowRewardExpired;
|
|
@@ -2,4 +2,5 @@ import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@
|
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
3
|
export declare const makeLimitations: (item: Discount) => string;
|
|
4
4
|
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const getIsDealExpired: (item: Discount) => boolean;
|
|
6
|
+
export declare const getIsRewardExpired: (item: Discount) => boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIsRewardExpired = exports.makeDiscountEnhanced = exports.makeLimitations = exports.makeValidDeals = void 0;
|
|
3
|
+
exports.getIsRewardExpired = exports.getIsDealExpired = exports.makeDiscountEnhanced = exports.makeLimitations = exports.makeValidDeals = void 0;
|
|
4
4
|
const datetimes_1 = require("./datetimes");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
6
|
const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
@@ -104,7 +104,13 @@ const makeDiscountEnhanced = (item) => {
|
|
|
104
104
|
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
105
105
|
};
|
|
106
106
|
exports.makeDiscountEnhanced = makeDiscountEnhanced;
|
|
107
|
-
const
|
|
107
|
+
const getIsDealExpired = (item) => {
|
|
108
|
+
const { end_date } = item;
|
|
109
|
+
return end_date ? (0, datetimes_1.dateStrToDate)(end_date) < new Date() : false;
|
|
110
|
+
};
|
|
111
|
+
exports.getIsDealExpired = getIsDealExpired;
|
|
112
|
+
const getIsRewardExpired = (item) => {
|
|
113
|
+
const { end_at } = item;
|
|
108
114
|
return end_at ? (0, datetimes_1.dateStrToDate)(end_at) < new Date() : false;
|
|
109
115
|
};
|
|
110
116
|
exports.getIsRewardExpired = getIsRewardExpired;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
|
|
3
|
+
export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, kountSessionId?: string | null) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
6
6
|
data: CreditCardData | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors, validateCreditCard } from '../';
|
|
3
|
-
export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
|
|
3
|
+
export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const recaptchaRef = useRef(null);
|
|
6
6
|
const [submitting, setSubmitting] = useState(false);
|
|
@@ -28,6 +28,8 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
|
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
|
|
31
|
+
if (kountSessionId)
|
|
32
|
+
cardRc.kount_device_session_id = kountSessionId;
|
|
31
33
|
if (recaptchaKey) {
|
|
32
34
|
try {
|
|
33
35
|
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
|
|
|
3
3
|
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { makeFormErrors, makeNumeric, validateCreditCard } from '../utils';
|
|
3
|
-
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
3
|
+
export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const recaptchaRef = useRef(null);
|
|
@@ -69,6 +69,14 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
69
69
|
type: 'working',
|
|
70
70
|
args: { text: 'Submitting your contribution...' }
|
|
71
71
|
};
|
|
72
|
+
const formData = {
|
|
73
|
+
amount: amount,
|
|
74
|
+
email: email,
|
|
75
|
+
credit_card,
|
|
76
|
+
token: ''
|
|
77
|
+
};
|
|
78
|
+
if (kountSessionId)
|
|
79
|
+
formData.kount_device_session_id = kountSessionId;
|
|
72
80
|
if (recaptchaKey) {
|
|
73
81
|
try {
|
|
74
82
|
const token = recaptchaRef.current.getValue();
|
|
@@ -80,12 +88,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
80
88
|
else {
|
|
81
89
|
setSubmitting(true);
|
|
82
90
|
setAlert(alert);
|
|
83
|
-
purchase({
|
|
84
|
-
amount: amount,
|
|
85
|
-
email: email,
|
|
86
|
-
credit_card,
|
|
87
|
-
token: token
|
|
88
|
-
});
|
|
91
|
+
purchase(Object.assign(Object.assign({}, formData), { token }));
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
catch (err) {
|
|
@@ -97,12 +100,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
97
100
|
else {
|
|
98
101
|
setSubmitting(true);
|
|
99
102
|
setAlert(alert);
|
|
100
|
-
purchase(
|
|
101
|
-
amount: amount,
|
|
102
|
-
email: email,
|
|
103
|
-
credit_card,
|
|
104
|
-
token: ''
|
|
105
|
-
});
|
|
103
|
+
purchase(formData);
|
|
106
104
|
}
|
|
107
105
|
};
|
|
108
106
|
const handleSubmit = (evt) => {
|
|
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
|
|
|
3
3
|
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
4
|
type: string;
|
|
5
5
|
args?: unknown;
|
|
6
|
-
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string) => {
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null) => {
|
|
7
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
8
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
9
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
2
2
|
import { makeFormErrors, validateCreditCard } from '../utils';
|
|
3
|
-
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url) => {
|
|
3
|
+
export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const recaptchaRef = useRef(null);
|
|
@@ -91,6 +91,14 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
91
91
|
type: 'working',
|
|
92
92
|
args: { text: 'Submitting your purchase...' }
|
|
93
93
|
};
|
|
94
|
+
const formData = {
|
|
95
|
+
credit_card,
|
|
96
|
+
name: name !== null && name !== void 0 ? name : '',
|
|
97
|
+
email: email !== null && email !== void 0 ? email : '',
|
|
98
|
+
url: url !== null && url !== void 0 ? url : ''
|
|
99
|
+
};
|
|
100
|
+
if (kountSessionId)
|
|
101
|
+
formData.kount_device_session_id = kountSessionId;
|
|
94
102
|
if (recaptchaKey) {
|
|
95
103
|
try {
|
|
96
104
|
const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
@@ -104,14 +112,8 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
104
112
|
setSubmitting(true);
|
|
105
113
|
setAlert(alert);
|
|
106
114
|
const gift_cards = makeGiftCards(cards);
|
|
107
|
-
purchase({
|
|
108
|
-
|
|
109
|
-
credit_card,
|
|
110
|
-
name: name !== null && name !== void 0 ? name : '',
|
|
111
|
-
email: email !== null && email !== void 0 ? email : '',
|
|
112
|
-
url: url !== null && url !== void 0 ? url : '',
|
|
113
|
-
gift_cards
|
|
114
|
-
});
|
|
115
|
+
purchase(Object.assign(Object.assign({}, formData), { token,
|
|
116
|
+
gift_cards }));
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
catch (err) {
|
|
@@ -123,13 +125,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
|
|
|
123
125
|
setSubmitting(true);
|
|
124
126
|
setAlert(alert);
|
|
125
127
|
const gift_cards = makeGiftCards(cards);
|
|
126
|
-
purchase({
|
|
127
|
-
credit_card,
|
|
128
|
-
name: name !== null && name !== void 0 ? name : '',
|
|
129
|
-
email: email !== null && email !== void 0 ? email : '',
|
|
130
|
-
url: url !== null && url !== void 0 ? url : '',
|
|
131
|
-
gift_cards
|
|
132
|
-
});
|
|
128
|
+
purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
|
|
133
129
|
}
|
|
134
130
|
};
|
|
135
131
|
const handleSubmit = (evt) => {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { Money } from '@open-tender/types';
|
|
1
|
+
import { Money, TPLSPointsShopReward } from '@open-tender/types';
|
|
2
2
|
export declare const roundPoints: (points?: number | Money | null) => number;
|
|
3
|
+
export declare const getIsPointShowRewardExpired: (item: TPLSPointsShopReward) => boolean;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { dateStrToDate } from './datetimes';
|
|
1
2
|
export const roundPoints = (points) => {
|
|
2
3
|
if (!points || isNaN(Number(points)))
|
|
3
4
|
return 0;
|
|
4
5
|
return parseInt(parseFloat(points.toString()).toFixed(0));
|
|
5
6
|
};
|
|
7
|
+
export const getIsPointShowRewardExpired = (item) => {
|
|
8
|
+
const { end_date } = item;
|
|
9
|
+
return end_date ? dateStrToDate(end_date) < new Date() : false;
|
|
10
|
+
};
|
|
@@ -2,4 +2,5 @@ import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@
|
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
3
|
export declare const makeLimitations: (item: Discount) => string;
|
|
4
4
|
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const getIsDealExpired: (item: Discount) => boolean;
|
|
6
|
+
export declare const getIsRewardExpired: (item: Discount) => boolean;
|
|
@@ -98,6 +98,11 @@ export const makeDiscountEnhanced = (item) => {
|
|
|
98
98
|
const limitations = makeLimitations(item);
|
|
99
99
|
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
100
100
|
};
|
|
101
|
-
export const
|
|
101
|
+
export const getIsDealExpired = (item) => {
|
|
102
|
+
const { end_date } = item;
|
|
103
|
+
return end_date ? dateStrToDate(end_date) < new Date() : false;
|
|
104
|
+
};
|
|
105
|
+
export const getIsRewardExpired = (item) => {
|
|
106
|
+
const { end_at } = item;
|
|
102
107
|
return end_at ? dateStrToDate(end_at) < new Date() : false;
|
|
103
108
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.92",
|
|
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.4.
|
|
39
|
+
"@open-tender/types": "^0.4.130",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"typescript": "^4.8.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@open-tender/types": "^0.4.
|
|
61
|
+
"@open-tender/types": "^0.4.130",
|
|
62
62
|
"@reduxjs/toolkit": "^1.8.5",
|
|
63
63
|
"react": "^18.2.0"
|
|
64
64
|
},
|