@open-tender/utils 0.1.36 → 0.1.37
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/index.d.ts +8 -9
- package/dist/cjs/hooks/index.js +8 -9
- package/dist/cjs/hooks/useCartGuestForm.d.ts +7 -15
- package/dist/cjs/hooks/useCartGuestForm.js +17 -7
- package/dist/cjs/hooks/useSignUpForm.d.ts +2 -2
- package/dist/cjs/hooks/useSignUpForm.js +0 -3
- package/dist/cjs/utils/datetimes.d.ts +1 -6
- package/dist/esm/hooks/index.d.ts +8 -9
- package/dist/esm/hooks/index.js +8 -9
- package/dist/esm/hooks/useCartGuestForm.d.ts +7 -15
- package/dist/esm/hooks/useCartGuestForm.js +17 -7
- package/dist/esm/hooks/useSignUpForm.d.ts +2 -2
- package/dist/esm/hooks/useSignUpForm.js +0 -3
- package/dist/esm/utils/datetimes.d.ts +1 -6
- package/package.json +1 -1
- package/dist/cjs/hooks/useLevelUpForm.d.ts +0 -11
- package/dist/cjs/hooks/useLevelUpForm.js +0 -43
- package/dist/esm/hooks/useLevelUpForm.d.ts +0 -11
- package/dist/esm/hooks/useLevelUpForm.js +0 -39
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './menu';
|
|
2
|
+
export * from './types';
|
|
2
3
|
export * from './useAddressForm';
|
|
3
4
|
export * from './useAllergenForm';
|
|
5
|
+
export * from './useCartGuestForm';
|
|
6
|
+
export * from './useCheckoutLoginForm';
|
|
4
7
|
export * from './useCreditCard';
|
|
5
8
|
export * from './useCreditCardForm';
|
|
6
9
|
export * from './useCurbside';
|
|
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
|
|
|
10
13
|
export * from './useGiftCardAssignOtherForm';
|
|
11
14
|
export * from './useGiftCardForm';
|
|
12
15
|
export * from './useGiftCardsForm';
|
|
13
|
-
export * from './useOrderRating';
|
|
14
|
-
export * from './useProfileForm';
|
|
15
|
-
export * from './useSignUpGuestForm';
|
|
16
|
-
export * from './useSignUpForm';
|
|
17
|
-
export * from './useCartGuestForm';
|
|
18
|
-
export * from './useCheckoutLoginForm';
|
|
19
16
|
export * from './useGuestForm';
|
|
17
|
+
export * from './useImage';
|
|
20
18
|
export * from './useOrderFulfillmentForm';
|
|
19
|
+
export * from './useOrderRating';
|
|
21
20
|
export * from './useOrderRatingForm';
|
|
21
|
+
export * from './useProfileForm';
|
|
22
22
|
export * from './useResetPasswordForm';
|
|
23
23
|
export * from './useSendResetForm';
|
|
24
24
|
export * from './useSigninForm';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './useLevelUpForm';
|
|
25
|
+
export * from './useSignUpGuestForm';
|
|
26
|
+
export * from './useSignUpForm';
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./menu"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./useAddressForm"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./useAllergenForm"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useCartGuestForm"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./useCheckoutLoginForm"), exports);
|
|
7
10
|
tslib_1.__exportStar(require("./useCreditCard"), exports);
|
|
8
11
|
tslib_1.__exportStar(require("./useCreditCardForm"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./useCurbside"), exports);
|
|
@@ -13,18 +16,14 @@ tslib_1.__exportStar(require("./useGiftCardAssignForm"), exports);
|
|
|
13
16
|
tslib_1.__exportStar(require("./useGiftCardAssignOtherForm"), exports);
|
|
14
17
|
tslib_1.__exportStar(require("./useGiftCardForm"), exports);
|
|
15
18
|
tslib_1.__exportStar(require("./useGiftCardsForm"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./useOrderRating"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./useProfileForm"), exports);
|
|
18
|
-
tslib_1.__exportStar(require("./useSignUpGuestForm"), exports);
|
|
19
|
-
tslib_1.__exportStar(require("./useSignUpForm"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./useCartGuestForm"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./useCheckoutLoginForm"), exports);
|
|
22
19
|
tslib_1.__exportStar(require("./useGuestForm"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./useImage"), exports);
|
|
23
21
|
tslib_1.__exportStar(require("./useOrderFulfillmentForm"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./useOrderRating"), exports);
|
|
24
23
|
tslib_1.__exportStar(require("./useOrderRatingForm"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./useProfileForm"), exports);
|
|
25
25
|
tslib_1.__exportStar(require("./useResetPasswordForm"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./useSendResetForm"), exports);
|
|
27
27
|
tslib_1.__exportStar(require("./useSigninForm"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./
|
|
29
|
-
tslib_1.__exportStar(require("./
|
|
30
|
-
tslib_1.__exportStar(require("./useLevelUpForm"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./useSignUpGuestForm"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./useSignUpForm"), exports);
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
|
|
4
|
-
label?: string;
|
|
5
|
-
name: string;
|
|
6
|
-
type?: string;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const useCartGuestForm: (loading: RequestStatus, errMsg: string, cartId: number, joinCart: (data: any, callback?: any) => void) => {
|
|
2
|
+
import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
|
|
10
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
cart_id?: number | undefined;
|
|
15
|
-
};
|
|
6
|
+
data: GroupOrderGuestCreate;
|
|
7
|
+
errors: Record<string, string>;
|
|
16
8
|
submitting: boolean;
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
fields: FormFields;
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
19
12
|
};
|
|
20
|
-
export {};
|
|
@@ -2,35 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCartGuestForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const initState = {
|
|
7
|
+
first_name: '',
|
|
8
|
+
last_name: ''
|
|
9
|
+
};
|
|
10
|
+
const useCartGuestForm = (loading, error, cartId, joinCart) => {
|
|
6
11
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
12
|
const inputRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)({ cart_id: cartId });
|
|
13
|
+
const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
9
14
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
15
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
16
|
const fields = [
|
|
11
17
|
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
12
18
|
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
13
19
|
];
|
|
14
20
|
(0, react_1.useEffect)(() => {
|
|
15
21
|
return () => {
|
|
16
|
-
setData({});
|
|
22
|
+
setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
23
|
+
setErrors({});
|
|
17
24
|
};
|
|
18
|
-
}, []);
|
|
25
|
+
}, [cartId]);
|
|
19
26
|
(0, react_1.useEffect)(() => {
|
|
20
27
|
var _a, _b;
|
|
21
28
|
if (loading === 'idle') {
|
|
22
29
|
setSubmitting(false);
|
|
23
|
-
if (
|
|
30
|
+
if (error) {
|
|
31
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
24
32
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
|
-
}, [loading,
|
|
35
|
+
}, [loading, error]);
|
|
28
36
|
const handleChange = (name, value) => {
|
|
29
37
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
30
38
|
};
|
|
31
39
|
const handleSubmit = (evt) => {
|
|
32
40
|
var _a, _b;
|
|
33
41
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
42
|
+
setErrors({});
|
|
34
43
|
setSubmitting(true);
|
|
35
44
|
joinCart(data);
|
|
36
45
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
@@ -38,9 +47,10 @@ const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
38
47
|
return {
|
|
39
48
|
submitRef,
|
|
40
49
|
inputRef,
|
|
41
|
-
fields,
|
|
42
50
|
data,
|
|
51
|
+
errors,
|
|
43
52
|
submitting,
|
|
53
|
+
fields,
|
|
44
54
|
handleChange,
|
|
45
55
|
handleSubmit
|
|
46
56
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutConfig, CustomerCreate, RequestError } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpForm: (loading:
|
|
2
|
+
import { CheckoutConfig, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
data: CustomerCreate;
|
|
6
6
|
errors: Record<string, string>;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { DateString, FirstTime, GroupOrderTime, Holidays, ISOString, Order, OrderTime, OrderTimeWithDate, RequestedAt, RevenueCenter, ServiceType, TimeInterval, TimeObject, Timezone, TimezonePython, ValidTimes, Weekday } from '@open-tender/types';
|
|
2
|
-
export declare const timezoneMap:
|
|
3
|
-
'US/Eastern': string;
|
|
4
|
-
'US/Central': string;
|
|
5
|
-
'US/Mountain': string;
|
|
6
|
-
'US/Pacific': string;
|
|
7
|
-
};
|
|
2
|
+
export declare const timezoneMap: Record<TimezonePython, Timezone>;
|
|
8
3
|
export declare const weekdays: string[];
|
|
9
4
|
export declare const weekdaysUpper: string[];
|
|
10
5
|
export declare const weekdaysLower: string[];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './menu';
|
|
2
|
+
export * from './types';
|
|
2
3
|
export * from './useAddressForm';
|
|
3
4
|
export * from './useAllergenForm';
|
|
5
|
+
export * from './useCartGuestForm';
|
|
6
|
+
export * from './useCheckoutLoginForm';
|
|
4
7
|
export * from './useCreditCard';
|
|
5
8
|
export * from './useCreditCardForm';
|
|
6
9
|
export * from './useCurbside';
|
|
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
|
|
|
10
13
|
export * from './useGiftCardAssignOtherForm';
|
|
11
14
|
export * from './useGiftCardForm';
|
|
12
15
|
export * from './useGiftCardsForm';
|
|
13
|
-
export * from './useOrderRating';
|
|
14
|
-
export * from './useProfileForm';
|
|
15
|
-
export * from './useSignUpGuestForm';
|
|
16
|
-
export * from './useSignUpForm';
|
|
17
|
-
export * from './useCartGuestForm';
|
|
18
|
-
export * from './useCheckoutLoginForm';
|
|
19
16
|
export * from './useGuestForm';
|
|
17
|
+
export * from './useImage';
|
|
20
18
|
export * from './useOrderFulfillmentForm';
|
|
19
|
+
export * from './useOrderRating';
|
|
21
20
|
export * from './useOrderRatingForm';
|
|
21
|
+
export * from './useProfileForm';
|
|
22
22
|
export * from './useResetPasswordForm';
|
|
23
23
|
export * from './useSendResetForm';
|
|
24
24
|
export * from './useSigninForm';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './useLevelUpForm';
|
|
25
|
+
export * from './useSignUpGuestForm';
|
|
26
|
+
export * from './useSignUpForm';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from './menu';
|
|
2
|
+
export * from './types';
|
|
2
3
|
export * from './useAddressForm';
|
|
3
4
|
export * from './useAllergenForm';
|
|
5
|
+
export * from './useCartGuestForm';
|
|
6
|
+
export * from './useCheckoutLoginForm';
|
|
4
7
|
export * from './useCreditCard';
|
|
5
8
|
export * from './useCreditCardForm';
|
|
6
9
|
export * from './useCurbside';
|
|
@@ -10,18 +13,14 @@ export * from './useGiftCardAssignForm';
|
|
|
10
13
|
export * from './useGiftCardAssignOtherForm';
|
|
11
14
|
export * from './useGiftCardForm';
|
|
12
15
|
export * from './useGiftCardsForm';
|
|
13
|
-
export * from './useOrderRating';
|
|
14
|
-
export * from './useProfileForm';
|
|
15
|
-
export * from './useSignUpGuestForm';
|
|
16
|
-
export * from './useSignUpForm';
|
|
17
|
-
export * from './useCartGuestForm';
|
|
18
|
-
export * from './useCheckoutLoginForm';
|
|
19
16
|
export * from './useGuestForm';
|
|
17
|
+
export * from './useImage';
|
|
20
18
|
export * from './useOrderFulfillmentForm';
|
|
19
|
+
export * from './useOrderRating';
|
|
21
20
|
export * from './useOrderRatingForm';
|
|
21
|
+
export * from './useProfileForm';
|
|
22
22
|
export * from './useResetPasswordForm';
|
|
23
23
|
export * from './useSendResetForm';
|
|
24
24
|
export * from './useSigninForm';
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './useLevelUpForm';
|
|
25
|
+
export * from './useSignUpGuestForm';
|
|
26
|
+
export * from './useSignUpForm';
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
|
|
4
|
-
label?: string;
|
|
5
|
-
name: string;
|
|
6
|
-
type?: string;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const useCartGuestForm: (loading: RequestStatus, errMsg: string, cartId: number, joinCart: (data: any, callback?: any) => void) => {
|
|
2
|
+
import { FormFields, GroupOrderGuestCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useCartGuestForm: (loading: RequestStatus, error: RequestError, cartId: number, joinCart: (data: GroupOrderGuestCreate, callback?: () => void) => void) => {
|
|
10
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
11
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
cart_id?: number | undefined;
|
|
15
|
-
};
|
|
6
|
+
data: GroupOrderGuestCreate;
|
|
7
|
+
errors: Record<string, string>;
|
|
16
8
|
submitting: boolean;
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
fields: FormFields;
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
19
12
|
};
|
|
20
|
-
export {};
|
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
import { useRef, useState, useEffect } from 'react';
|
|
2
|
-
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
3
|
+
const initState = {
|
|
4
|
+
first_name: '',
|
|
5
|
+
last_name: ''
|
|
6
|
+
};
|
|
7
|
+
export const useCartGuestForm = (loading, error, cartId, joinCart) => {
|
|
3
8
|
const submitRef = useRef(null);
|
|
4
9
|
const inputRef = useRef(null);
|
|
5
|
-
const [data, setData] = useState({ cart_id: cartId });
|
|
10
|
+
const [data, setData] = useState(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
6
11
|
const [submitting, setSubmitting] = useState(false);
|
|
12
|
+
const [errors, setErrors] = useState({});
|
|
7
13
|
const fields = [
|
|
8
14
|
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
9
15
|
{ label: 'Last Name', name: 'last_name', type: 'text', required: true }
|
|
10
16
|
];
|
|
11
17
|
useEffect(() => {
|
|
12
18
|
return () => {
|
|
13
|
-
setData({});
|
|
19
|
+
setData(Object.assign(Object.assign({}, initState), { cart_id: cartId }));
|
|
20
|
+
setErrors({});
|
|
14
21
|
};
|
|
15
|
-
}, []);
|
|
22
|
+
}, [cartId]);
|
|
16
23
|
useEffect(() => {
|
|
17
24
|
var _a, _b;
|
|
18
25
|
if (loading === 'idle') {
|
|
19
26
|
setSubmitting(false);
|
|
20
|
-
if (
|
|
27
|
+
if (error) {
|
|
28
|
+
setErrors(makeFormErrors(error));
|
|
21
29
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
|
-
}, [loading,
|
|
32
|
+
}, [loading, error]);
|
|
25
33
|
const handleChange = (name, value) => {
|
|
26
34
|
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
27
35
|
};
|
|
28
36
|
const handleSubmit = (evt) => {
|
|
29
37
|
var _a, _b;
|
|
30
38
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
39
|
+
setErrors({});
|
|
31
40
|
setSubmitting(true);
|
|
32
41
|
joinCart(data);
|
|
33
42
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
@@ -35,9 +44,10 @@ export const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
|
35
44
|
return {
|
|
36
45
|
submitRef,
|
|
37
46
|
inputRef,
|
|
38
|
-
fields,
|
|
39
47
|
data,
|
|
48
|
+
errors,
|
|
40
49
|
submitting,
|
|
50
|
+
fields,
|
|
41
51
|
handleChange,
|
|
42
52
|
handleSubmit
|
|
43
53
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CheckoutConfig, CustomerCreate, RequestError } from '@open-tender/types';
|
|
3
|
-
export declare const useSignUpForm: (loading:
|
|
2
|
+
import { CheckoutConfig, CustomerCreate, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useSignUpForm: (loading: RequestStatus, error: RequestError, signUp: (data: CustomerCreate, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
data: CustomerCreate;
|
|
6
6
|
errors: Record<string, string>;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { DateString, FirstTime, GroupOrderTime, Holidays, ISOString, Order, OrderTime, OrderTimeWithDate, RequestedAt, RevenueCenter, ServiceType, TimeInterval, TimeObject, Timezone, TimezonePython, ValidTimes, Weekday } from '@open-tender/types';
|
|
2
|
-
export declare const timezoneMap:
|
|
3
|
-
'US/Eastern': string;
|
|
4
|
-
'US/Central': string;
|
|
5
|
-
'US/Mountain': string;
|
|
6
|
-
'US/Pacific': string;
|
|
7
|
-
};
|
|
2
|
+
export declare const timezoneMap: Record<TimezonePython, Timezone>;
|
|
8
3
|
export declare const weekdays: string[];
|
|
9
4
|
export declare const weekdaysUpper: string[];
|
|
10
5
|
export declare const weekdaysLower: string[];
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLevelUpForm: (email: string, loading: RequestStatus, error: any, connect: (data: any, callback: any) => void, callback: any) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
data: any;
|
|
7
|
-
errors: {};
|
|
8
|
-
submitting: boolean;
|
|
9
|
-
handleChange: (evt?: any) => void;
|
|
10
|
-
handleSubmit: (evt?: any) => void;
|
|
11
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useLevelUpForm = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useLevelUpForm = (email, loading, error, connect, callback) => {
|
|
6
|
-
const submitRef = (0, react_1.useRef)(null);
|
|
7
|
-
const inputRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)({ email });
|
|
9
|
-
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
|
-
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
11
|
-
(0, react_1.useEffect)(() => {
|
|
12
|
-
var _a;
|
|
13
|
-
if (loading === 'idle') {
|
|
14
|
-
setSubmitting(false);
|
|
15
|
-
if (error) {
|
|
16
|
-
setErrors(error);
|
|
17
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}, [loading, error]);
|
|
21
|
-
const handleChange = (evt) => {
|
|
22
|
-
const { id, type, value, checked } = evt === null || evt === void 0 ? void 0 : evt.target;
|
|
23
|
-
const inputValue = type === 'checkbox' ? checked : value;
|
|
24
|
-
setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
|
|
25
|
-
};
|
|
26
|
-
const handleSubmit = (evt) => {
|
|
27
|
-
var _a;
|
|
28
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
29
|
-
setSubmitting(true);
|
|
30
|
-
connect(data, callback);
|
|
31
|
-
(_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
submitRef,
|
|
35
|
-
inputRef,
|
|
36
|
-
data,
|
|
37
|
-
errors,
|
|
38
|
-
submitting,
|
|
39
|
-
handleChange,
|
|
40
|
-
handleSubmit
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
exports.useLevelUpForm = useLevelUpForm;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useLevelUpForm: (email: string, loading: RequestStatus, error: any, connect: (data: any, callback: any) => void, callback: any) => {
|
|
4
|
-
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
data: any;
|
|
7
|
-
errors: {};
|
|
8
|
-
submitting: boolean;
|
|
9
|
-
handleChange: (evt?: any) => void;
|
|
10
|
-
handleSubmit: (evt?: any) => void;
|
|
11
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
export const useLevelUpForm = (email, loading, error, connect, callback) => {
|
|
3
|
-
const submitRef = useRef(null);
|
|
4
|
-
const inputRef = useRef(null);
|
|
5
|
-
const [data, setData] = useState({ email });
|
|
6
|
-
const [errors, setErrors] = useState({});
|
|
7
|
-
const [submitting, setSubmitting] = useState(false);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (loading === 'idle') {
|
|
11
|
-
setSubmitting(false);
|
|
12
|
-
if (error) {
|
|
13
|
-
setErrors(error);
|
|
14
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}, [loading, error]);
|
|
18
|
-
const handleChange = (evt) => {
|
|
19
|
-
const { id, type, value, checked } = evt === null || evt === void 0 ? void 0 : evt.target;
|
|
20
|
-
const inputValue = type === 'checkbox' ? checked : value;
|
|
21
|
-
setData(Object.assign(Object.assign({}, data), { [id]: inputValue }));
|
|
22
|
-
};
|
|
23
|
-
const handleSubmit = (evt) => {
|
|
24
|
-
var _a;
|
|
25
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
26
|
-
setSubmitting(true);
|
|
27
|
-
connect(data, callback);
|
|
28
|
-
(_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
submitRef,
|
|
32
|
-
inputRef,
|
|
33
|
-
data,
|
|
34
|
-
errors,
|
|
35
|
-
submitting,
|
|
36
|
-
handleChange,
|
|
37
|
-
handleSubmit
|
|
38
|
-
};
|
|
39
|
-
};
|