@open-tender/utils 0.0.57 → 0.0.59
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/types.d.ts +4 -0
- package/dist/cjs/hooks/types.js +2 -0
- package/dist/cjs/hooks/useAddressForm.d.ts +2 -5
- package/dist/cjs/hooks/useAddressForm.js +3 -3
- package/dist/cjs/hooks/useAllergenForm.d.ts +5 -2
- package/dist/cjs/hooks/useAllergenForm.js +8 -4
- package/dist/cjs/hooks/useCartGuestForm.d.ts +21 -0
- package/dist/cjs/hooks/useCartGuestForm.js +46 -0
- package/dist/cjs/hooks/useCheckoutLoginForm.d.ts +12 -0
- package/dist/cjs/hooks/useCheckoutLoginForm.js +41 -0
- package/dist/cjs/hooks/useCommunicationPreferences.d.ts +0 -0
- package/dist/cjs/hooks/useCommunicationPreferences.js +1 -0
- package/dist/cjs/hooks/useCreditCard.d.ts +8 -11
- package/dist/cjs/hooks/useCreditCard.js +61 -41
- package/dist/cjs/hooks/useDineInForm.d.ts +8 -3
- package/dist/cjs/hooks/useDineInForm.js +8 -2
- package/dist/cjs/hooks/useDonationForm.d.ts +4 -1
- package/dist/cjs/hooks/useDonationForm.js +17 -3
- package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +5 -7
- package/dist/cjs/hooks/useGiftCardAssignForm.js +11 -3
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +8 -0
- package/dist/cjs/hooks/useGiftCardForm.d.ts +9 -5
- package/dist/cjs/hooks/useGiftCardForm.js +13 -4
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +30 -11
- package/dist/cjs/hooks/useGiftCardsForm.js +72 -31
- package/dist/cjs/hooks/useGuestForm.d.ts +13 -0
- package/dist/cjs/hooks/useGuestForm.js +41 -0
- package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +13 -0
- package/dist/cjs/hooks/useOrderFulfillmentForm.js +40 -0
- package/dist/cjs/hooks/useOrderRatingForm.d.ts +13 -0
- package/dist/cjs/hooks/useOrderRatingForm.js +33 -0
- package/dist/cjs/hooks/useProfileForm.d.ts +18 -23
- package/dist/cjs/hooks/useProfileForm.js +27 -28
- package/dist/cjs/hooks/useResetPasswordForm.d.ts +20 -0
- package/dist/cjs/hooks/useResetPasswordForm.js +66 -0
- package/dist/cjs/hooks/useSendResetForm.d.ts +12 -0
- package/dist/cjs/hooks/useSendResetForm.js +36 -0
- package/dist/cjs/hooks/useSignUpForm.d.ts +21 -0
- package/dist/cjs/hooks/useSignUpForm.js +91 -0
- package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -0
- package/dist/cjs/hooks/useSignUpGuestForm.js +74 -0
- package/dist/cjs/hooks/useSigninForm.d.ts +12 -0
- package/dist/cjs/hooks/useSigninForm.js +41 -0
- package/dist/esm/hooks/types.d.ts +4 -0
- package/dist/esm/hooks/types.js +1 -0
- package/dist/esm/hooks/useAddressForm.d.ts +2 -5
- package/dist/esm/hooks/useAddressForm.js +3 -3
- package/dist/esm/hooks/useAllergenForm.d.ts +5 -2
- package/dist/esm/hooks/useAllergenForm.js +9 -5
- package/dist/esm/hooks/useCartGuestForm.d.ts +21 -0
- package/dist/esm/hooks/useCartGuestForm.js +44 -0
- package/dist/esm/hooks/useCheckoutLoginForm.d.ts +12 -0
- package/dist/esm/hooks/useCheckoutLoginForm.js +39 -0
- package/dist/esm/hooks/useCommunicationPreferences.d.ts +0 -0
- package/dist/esm/hooks/useCommunicationPreferences.js +1 -0
- package/dist/esm/hooks/useCreditCard.d.ts +8 -11
- package/dist/esm/hooks/useCreditCard.js +62 -42
- package/dist/esm/hooks/useDineInForm.d.ts +8 -3
- package/dist/esm/hooks/useDineInForm.js +9 -3
- package/dist/esm/hooks/useDonationForm.d.ts +4 -1
- package/dist/esm/hooks/useDonationForm.js +17 -3
- package/dist/esm/hooks/useGiftCardAssignForm.d.ts +5 -7
- package/dist/esm/hooks/useGiftCardAssignForm.js +12 -4
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +5 -1
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +9 -1
- package/dist/esm/hooks/useGiftCardForm.d.ts +9 -5
- package/dist/esm/hooks/useGiftCardForm.js +14 -5
- package/dist/esm/hooks/useGiftCardsForm.d.ts +30 -11
- package/dist/esm/hooks/useGiftCardsForm.js +73 -32
- package/dist/esm/hooks/useGuestForm.d.ts +13 -0
- package/dist/esm/hooks/useGuestForm.js +39 -0
- package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +13 -0
- package/dist/esm/hooks/useOrderFulfillmentForm.js +38 -0
- package/dist/esm/hooks/useOrderRatingForm.d.ts +13 -0
- package/dist/esm/hooks/useOrderRatingForm.js +31 -0
- package/dist/esm/hooks/useProfileForm.d.ts +18 -23
- package/dist/esm/hooks/useProfileForm.js +28 -29
- package/dist/esm/hooks/useResetPasswordForm.d.ts +20 -0
- package/dist/esm/hooks/useResetPasswordForm.js +64 -0
- package/dist/esm/hooks/useSendResetForm.d.ts +12 -0
- package/dist/esm/hooks/useSendResetForm.js +34 -0
- package/dist/esm/hooks/useSignUpForm.d.ts +21 -0
- package/dist/esm/hooks/useSignUpForm.js +89 -0
- package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -0
- package/dist/esm/hooks/useSignUpGuestForm.js +72 -0
- package/dist/esm/hooks/useSigninForm.d.ts +12 -0
- package/dist/esm/hooks/useSigninForm.js +39 -0
- package/package.json +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useResetPasswordForm = (loading, error, reset, resetForm, resetToken) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
7
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
8
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
9
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
10
|
+
const fields = [
|
|
11
|
+
{ label: 'New Password', name: 'new_password', type: 'password' },
|
|
12
|
+
{ label: 'Confirm Password', name: 'confirm', type: 'password' },
|
|
13
|
+
];
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
setData({});
|
|
16
|
+
setErrors({});
|
|
17
|
+
resetForm();
|
|
18
|
+
return () => {
|
|
19
|
+
setData({});
|
|
20
|
+
setErrors({});
|
|
21
|
+
resetForm();
|
|
22
|
+
};
|
|
23
|
+
}, [resetForm]);
|
|
24
|
+
(0, react_1.useEffect)(() => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
if (loading === 'idle') {
|
|
27
|
+
setSubmitting(false);
|
|
28
|
+
if (error) {
|
|
29
|
+
setErrors(error);
|
|
30
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [loading, error]);
|
|
34
|
+
const handleChange = (name, value) => {
|
|
35
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
36
|
+
};
|
|
37
|
+
const handleSubmit = () => {
|
|
38
|
+
var _a, _b, _c, _d, _e, _f;
|
|
39
|
+
const { new_password, confirm } = data;
|
|
40
|
+
if (!new_password || new_password.length < 8) {
|
|
41
|
+
setErrors({ new_password: 'Must be at least 8 characters' });
|
|
42
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
43
|
+
}
|
|
44
|
+
else if (new_password !== confirm) {
|
|
45
|
+
setErrors({ confirm: 'Passwords do not match' });
|
|
46
|
+
((_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.focus) && ((_d = inputRef.current) === null || _d === void 0 ? void 0 : _d.focus());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setErrors({});
|
|
50
|
+
setSubmitting(true);
|
|
51
|
+
reset(new_password, resetToken);
|
|
52
|
+
}
|
|
53
|
+
((_e = submitRef.current) === null || _e === void 0 ? void 0 : _e.blur) && ((_f = submitRef.current) === null || _f === void 0 ? void 0 : _f.blur());
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
submitRef,
|
|
57
|
+
inputRef,
|
|
58
|
+
fields,
|
|
59
|
+
data,
|
|
60
|
+
errors,
|
|
61
|
+
submitting,
|
|
62
|
+
handleChange,
|
|
63
|
+
handleSubmit,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.default = useResetPasswordForm;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useSendResetForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, error: any, sendReset: (email: string, linkUrl: string) => Promise<void>, callback?: () => void, windowref?: any, linkUrlVal?: string) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
7
|
+
data: any;
|
|
8
|
+
errMsg: any;
|
|
9
|
+
handleChange: (name: string, value: string) => void;
|
|
10
|
+
handleSubmit: () => void;
|
|
11
|
+
};
|
|
12
|
+
export default useSendResetForm;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useSendResetForm = (loading, error, sendReset, callback, windowref, linkUrlVal) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
7
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
8
|
+
const errMsg = error && error.email ? error.email : null;
|
|
9
|
+
(0, react_1.useEffect)(() => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
if (loading === 'idle' && error) {
|
|
12
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
13
|
+
}
|
|
14
|
+
}, [loading, error]);
|
|
15
|
+
const handleChange = (name, value) => {
|
|
16
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
17
|
+
};
|
|
18
|
+
const handleSubmit = () => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const linkUrl = windowref ? `${windowref.location.origin}/reset-password` : `${linkUrlVal}`;
|
|
21
|
+
sendReset(data.email, linkUrl).then(() => {
|
|
22
|
+
if (callback)
|
|
23
|
+
callback();
|
|
24
|
+
});
|
|
25
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
submitRef,
|
|
29
|
+
inputRef,
|
|
30
|
+
data,
|
|
31
|
+
errMsg,
|
|
32
|
+
handleChange,
|
|
33
|
+
handleSubmit,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.default = useSendResetForm;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CheckoutConfig, Profile } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
interface SignUpFormField {
|
|
5
|
+
label?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
autoComplete?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const useSignUpForm: <SubmitRef extends Field>(loading: RequestInfo, error: any, signUp: (data: any, callback?: () => void) => void, callback?: () => void, checkConfig?: Partial<CheckoutConfig>, hasThanx?: boolean) => {
|
|
12
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
13
|
+
data: Partial<Profile>;
|
|
14
|
+
errors: any;
|
|
15
|
+
submitting: boolean;
|
|
16
|
+
formfields: SignUpFormField[];
|
|
17
|
+
errMsg: string | null;
|
|
18
|
+
handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
19
|
+
handleSubmit: () => void;
|
|
20
|
+
};
|
|
21
|
+
export default useSignUpForm;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const utils_1 = require("@open-tender/utils");
|
|
5
|
+
const useSignUpForm = (loading, error, signUp, callback, checkConfig = {}, hasThanx = false) => {
|
|
6
|
+
const { displayed, required } = checkConfig || {};
|
|
7
|
+
const companyDisplayed = displayed && displayed.customer.includes('company');
|
|
8
|
+
const companyRequired = required && required.customer.includes('company');
|
|
9
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
10
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
11
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
12
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
13
|
+
const errMsg = error ? 'There are one or more errors below.' : null;
|
|
14
|
+
let fields = [
|
|
15
|
+
{
|
|
16
|
+
label: 'First Name',
|
|
17
|
+
name: 'first_name',
|
|
18
|
+
type: 'text',
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'Last Name',
|
|
23
|
+
name: 'last_name',
|
|
24
|
+
type: 'text',
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Email',
|
|
29
|
+
name: 'email',
|
|
30
|
+
type: 'email',
|
|
31
|
+
required: true,
|
|
32
|
+
autoComplete: 'email',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Password',
|
|
36
|
+
name: 'password',
|
|
37
|
+
type: 'password',
|
|
38
|
+
required: true,
|
|
39
|
+
autoComplete: 'new-password',
|
|
40
|
+
},
|
|
41
|
+
{ label: 'Phone', name: 'phone', type: 'tel', required: true },
|
|
42
|
+
];
|
|
43
|
+
if (companyDisplayed || companyRequired) {
|
|
44
|
+
const company = {
|
|
45
|
+
label: 'Company',
|
|
46
|
+
name: 'company',
|
|
47
|
+
type: 'text',
|
|
48
|
+
required: companyRequired,
|
|
49
|
+
};
|
|
50
|
+
fields = [...fields, company];
|
|
51
|
+
}
|
|
52
|
+
const formfields = hasThanx
|
|
53
|
+
? fields.filter((i) => i.name !== 'password')
|
|
54
|
+
: fields;
|
|
55
|
+
(0, react_1.useEffect)(() => {
|
|
56
|
+
return () => {
|
|
57
|
+
setData({});
|
|
58
|
+
setErrors({});
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
(0, react_1.useEffect)(() => {
|
|
62
|
+
if (loading === 'idle') {
|
|
63
|
+
setSubmitting(false);
|
|
64
|
+
if (error) {
|
|
65
|
+
setErrors(error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, [loading, error]);
|
|
69
|
+
const handleChange = (name, type, value, checked) => {
|
|
70
|
+
const inputValue = type === 'checkbox' ? checked : name === 'phone' ? (0, utils_1.makePhone)(value !== null && value !== void 0 ? value : "") : value;
|
|
71
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
72
|
+
};
|
|
73
|
+
const handleSubmit = () => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
setErrors({});
|
|
76
|
+
setSubmitting(true);
|
|
77
|
+
signUp(data, callback);
|
|
78
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
submitRef,
|
|
82
|
+
data,
|
|
83
|
+
errors,
|
|
84
|
+
submitting,
|
|
85
|
+
formfields,
|
|
86
|
+
errMsg,
|
|
87
|
+
handleChange,
|
|
88
|
+
handleSubmit,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.default = useSignUpForm;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GuestData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useSignUpGuestForm: <InputRef extends Field, SubmitRef extends Field>(email: string, guest: Partial<GuestData>, loading: RequestStatus, error: any, signUp: (data: any) => void, submitGuest: (data: Partial<GuestData>) => void, hasThanx?: boolean) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
7
|
+
data: {
|
|
8
|
+
first_name?: string | undefined;
|
|
9
|
+
email?: string | undefined;
|
|
10
|
+
last_name?: string | undefined;
|
|
11
|
+
phone?: string | undefined;
|
|
12
|
+
password?: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
guestDisabled: boolean;
|
|
16
|
+
errors: {};
|
|
17
|
+
errMsg: string | null;
|
|
18
|
+
submitting: boolean;
|
|
19
|
+
handleChange: (id: string, value: string) => void;
|
|
20
|
+
handleSubmit: () => void;
|
|
21
|
+
handleGuest: () => void;
|
|
22
|
+
};
|
|
23
|
+
export default useSignUpGuestForm;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const utils_1 = require("@open-tender/utils");
|
|
5
|
+
const initialData = {
|
|
6
|
+
first_name: '',
|
|
7
|
+
last_name: '',
|
|
8
|
+
phone: '',
|
|
9
|
+
password: '',
|
|
10
|
+
};
|
|
11
|
+
const useSignUpGuestForm = (email, guest, loading, error, signUp, submitGuest, hasThanx) => {
|
|
12
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
13
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
14
|
+
const initData = Object.assign(Object.assign({}, initialData), guest);
|
|
15
|
+
const [data, setData] = (0, react_1.useState)(initData);
|
|
16
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
17
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
18
|
+
const { guestData, guestIncomplete } = (0, utils_1.checkGuestData)(data, email);
|
|
19
|
+
const isIncomplete = hasThanx ? guestIncomplete : (0, utils_1.checkEmpty)(data);
|
|
20
|
+
const isLoading = loading === 'pending';
|
|
21
|
+
const disabled = isIncomplete || isLoading;
|
|
22
|
+
const guestDisabled = guestIncomplete || isLoading;
|
|
23
|
+
const errMsg = (error === null || error === void 0 ? void 0 : error.form) ? 'There are one or more errors below' : null;
|
|
24
|
+
const handleChange = (id, value) => {
|
|
25
|
+
const val = id === 'phone' ? (0, utils_1.makePhone)(value) : value;
|
|
26
|
+
setData(Object.assign(Object.assign({}, data), { [id]: val }));
|
|
27
|
+
};
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
return () => {
|
|
30
|
+
setData({});
|
|
31
|
+
setErrors({});
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
if (loading === 'idle') {
|
|
37
|
+
setSubmitting(false);
|
|
38
|
+
if (error) {
|
|
39
|
+
setErrors(error);
|
|
40
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, [loading, error]);
|
|
44
|
+
const handleSubmit = () => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (!disabled) {
|
|
47
|
+
setErrors({});
|
|
48
|
+
setSubmitting(true);
|
|
49
|
+
signUp(Object.assign(Object.assign({}, data), { email }));
|
|
50
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const handleGuest = () => {
|
|
54
|
+
if (!guestDisabled) {
|
|
55
|
+
setErrors({});
|
|
56
|
+
setSubmitting(true);
|
|
57
|
+
submitGuest(Object.assign(Object.assign({}, guestData), { email }));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
submitRef,
|
|
62
|
+
inputRef,
|
|
63
|
+
data,
|
|
64
|
+
disabled,
|
|
65
|
+
guestDisabled,
|
|
66
|
+
errors,
|
|
67
|
+
errMsg,
|
|
68
|
+
submitting,
|
|
69
|
+
handleChange,
|
|
70
|
+
handleSubmit,
|
|
71
|
+
handleGuest,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.default = useSignUpGuestForm;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LoginData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useSignInForm: <InputRef extends Field, SubmitRef extends Field>(email: string, loading: RequestStatus, error: any, login: (email?: string, password?: string) => void, callback?: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
7
|
+
data: Partial<LoginData>;
|
|
8
|
+
submitting: boolean;
|
|
9
|
+
handleChange: (name: string, value: string) => void;
|
|
10
|
+
handleSubmit: () => void;
|
|
11
|
+
};
|
|
12
|
+
export default useSignInForm;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const useSignInForm = (email, loading, error, login, callback) => {
|
|
5
|
+
const submitRef = (0, react_1.useRef)(null);
|
|
6
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
7
|
+
const [hasSubmit, setHasSubmit] = (0, react_1.useState)(false);
|
|
8
|
+
const [data, setData] = (0, react_1.useState)({ email });
|
|
9
|
+
const submitting = loading === 'pending';
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (loading === 'idle' && hasSubmit) {
|
|
13
|
+
if (error) {
|
|
14
|
+
setHasSubmit(false);
|
|
15
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
16
|
+
}
|
|
17
|
+
else if (callback) {
|
|
18
|
+
callback();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, [loading, error, hasSubmit, callback]);
|
|
22
|
+
const handleChange = (name, value) => {
|
|
23
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
24
|
+
};
|
|
25
|
+
const handleSubmit = () => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
setHasSubmit(true);
|
|
28
|
+
const { email, password } = data;
|
|
29
|
+
login(email, password);
|
|
30
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
submitRef,
|
|
34
|
+
inputRef,
|
|
35
|
+
data,
|
|
36
|
+
submitting,
|
|
37
|
+
handleChange,
|
|
38
|
+
handleSubmit,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.default = useSignInForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Address, RequestStatus } from '@open-tender/types';
|
|
3
|
-
|
|
4
|
-
blur?: () => void;
|
|
5
|
-
focus?: () => void;
|
|
6
|
-
}
|
|
3
|
+
import { Field } from './types';
|
|
7
4
|
interface AddressFormField {
|
|
8
5
|
label: string;
|
|
9
6
|
name: string;
|
|
@@ -15,7 +12,7 @@ export declare const useAddressForm: <InputRef extends Field, SubmitRef extends
|
|
|
15
12
|
data: Address;
|
|
16
13
|
errors: any;
|
|
17
14
|
submitting: boolean;
|
|
18
|
-
handleChange: (
|
|
15
|
+
handleChange: (name: string, type: string, value: string | null, checked: boolean | null) => void;
|
|
19
16
|
handleSubmit: () => void;
|
|
20
17
|
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
21
18
|
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
@@ -24,13 +24,13 @@ export const useAddressForm = (address, loading, error, update, callback) => {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}, [loading, error]);
|
|
27
|
-
const handleChange = (
|
|
27
|
+
const handleChange = (name, type, value, checked) => {
|
|
28
28
|
const inputValue = type === 'checkbox'
|
|
29
29
|
? checked
|
|
30
|
-
:
|
|
30
|
+
: name === 'phone'
|
|
31
31
|
? makePhone(value !== null && value !== void 0 ? value : '')
|
|
32
32
|
: value;
|
|
33
|
-
setData(Object.assign(Object.assign({}, data), { [
|
|
33
|
+
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
34
34
|
};
|
|
35
35
|
const handleSubmit = () => {
|
|
36
36
|
var _a, _b;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Allergen, Allergens } from '@open-tender/types';
|
|
2
|
-
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useAllergenForm: <SubmitRef extends Field>(allergens: Allergens, selectedAllergens: Allergens, isLoading: boolean | undefined, error: any, setAllergens: (allergens: Allergens) => void, updateAllergens: (allergen: Partial<Allergen>[]) => void, callback?: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
3
6
|
submitting: boolean;
|
|
4
7
|
allergenIds: number[];
|
|
5
8
|
formError: any;
|
|
6
|
-
handleChange: (
|
|
9
|
+
handleChange: (name: string, checked?: boolean) => void;
|
|
7
10
|
handleSubmit: () => void;
|
|
8
11
|
};
|
|
9
12
|
export default useAllergenForm;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error = null, setAllergens, updateAllergens, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
3
4
|
const [data, setData] = useState([]);
|
|
4
5
|
const [submitting, setSubmitting] = useState(false);
|
|
5
6
|
const allergenIds = data.map(i => i.allergen_id);
|
|
6
7
|
const formError = error ? error.detail || error.message : null;
|
|
7
8
|
useEffect(() => {
|
|
9
|
+
var _a, _b;
|
|
8
10
|
// uses isLoading boolean because loading state is based on
|
|
9
11
|
// both brand allergens and customer allergens loading
|
|
10
12
|
if (!isLoading) {
|
|
11
13
|
setSubmitting(false);
|
|
14
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
12
15
|
}
|
|
13
16
|
}, [isLoading]);
|
|
14
17
|
useEffect(() => {
|
|
15
18
|
setData(selectedAllergens || []);
|
|
16
19
|
}, [selectedAllergens, allergens]);
|
|
17
|
-
const handleChange = (
|
|
20
|
+
const handleChange = (name, checked) => {
|
|
18
21
|
const newData = checked
|
|
19
|
-
? [...data, { allergen_id: parseInt(
|
|
20
|
-
: data.filter(i => i.allergen_id !== parseInt(
|
|
22
|
+
? [...data, { allergen_id: parseInt(name) }]
|
|
23
|
+
: data.filter(i => i.allergen_id !== parseInt(name));
|
|
21
24
|
setData(newData);
|
|
22
25
|
};
|
|
23
26
|
const handleSubmit = () => {
|
|
@@ -27,11 +30,12 @@ const useAllergenForm = (allergens, selectedAllergens, isLoading = false, error
|
|
|
27
30
|
if (updateAllergens) {
|
|
28
31
|
updateAllergens(newData);
|
|
29
32
|
}
|
|
30
|
-
|
|
33
|
+
if (callback) {
|
|
31
34
|
callback();
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
37
|
return {
|
|
38
|
+
submitRef,
|
|
35
39
|
submitting,
|
|
36
40
|
allergenIds,
|
|
37
41
|
formError,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
interface CartGuestFormField {
|
|
5
|
+
label?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const useCartGuestForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, errMsg: string, cartId: number, joinCart: (data: any, callback?: any) => void) => {
|
|
11
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
12
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
13
|
+
fields: CartGuestFormField[];
|
|
14
|
+
data: {
|
|
15
|
+
cart_id?: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
submitting: boolean;
|
|
18
|
+
handleChange: (name: string, value: string) => void;
|
|
19
|
+
handleSubmit: () => void;
|
|
20
|
+
};
|
|
21
|
+
export default useCartGuestForm;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
const useCartGuestForm = (loading, errMsg, cartId, joinCart) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
5
|
+
const [data, setData] = useState({ cart_id: cartId });
|
|
6
|
+
const [submitting, setSubmitting] = useState(false);
|
|
7
|
+
const fields = [
|
|
8
|
+
{ label: 'First Name', name: 'first_name', type: 'text', required: true },
|
|
9
|
+
{ label: 'Last Name', name: 'last_name', type: 'text', required: true },
|
|
10
|
+
];
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
return () => {
|
|
13
|
+
setData({});
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (loading === 'idle') {
|
|
19
|
+
setSubmitting(false);
|
|
20
|
+
if (errMsg) {
|
|
21
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, [loading, errMsg]);
|
|
25
|
+
const handleChange = (name, value) => {
|
|
26
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
27
|
+
};
|
|
28
|
+
const handleSubmit = () => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
setSubmitting(true);
|
|
31
|
+
joinCart(data);
|
|
32
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
submitRef,
|
|
36
|
+
inputRef,
|
|
37
|
+
fields,
|
|
38
|
+
data,
|
|
39
|
+
submitting,
|
|
40
|
+
handleChange,
|
|
41
|
+
handleSubmit,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default useCartGuestForm;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LoginData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useLoginForm: <InputRef extends Field, SubmitRef extends Field>(loading: RequestStatus, error: any, login: (email?: string, password?: string) => void, callback?: () => void) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
inputRef: import("react").MutableRefObject<InputRef | null>;
|
|
7
|
+
data: Partial<LoginData>;
|
|
8
|
+
submitting: boolean;
|
|
9
|
+
handleChange: (name: string, value: string) => void;
|
|
10
|
+
handleSubmit: () => void;
|
|
11
|
+
};
|
|
12
|
+
export default useLoginForm;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
const useLoginForm = (loading, error, login, callback) => {
|
|
3
|
+
const submitRef = useRef(null);
|
|
4
|
+
const inputRef = useRef(null);
|
|
5
|
+
const [hasSubmit, setHasSubmit] = useState(false);
|
|
6
|
+
const [data, setData] = useState({});
|
|
7
|
+
const submitting = loading === 'pending';
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if (loading === 'idle' && hasSubmit) {
|
|
11
|
+
if (error) {
|
|
12
|
+
setHasSubmit(false);
|
|
13
|
+
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
14
|
+
}
|
|
15
|
+
else if (callback) {
|
|
16
|
+
callback();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, [loading, error, hasSubmit, callback]);
|
|
20
|
+
const handleChange = (name, value) => {
|
|
21
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
22
|
+
};
|
|
23
|
+
const handleSubmit = () => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
setHasSubmit(true);
|
|
26
|
+
const { email, password } = data;
|
|
27
|
+
login(email, password);
|
|
28
|
+
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
submitRef,
|
|
32
|
+
inputRef,
|
|
33
|
+
data,
|
|
34
|
+
submitting,
|
|
35
|
+
handleChange,
|
|
36
|
+
handleSubmit,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default useLoginForm;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CreditCardData } from '@open-tender/types';
|
|
3
|
-
|
|
2
|
+
import { CardType, CreditCardData, RequestStatus } from '@open-tender/types';
|
|
3
|
+
import { Field } from './types';
|
|
4
|
+
declare const useCreditCardForm: <SubmitRef extends Field>(loading: RequestStatus, error: any, data: CreditCardData, cardType: CardType, setErrors: (errors: any) => void, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string, revenue_center_id: number | null, windowRef?: Window) => {
|
|
5
|
+
submitRef: import("react").MutableRefObject<SubmitRef | null>;
|
|
6
|
+
recaptchaRef: import("react").MutableRefObject<any>;
|
|
4
7
|
data: CreditCardData;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
disabled: boolean | undefined;
|
|
8
|
-
setErrors: import("react").Dispatch<any>;
|
|
9
|
-
handleChange: (name: keyof CreditCardData, value: string) => void;
|
|
10
|
-
handleBlur: (name: keyof CreditCardData) => void;
|
|
11
|
-
handleReset: () => void;
|
|
12
|
-
isComplete: boolean;
|
|
8
|
+
submitting: boolean;
|
|
9
|
+
handleSubmit: () => void;
|
|
13
10
|
};
|
|
14
|
-
export default
|
|
11
|
+
export default useCreditCardForm;
|