@open-tender/utils 0.1.55 → 0.1.56
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/useGiftCardForm.d.ts +1 -1
- package/dist/cjs/hooks/useGuestForm.d.ts +7 -6
- package/dist/cjs/hooks/useGuestForm.js +22 -9
- package/dist/cjs/utils/helpers.d.ts +5 -5
- package/dist/cjs/utils/helpers.js +1 -1
- package/dist/esm/hooks/useGiftCardForm.d.ts +1 -1
- package/dist/esm/hooks/useGuestForm.d.ts +7 -6
- package/dist/esm/hooks/useGuestForm.js +22 -9
- package/dist/esm/utils/helpers.d.ts +5 -5
- package/dist/esm/utils/helpers.js +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export declare const useGiftCardForm: (creditCards: CreditCards, loading: Reques
|
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
7
7
|
data: GiftCardPurchase;
|
|
8
|
-
errors:
|
|
8
|
+
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
10
10
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
11
|
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useGuestForm: (email: string, loading: RequestStatus,
|
|
2
|
+
import { CheckoutFormCustomer, FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGuestForm: (email: string, loading: RequestStatus, error: RequestError, checkGuest: (email: string) => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: CheckoutFormCustomer;
|
|
8
|
+
errors: Record<string, string>;
|
|
8
9
|
submitting: boolean;
|
|
9
|
-
handleChange: (name: string, value: string) => void;
|
|
10
|
-
handleSubmit: (evt
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
11
12
|
};
|
|
@@ -2,19 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useGuestForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const useGuestForm = (email, loading, error, checkGuest) => {
|
|
6
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)({});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const [data, setData] = (0, react_1.useState)({ email });
|
|
10
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
11
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
+
const fields = [
|
|
13
|
+
{
|
|
14
|
+
label: 'Email',
|
|
15
|
+
name: 'email',
|
|
16
|
+
type: 'email'
|
|
17
|
+
}
|
|
18
|
+
];
|
|
11
19
|
(0, react_1.useEffect)(() => {
|
|
12
20
|
var _a, _b;
|
|
13
21
|
if (loading === 'idle') {
|
|
14
|
-
|
|
22
|
+
setSubmitting(false);
|
|
23
|
+
if (error) {
|
|
24
|
+
const errs = (0, utils_1.makeFormErrors)(error);
|
|
25
|
+
setErrors(errs);
|
|
15
26
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
|
-
}, [loading,
|
|
29
|
+
}, [loading, error]);
|
|
18
30
|
(0, react_1.useEffect)(() => {
|
|
19
31
|
if (email && data.email === undefined) {
|
|
20
32
|
setData({ email });
|
|
@@ -26,15 +38,16 @@ const useGuestForm = (email, loading, errors, checkGuest) => {
|
|
|
26
38
|
const handleSubmit = (evt) => {
|
|
27
39
|
var _a, _b;
|
|
28
40
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
if (data.email)
|
|
42
|
+
checkGuest(data.email);
|
|
31
43
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
32
44
|
};
|
|
33
45
|
return {
|
|
34
46
|
submitRef,
|
|
35
47
|
inputRef,
|
|
48
|
+
fields,
|
|
36
49
|
data,
|
|
37
|
-
|
|
50
|
+
errors,
|
|
38
51
|
submitting,
|
|
39
52
|
handleChange,
|
|
40
53
|
handleSubmit
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Announcements, ContentImages, DateString,
|
|
1
|
+
import { Announcements, CheckoutFormCustomer, ContentImages, DateString, Images, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
2
|
export declare const isString: (str: any) => boolean;
|
|
3
3
|
export declare const isObject: (obj: any) => boolean;
|
|
4
4
|
export declare const isEmpty: (obj?: object | null) => boolean;
|
|
@@ -16,11 +16,11 @@ export declare const slashesToDashes: (birthDate: string) => DateString | null;
|
|
|
16
16
|
export declare const dashesToSlashes: (birthDate?: string | null) => string | null;
|
|
17
17
|
export declare const validateEmail: (email: string) => boolean;
|
|
18
18
|
export declare const checkEmpty: (data: Record<string | number, unknown>) => boolean;
|
|
19
|
-
export declare const checkGuestData: (data:
|
|
19
|
+
export declare const checkGuestData: (data: CheckoutFormCustomer, email: string) => {
|
|
20
20
|
guestData: {
|
|
21
|
-
first_name: string;
|
|
22
|
-
last_name: string;
|
|
23
|
-
phone: string;
|
|
21
|
+
first_name: string | undefined;
|
|
22
|
+
last_name: string | undefined;
|
|
23
|
+
phone: string | undefined;
|
|
24
24
|
email: string;
|
|
25
25
|
};
|
|
26
26
|
guestIncomplete: boolean;
|
|
@@ -124,7 +124,7 @@ exports.checkEmpty = checkEmpty;
|
|
|
124
124
|
const checkGuestData = (data, email) => {
|
|
125
125
|
const { first_name, last_name, phone } = data;
|
|
126
126
|
const guestData = { first_name, last_name, phone, email };
|
|
127
|
-
const validPhone = (0, exports.validatePhone)(phone)
|
|
127
|
+
const validPhone = phone ? (0, exports.validatePhone)(phone) || null : null;
|
|
128
128
|
const guestIncomplete = (0, exports.checkEmpty)(Object.assign(Object.assign({}, guestData), { phone: validPhone }));
|
|
129
129
|
return { guestData, guestIncomplete };
|
|
130
130
|
};
|
|
@@ -5,7 +5,7 @@ export declare const useGiftCardForm: (creditCards: CreditCards, loading: Reques
|
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
fields: FormFields;
|
|
7
7
|
data: GiftCardPurchase;
|
|
8
|
-
errors:
|
|
8
|
+
errors: Record<string, string>;
|
|
9
9
|
submitting: boolean;
|
|
10
10
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
11
|
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const useGuestForm: (email: string, loading: RequestStatus,
|
|
2
|
+
import { CheckoutFormCustomer, FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGuestForm: (email: string, loading: RequestStatus, error: RequestError, checkGuest: (email: string) => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: CheckoutFormCustomer;
|
|
8
|
+
errors: Record<string, string>;
|
|
8
9
|
submitting: boolean;
|
|
9
|
-
handleChange: (name: string, value: string) => void;
|
|
10
|
-
handleSubmit: (evt
|
|
10
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
11
12
|
};
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
-
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
3
|
+
export const useGuestForm = (email, loading, error, checkGuest) => {
|
|
3
4
|
const submitRef = useRef(null);
|
|
4
5
|
const inputRef = useRef(null);
|
|
5
|
-
const [data, setData] = useState({});
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const [data, setData] = useState({ email });
|
|
7
|
+
const [errors, setErrors] = useState({});
|
|
8
|
+
const [submitting, setSubmitting] = useState(false);
|
|
9
|
+
const fields = [
|
|
10
|
+
{
|
|
11
|
+
label: 'Email',
|
|
12
|
+
name: 'email',
|
|
13
|
+
type: 'email'
|
|
14
|
+
}
|
|
15
|
+
];
|
|
8
16
|
useEffect(() => {
|
|
9
17
|
var _a, _b;
|
|
10
18
|
if (loading === 'idle') {
|
|
11
|
-
|
|
19
|
+
setSubmitting(false);
|
|
20
|
+
if (error) {
|
|
21
|
+
const errs = makeFormErrors(error);
|
|
22
|
+
setErrors(errs);
|
|
12
23
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
24
|
+
}
|
|
13
25
|
}
|
|
14
|
-
}, [loading,
|
|
26
|
+
}, [loading, error]);
|
|
15
27
|
useEffect(() => {
|
|
16
28
|
if (email && data.email === undefined) {
|
|
17
29
|
setData({ email });
|
|
@@ -23,15 +35,16 @@ export const useGuestForm = (email, loading, errors, checkGuest) => {
|
|
|
23
35
|
const handleSubmit = (evt) => {
|
|
24
36
|
var _a, _b;
|
|
25
37
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
if (data.email)
|
|
39
|
+
checkGuest(data.email);
|
|
28
40
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
29
41
|
};
|
|
30
42
|
return {
|
|
31
43
|
submitRef,
|
|
32
44
|
inputRef,
|
|
45
|
+
fields,
|
|
33
46
|
data,
|
|
34
|
-
|
|
47
|
+
errors,
|
|
35
48
|
submitting,
|
|
36
49
|
handleChange,
|
|
37
50
|
handleSubmit
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Announcements, ContentImages, DateString,
|
|
1
|
+
import { Announcements, CheckoutFormCustomer, ContentImages, DateString, Images, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
2
|
export declare const isString: (str: any) => boolean;
|
|
3
3
|
export declare const isObject: (obj: any) => boolean;
|
|
4
4
|
export declare const isEmpty: (obj?: object | null) => boolean;
|
|
@@ -16,11 +16,11 @@ export declare const slashesToDashes: (birthDate: string) => DateString | null;
|
|
|
16
16
|
export declare const dashesToSlashes: (birthDate?: string | null) => string | null;
|
|
17
17
|
export declare const validateEmail: (email: string) => boolean;
|
|
18
18
|
export declare const checkEmpty: (data: Record<string | number, unknown>) => boolean;
|
|
19
|
-
export declare const checkGuestData: (data:
|
|
19
|
+
export declare const checkGuestData: (data: CheckoutFormCustomer, email: string) => {
|
|
20
20
|
guestData: {
|
|
21
|
-
first_name: string;
|
|
22
|
-
last_name: string;
|
|
23
|
-
phone: string;
|
|
21
|
+
first_name: string | undefined;
|
|
22
|
+
last_name: string | undefined;
|
|
23
|
+
phone: string | undefined;
|
|
24
24
|
email: string;
|
|
25
25
|
};
|
|
26
26
|
guestIncomplete: boolean;
|
|
@@ -104,7 +104,7 @@ export const checkEmpty = (data) => {
|
|
|
104
104
|
export const checkGuestData = (data, email) => {
|
|
105
105
|
const { first_name, last_name, phone } = data;
|
|
106
106
|
const guestData = { first_name, last_name, phone, email };
|
|
107
|
-
const validPhone = validatePhone(phone)
|
|
107
|
+
const validPhone = phone ? validatePhone(phone) || null : null;
|
|
108
108
|
const guestIncomplete = checkEmpty(Object.assign(Object.assign({}, guestData), { phone: validPhone }));
|
|
109
109
|
return { guestData, guestIncomplete };
|
|
110
110
|
};
|
package/package.json
CHANGED