@open-tender/utils 0.5.21 → 0.5.23

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.
@@ -1,10 +1,10 @@
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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData | null;
7
7
  errors: Record<string, string> | CreditCardErrors;
8
8
  submitting: boolean;
9
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
9
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
10
10
  };
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCreditCardForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const __1 = require("../");
6
- const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId, requireCardholderName = false) => {
7
+ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const recaptchaRef = (0, react_1.useRef)(null);
9
10
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
@@ -18,8 +19,8 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, re
18
19
  }
19
20
  }
20
21
  }, [loading, error]);
21
- const handleSubmit = (evt) => {
22
- var _a, _b, _c;
22
+ const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
23
+ var _a, _b, _c, _d, _e;
23
24
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
24
25
  setErrors({});
25
26
  if (!data || !cardType)
@@ -33,9 +34,12 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, re
33
34
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
34
35
  if (kountSessionId)
35
36
  cardRc.kount_device_session_id = kountSessionId;
36
- if (recaptchaKey) {
37
+ if (includeRecaptcha) {
37
38
  try {
38
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
39
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
40
+ const token = isEnterpriseRecaptcha
41
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
42
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
39
43
  if (!token) {
40
44
  setSubmitting(false);
41
45
  setErrors({
@@ -59,8 +63,8 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, re
59
63
  addCard(cardRc, callback);
60
64
  }
61
65
  }
62
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
63
- };
66
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
67
+ });
64
68
  return {
65
69
  submitRef,
66
70
  recaptchaRef,
@@ -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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDonationsForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const utils_1 = require("../utils");
6
- const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
7
+ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const inputRef = (0, react_1.useRef)(null);
9
10
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -67,7 +68,8 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
67
68
  const customerCardId = parseInt(value);
68
69
  setCreditCard({ customer_card_id: customerCardId });
69
70
  };
70
- const purchaseWithCaptcha = (credit_card) => {
71
+ const purchaseWithCaptcha = (credit_card) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
72
+ var _a, _b, _c;
71
73
  const alert = {
72
74
  type: 'working',
73
75
  args: { text: 'Submitting your contribution...' }
@@ -80,9 +82,12 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
80
82
  };
81
83
  if (kountSessionId)
82
84
  formData.kount_device_session_id = kountSessionId;
83
- if (recaptchaKey) {
85
+ if (includeRecaptcha) {
84
86
  try {
85
- const token = recaptchaRef.current.getValue();
87
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
88
+ const token = isEnterpriseRecaptcha
89
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
90
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
86
91
  if (!token) {
87
92
  setSubmitting(false);
88
93
  setErrors({ form: 'Please complete the recaptcha before submitting' });
@@ -105,7 +110,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
105
110
  setAlert(alert);
106
111
  purchase(formData);
107
112
  }
108
- };
113
+ });
109
114
  const handleSubmit = (evt) => {
110
115
  var _a, _b, _c;
111
116
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useGiftCardsForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const utils_1 = require("../utils");
6
- const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
7
+ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const inputRef = (0, react_1.useRef)(null);
9
10
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -88,8 +89,8 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
88
89
  const customerCardId = parseInt(`${value}`);
89
90
  setCreditCard({ customer_card_id: customerCardId });
90
91
  };
91
- const purchaseWithCaptcha = (credit_card) => {
92
- var _a;
92
+ const purchaseWithCaptcha = (credit_card) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
93
+ var _a, _b, _c;
93
94
  const alert = {
94
95
  type: 'working',
95
96
  args: { text: 'Submitting your purchase...' }
@@ -102,9 +103,12 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
102
103
  };
103
104
  if (kountSessionId)
104
105
  formData.kount_device_session_id = kountSessionId;
105
- if (recaptchaKey) {
106
+ if (includeRecaptcha) {
106
107
  try {
107
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
108
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
109
+ const token = isEnterpriseRecaptcha
110
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
111
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
108
112
  if (!token) {
109
113
  setSubmitting(false);
110
114
  setErrors({
@@ -130,7 +134,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
130
134
  const gift_cards = makeGiftCards(cards);
131
135
  purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
132
136
  }
133
- };
137
+ });
134
138
  const handleSubmit = (evt) => {
135
139
  var _a, _b, _c;
136
140
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, recaptchaKey: string | null, callback?: () => void, showPassword?: boolean) => {
3
+ export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
9
9
  errors: Record<string, string>;
10
10
  submitting: boolean;
11
11
  handleChange: (name: string, value: string | number | boolean) => void;
12
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
13
13
  };
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useLoginForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const utils_1 = require("../utils");
6
- const useLoginForm = (loading, error, login, recaptchaKey, callback, showPassword = true) => {
7
+ const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const inputRef = (0, react_1.useRef)(null);
9
10
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -47,13 +48,16 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
47
48
  const handleChange = (name, value) => {
48
49
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
49
50
  };
50
- const handleSubmit = (evt) => {
51
- var _a, _b, _c;
51
+ const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
52
+ var _a, _b, _c, _d, _e;
52
53
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
53
54
  const { email, password } = data;
54
- if (recaptchaKey) {
55
+ if (includeRecaptcha) {
55
56
  try {
56
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
57
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
58
+ const token = isEnterpriseRecaptcha
59
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
60
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
57
61
  if (!token) {
58
62
  setSubmitting(false);
59
63
  setErrors({
@@ -78,8 +82,8 @@ const useLoginForm = (loading, error, login, recaptchaKey, callback, showPasswor
78
82
  login(email, password);
79
83
  setSubmitting(true);
80
84
  }
81
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
82
- };
85
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
86
+ });
83
87
  return {
84
88
  submitRef,
85
89
  inputRef,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, recaptchaKey: string | null, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
3
+ export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -13,5 +13,5 @@ export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: Request
13
13
  setErrors: import("react").Dispatch<import("react").SetStateAction<Record<string, string>>>;
14
14
  submitting: boolean;
15
15
  handleChange: (name: string, value: string | number | boolean) => void;
16
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
16
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
17
17
  };
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOneTimePasscodeForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const utils_1 = require("../utils");
6
- const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, callback) => {
7
+ const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const inputRef = (0, react_1.useRef)(null);
9
10
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -64,16 +65,19 @@ const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, c
64
65
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
65
66
  }
66
67
  };
67
- const handleSubmit = (evt) => {
68
- var _a, _b, _c;
68
+ const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
69
+ var _a, _b, _c, _d, _e;
69
70
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
70
71
  const { identifier, one_time_passcode } = data;
71
72
  const values = /[a-zA-Z]/g.test(identifier)
72
73
  ? { email: identifier }
73
74
  : { phone: identifier };
74
- if (recaptchaKey) {
75
+ if (includeRecaptcha) {
75
76
  try {
76
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
77
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
78
+ const token = isEnterpriseRecaptcha
79
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
80
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
77
81
  if (!token) {
78
82
  setSubmitting(false);
79
83
  setErrors({
@@ -98,8 +102,8 @@ const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, c
98
102
  otpSent ? submit({ one_time_passcode }) : submit(values);
99
103
  setSubmitting(true);
100
104
  }
101
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
102
- };
105
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
106
+ });
103
107
  return {
104
108
  submitRef,
105
109
  inputRef,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, recaptchaKey: string | null, callback?: () => void) => {
3
+ export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | null, callback?: () => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -9,5 +9,5 @@ export declare const useSignInForm: (email: string, loading: RequestStatus, erro
9
9
  errors: Record<string, string>;
10
10
  submitting: boolean;
11
11
  handleChange: (name: string, value: string | number | boolean) => void;
12
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
13
13
  };
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSignInForm = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const react_1 = require("react");
5
6
  const utils_1 = require("../utils");
6
- const useSignInForm = (email, loading, error, login, recaptchaKey, callback) => {
7
+ const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
7
8
  const submitRef = (0, react_1.useRef)(null);
8
9
  const inputRef = (0, react_1.useRef)(null);
9
10
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -47,13 +48,16 @@ const useSignInForm = (email, loading, error, login, recaptchaKey, callback) =>
47
48
  const handleChange = (name, value) => {
48
49
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
49
50
  };
50
- const handleSubmit = (evt) => {
51
- var _a, _b, _c;
51
+ const handleSubmit = (evt) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
52
+ var _a, _b, _c, _d, _e;
52
53
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
53
54
  const { email, password } = data;
54
- if (recaptchaKey) {
55
+ if (includeRecaptcha) {
55
56
  try {
56
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
57
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
58
+ const token = isEnterpriseRecaptcha
59
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
60
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
57
61
  if (!token) {
58
62
  setSubmitting(false);
59
63
  setErrors({
@@ -76,8 +80,8 @@ const useSignInForm = (email, loading, error, login, recaptchaKey, callback) =>
76
80
  login(email, password);
77
81
  setSubmitting(true);
78
82
  }
79
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
80
- };
83
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
84
+ });
81
85
  return {
82
86
  submitRef,
83
87
  inputRef,
@@ -208,7 +208,7 @@ export declare const makeSimpleCart: <C extends {
208
208
  made_for: string;
209
209
  notes: string;
210
210
  }[];
211
- export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
211
+ export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut, requestedAt: RequestedAt) => {
212
212
  newCart: Cart;
213
213
  errors: CartErrors | null;
214
214
  };
@@ -731,7 +731,7 @@ const makeGroupsLookup = (item) => {
731
731
  }, {});
732
732
  };
733
733
  // TODO: refactor for nested modifiers
734
- const validateCart = (cart, categories, soldOut) => {
734
+ const validateCart = (cart, categories, soldOut, requestedAt) => {
735
735
  const itemIds = cart.map(item => item.id);
736
736
  const itemLookup = makeItemLookup(categories, itemIds);
737
737
  let errors = null;
@@ -740,7 +740,8 @@ const validateCart = (cart, categories, soldOut) => {
740
740
  let newCart = cart.map(oldItem => {
741
741
  var _a, _b, _c, _d;
742
742
  const newItem = itemLookup[oldItem.id];
743
- if (!newItem || soldOut.includes(oldItem.id)) {
743
+ if (!newItem ||
744
+ (0, exports.checkSoldOut)(oldItem.id, newItem.suspend_until, soldOut, requestedAt)) {
744
745
  missingItems.push(oldItem);
745
746
  return null;
746
747
  }
@@ -758,7 +759,7 @@ const validateCart = (cart, categories, soldOut) => {
758
759
  return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
759
760
  })
760
761
  .map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
761
- const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map((group) => {
762
+ const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
762
763
  const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
763
764
  const newGroup = newGroups[group.id];
764
765
  // check if option group is still part of the item
@@ -772,12 +773,13 @@ const validateCart = (cart, categories, soldOut) => {
772
773
  }
773
774
  }
774
775
  else {
775
- const updatedOptions = group.options.map((option) => {
776
+ const updatedOptions = group.options.map(option => {
776
777
  const newOption = newGroup.options[option.id];
777
778
  // check to see if any OLD options aren't avaiilable on the current menu
778
779
  // or if any of the options are currently sold out
779
780
  if (!newOption ||
780
- (option.quantity > 0 && soldOut.includes(option.id))) {
781
+ (option.quantity > 0 &&
782
+ (0, exports.checkSoldOut)(option.id, option.suspend_until, soldOut, requestedAt))) {
781
783
  missingOptions.push(option);
782
784
  return option;
783
785
  }
@@ -1,10 +1,10 @@
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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, includeRecaptcha: boolean | undefined, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData | null;
7
7
  errors: Record<string, string> | CreditCardErrors;
8
8
  submitting: boolean;
9
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
9
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
10
10
  };
@@ -1,6 +1,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useState, useEffect, useRef } from 'react';
2
3
  import { makeFormErrors, validateCreditCard } from '../';
3
- export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId, requireCardholderName = false) => {
4
+ export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, includeRecaptcha, revenue_center_id, kountSessionId, requireCardholderName = false) => {
4
5
  const submitRef = useRef(null);
5
6
  const recaptchaRef = useRef(null);
6
7
  const [submitting, setSubmitting] = useState(false);
@@ -15,8 +16,8 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
15
16
  }
16
17
  }
17
18
  }, [loading, error]);
18
- const handleSubmit = (evt) => {
19
- var _a, _b, _c;
19
+ const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
20
+ var _a, _b, _c, _d, _e;
20
21
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
21
22
  setErrors({});
22
23
  if (!data || !cardType)
@@ -30,9 +31,12 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
30
31
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
31
32
  if (kountSessionId)
32
33
  cardRc.kount_device_session_id = kountSessionId;
33
- if (recaptchaKey) {
34
+ if (includeRecaptcha) {
34
35
  try {
35
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
36
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
37
+ const token = isEnterpriseRecaptcha
38
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
39
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
36
40
  if (!token) {
37
41
  setSubmitting(false);
38
42
  setErrors({
@@ -56,8 +60,8 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
56
60
  addCard(cardRc, callback);
57
61
  }
58
62
  }
59
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
60
- };
63
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
64
+ });
61
65
  return {
62
66
  submitRef,
63
67
  recaptchaRef,
@@ -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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
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,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useMemo, useEffect, useRef, useState } from 'react';
2
3
  import { makeFormErrors, makeNumeric, validateCreditCard } from '../utils';
3
- export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
4
+ export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, includeRecaptcha, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
4
5
  const submitRef = useRef(null);
5
6
  const inputRef = useRef(null);
6
7
  const recaptchaRef = useRef(null);
@@ -64,7 +65,8 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
64
65
  const customerCardId = parseInt(value);
65
66
  setCreditCard({ customer_card_id: customerCardId });
66
67
  };
67
- const purchaseWithCaptcha = (credit_card) => {
68
+ const purchaseWithCaptcha = (credit_card) => __awaiter(void 0, void 0, void 0, function* () {
69
+ var _a, _b, _c;
68
70
  const alert = {
69
71
  type: 'working',
70
72
  args: { text: 'Submitting your contribution...' }
@@ -77,9 +79,12 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
77
79
  };
78
80
  if (kountSessionId)
79
81
  formData.kount_device_session_id = kountSessionId;
80
- if (recaptchaKey) {
82
+ if (includeRecaptcha) {
81
83
  try {
82
- const token = recaptchaRef.current.getValue();
84
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
85
+ const token = isEnterpriseRecaptcha
86
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
87
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
83
88
  if (!token) {
84
89
  setSubmitting(false);
85
90
  setErrors({ form: 'Please complete the recaptcha before submitting' });
@@ -102,7 +107,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
102
107
  setAlert(alert);
103
108
  purchase(formData);
104
109
  }
105
- };
110
+ });
106
111
  const handleSubmit = (evt) => {
107
112
  var _a, _b, _c;
108
113
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -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, kountSessionId?: string | null, requireCardholderName?: boolean) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, includeRecaptcha?: boolean, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
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,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useMemo, useRef, useState, useEffect } from 'react';
2
3
  import { makeFormErrors, validateCreditCard } from '../utils';
3
- export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
4
+ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, includeRecaptcha, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
4
5
  const submitRef = useRef(null);
5
6
  const inputRef = useRef(null);
6
7
  const recaptchaRef = useRef(null);
@@ -85,8 +86,8 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
85
86
  const customerCardId = parseInt(`${value}`);
86
87
  setCreditCard({ customer_card_id: customerCardId });
87
88
  };
88
- const purchaseWithCaptcha = (credit_card) => {
89
- var _a;
89
+ const purchaseWithCaptcha = (credit_card) => __awaiter(void 0, void 0, void 0, function* () {
90
+ var _a, _b, _c;
90
91
  const alert = {
91
92
  type: 'working',
92
93
  args: { text: 'Submitting your purchase...' }
@@ -99,9 +100,12 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
99
100
  };
100
101
  if (kountSessionId)
101
102
  formData.kount_device_session_id = kountSessionId;
102
- if (recaptchaKey) {
103
+ if (includeRecaptcha) {
103
104
  try {
104
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
105
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
106
+ const token = isEnterpriseRecaptcha
107
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
108
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
105
109
  if (!token) {
106
110
  setSubmitting(false);
107
111
  setErrors({
@@ -127,7 +131,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
127
131
  const gift_cards = makeGiftCards(cards);
128
132
  purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
129
133
  }
130
- };
134
+ });
131
135
  const handleSubmit = (evt) => {
132
136
  var _a, _b, _c;
133
137
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, recaptchaKey: string | null, callback?: () => void, showPassword?: boolean) => {
3
+ export declare const useLoginForm: (loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | undefined, callback?: () => void, showPassword?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -9,5 +9,5 @@ export declare const useLoginForm: (loading: RequestStatus, error: RequestError,
9
9
  errors: Record<string, string>;
10
10
  submitting: boolean;
11
11
  handleChange: (name: string, value: string | number | boolean) => void;
12
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
13
13
  };
@@ -1,6 +1,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useState, useEffect, useRef } from 'react';
2
3
  import { makeFormErrors } from '../utils';
3
- export const useLoginForm = (loading, error, login, recaptchaKey, callback, showPassword = true) => {
4
+ export const useLoginForm = (loading, error, login, includeRecaptcha, callback, showPassword = true) => {
4
5
  const submitRef = useRef(null);
5
6
  const inputRef = useRef(null);
6
7
  const recaptchaRef = useRef(null);
@@ -44,13 +45,16 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
44
45
  const handleChange = (name, value) => {
45
46
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
46
47
  };
47
- const handleSubmit = (evt) => {
48
- var _a, _b, _c;
48
+ const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
49
+ var _a, _b, _c, _d, _e;
49
50
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
50
51
  const { email, password } = data;
51
- if (recaptchaKey) {
52
+ if (includeRecaptcha) {
52
53
  try {
53
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
54
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
55
+ const token = isEnterpriseRecaptcha
56
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
57
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
54
58
  if (!token) {
55
59
  setSubmitting(false);
56
60
  setErrors({
@@ -75,8 +79,8 @@ export const useLoginForm = (loading, error, login, recaptchaKey, callback, show
75
79
  login(email, password);
76
80
  setSubmitting(true);
77
81
  }
78
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
79
- };
82
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
83
+ });
80
84
  return {
81
85
  submitRef,
82
86
  inputRef,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CustomerSignIn, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, recaptchaKey: string | null, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
3
+ export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: RequestStatus, error: RequestError, includeRecaptcha: boolean | undefined, submit: (data: CustomerSignIn) => void, callback?: () => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -13,5 +13,5 @@ export declare const useOneTimePasscodeForm: (otpSent: boolean, loading: Request
13
13
  setErrors: import("react").Dispatch<import("react").SetStateAction<Record<string, string>>>;
14
14
  submitting: boolean;
15
15
  handleChange: (name: string, value: string | number | boolean) => void;
16
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
16
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
17
17
  };
@@ -1,6 +1,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useState, useEffect, useRef } from 'react';
2
3
  import { makeFormErrors, makePhone } from '../utils';
3
- export const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, submit, callback) => {
4
+ export const useOneTimePasscodeForm = (otpSent, loading, error, includeRecaptcha, submit, callback) => {
4
5
  const submitRef = useRef(null);
5
6
  const inputRef = useRef(null);
6
7
  const recaptchaRef = useRef(null);
@@ -61,16 +62,19 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, su
61
62
  setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
62
63
  }
63
64
  };
64
- const handleSubmit = (evt) => {
65
- var _a, _b, _c;
65
+ const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
66
+ var _a, _b, _c, _d, _e;
66
67
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
67
68
  const { identifier, one_time_passcode } = data;
68
69
  const values = /[a-zA-Z]/g.test(identifier)
69
70
  ? { email: identifier }
70
71
  : { phone: identifier };
71
- if (recaptchaKey) {
72
+ if (includeRecaptcha) {
72
73
  try {
73
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
74
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
75
+ const token = isEnterpriseRecaptcha
76
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
77
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
74
78
  if (!token) {
75
79
  setSubmitting(false);
76
80
  setErrors({
@@ -95,8 +99,8 @@ export const useOneTimePasscodeForm = (otpSent, loading, error, recaptchaKey, su
95
99
  otpSent ? submit({ one_time_passcode }) : submit(values);
96
100
  setSubmitting(true);
97
101
  }
98
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
99
- };
102
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
103
+ });
100
104
  return {
101
105
  submitRef,
102
106
  inputRef,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { FormFields, LoginData, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, recaptchaKey: string | null, callback?: () => void) => {
3
+ export declare const useSignInForm: (email: string, loading: RequestStatus, error: RequestError, login: (email: string, password?: string, recaptcha_token?: string) => void, includeRecaptcha: boolean | null, callback?: () => void) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
6
6
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -9,5 +9,5 @@ export declare const useSignInForm: (email: string, loading: RequestStatus, erro
9
9
  errors: Record<string, string>;
10
10
  submitting: boolean;
11
11
  handleChange: (name: string, value: string | number | boolean) => void;
12
- handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
12
+ handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => Promise<void>;
13
13
  };
@@ -1,6 +1,7 @@
1
+ import { __awaiter } from "tslib";
1
2
  import { useState, useEffect, useRef } from 'react';
2
3
  import { makeFormErrors } from '../utils';
3
- export const useSignInForm = (email, loading, error, login, recaptchaKey, callback) => {
4
+ export const useSignInForm = (email, loading, error, login, includeRecaptcha, callback) => {
4
5
  const submitRef = useRef(null);
5
6
  const inputRef = useRef(null);
6
7
  const recaptchaRef = useRef(null);
@@ -44,13 +45,16 @@ export const useSignInForm = (email, loading, error, login, recaptchaKey, callba
44
45
  const handleChange = (name, value) => {
45
46
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
46
47
  };
47
- const handleSubmit = (evt) => {
48
- var _a, _b, _c;
48
+ const handleSubmit = (evt) => __awaiter(void 0, void 0, void 0, function* () {
49
+ var _a, _b, _c, _d, _e;
49
50
  evt === null || evt === void 0 ? void 0 : evt.preventDefault();
50
51
  const { email, password } = data;
51
- if (recaptchaKey) {
52
+ if (includeRecaptcha) {
52
53
  try {
53
- const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
54
+ const isEnterpriseRecaptcha = ((_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.props.size) === 'invisible';
55
+ const token = isEnterpriseRecaptcha
56
+ ? yield ((_b = recaptchaRef.current) === null || _b === void 0 ? void 0 : _b.executeAsync())
57
+ : (_c = recaptchaRef.current) === null || _c === void 0 ? void 0 : _c.getValue();
54
58
  if (!token) {
55
59
  setSubmitting(false);
56
60
  setErrors({
@@ -73,8 +77,8 @@ export const useSignInForm = (email, loading, error, login, recaptchaKey, callba
73
77
  login(email, password);
74
78
  setSubmitting(true);
75
79
  }
76
- ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
77
- };
80
+ ((_d = submitRef.current) === null || _d === void 0 ? void 0 : _d.blur) && ((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur());
81
+ });
78
82
  return {
79
83
  submitRef,
80
84
  inputRef,
@@ -208,7 +208,7 @@ export declare const makeSimpleCart: <C extends {
208
208
  made_for: string;
209
209
  notes: string;
210
210
  }[];
211
- export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
211
+ export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut, requestedAt: RequestedAt) => {
212
212
  newCart: Cart;
213
213
  errors: CartErrors | null;
214
214
  };
@@ -695,7 +695,7 @@ const makeGroupsLookup = (item) => {
695
695
  }, {});
696
696
  };
697
697
  // TODO: refactor for nested modifiers
698
- export const validateCart = (cart, categories, soldOut) => {
698
+ export const validateCart = (cart, categories, soldOut, requestedAt) => {
699
699
  const itemIds = cart.map(item => item.id);
700
700
  const itemLookup = makeItemLookup(categories, itemIds);
701
701
  let errors = null;
@@ -704,7 +704,8 @@ export const validateCart = (cart, categories, soldOut) => {
704
704
  let newCart = cart.map(oldItem => {
705
705
  var _a, _b, _c, _d;
706
706
  const newItem = itemLookup[oldItem.id];
707
- if (!newItem || soldOut.includes(oldItem.id)) {
707
+ if (!newItem ||
708
+ checkSoldOut(oldItem.id, newItem.suspend_until, soldOut, requestedAt)) {
708
709
  missingItems.push(oldItem);
709
710
  return null;
710
711
  }
@@ -722,7 +723,7 @@ export const validateCart = (cart, categories, soldOut) => {
722
723
  return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
723
724
  })
724
725
  .map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
725
- const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map((group) => {
726
+ const updatedGroups = (_b = oldItem.groups) === null || _b === void 0 ? void 0 : _b.map(group => {
726
727
  const optionCount = group.options.reduce((t, i) => (t += i.quantity), 0);
727
728
  const newGroup = newGroups[group.id];
728
729
  // check if option group is still part of the item
@@ -736,12 +737,13 @@ export const validateCart = (cart, categories, soldOut) => {
736
737
  }
737
738
  }
738
739
  else {
739
- const updatedOptions = group.options.map((option) => {
740
+ const updatedOptions = group.options.map(option => {
740
741
  const newOption = newGroup.options[option.id];
741
742
  // check to see if any OLD options aren't avaiilable on the current menu
742
743
  // or if any of the options are currently sold out
743
744
  if (!newOption ||
744
- (option.quantity > 0 && soldOut.includes(option.id))) {
745
+ (option.quantity > 0 &&
746
+ checkSoldOut(option.id, option.suspend_until, soldOut, requestedAt))) {
745
747
  missingOptions.push(option);
746
748
  return option;
747
749
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.5.21",
3
+ "version": "0.5.23",
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",