@open-tender/utils 0.1.52 → 0.1.54
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/useGiftCardAssignOtherForm.d.ts +9 -6
- package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +15 -6
- package/dist/cjs/hooks/useGiftCardForm.d.ts +5 -8
- package/dist/cjs/hooks/useGiftCardForm.js +18 -7
- package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +9 -6
- package/dist/esm/hooks/useGiftCardAssignOtherForm.js +15 -6
- package/dist/esm/hooks/useGiftCardForm.d.ts +5 -8
- package/dist/esm/hooks/useGiftCardForm.js +18 -7
- package/package.json +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useGiftCardAssignOtherForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardAssignOtherForm: (loading: RequestStatus, error: RequestError, giftCardId: number, assign: (id: number, email: string, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
errors: Record<string, string>;
|
|
8
11
|
submitting: boolean;
|
|
9
|
-
handleChange: (value: string) => void;
|
|
10
|
-
handleSubmit: (evt
|
|
12
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
11
14
|
};
|
|
@@ -2,36 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useGiftCardAssignOtherForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
5
6
|
const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback) => {
|
|
6
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
7
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [
|
|
9
|
+
const [data, setData] = (0, react_1.useState)({ email: '' });
|
|
9
10
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
10
11
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
12
|
+
const fields = [
|
|
13
|
+
{
|
|
14
|
+
label: 'Email',
|
|
15
|
+
name: 'email',
|
|
16
|
+
type: 'text'
|
|
17
|
+
}
|
|
18
|
+
];
|
|
11
19
|
(0, react_1.useEffect)(() => {
|
|
12
20
|
var _a, _b;
|
|
13
21
|
if (loading === 'idle') {
|
|
14
22
|
setSubmitting(false);
|
|
15
23
|
if (error) {
|
|
16
|
-
setErrors(error);
|
|
24
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
17
25
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
}, [loading, error]);
|
|
21
|
-
const handleChange = (value) => {
|
|
22
|
-
|
|
29
|
+
const handleChange = (name, value) => {
|
|
30
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
23
31
|
};
|
|
24
32
|
const handleSubmit = (evt) => {
|
|
25
33
|
var _a, _b;
|
|
26
34
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
27
35
|
setSubmitting(true);
|
|
28
|
-
assign(giftCardId, email, callback);
|
|
36
|
+
assign(giftCardId, data.email, callback);
|
|
29
37
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
30
38
|
};
|
|
31
39
|
return {
|
|
32
40
|
submitRef,
|
|
33
41
|
inputRef,
|
|
34
|
-
|
|
42
|
+
fields,
|
|
43
|
+
data,
|
|
35
44
|
errors,
|
|
36
45
|
submitting,
|
|
37
46
|
handleChange,
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CreditCards,
|
|
3
|
-
export declare const useGiftCardForm: (
|
|
2
|
+
import { CreditCards, FormFields, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardForm: (giftCardId: number, creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback: () => void) => void, add: (data: GiftCardPurchase, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
name: string;
|
|
8
|
-
value: number;
|
|
9
|
-
}[];
|
|
10
|
-
errors: {};
|
|
6
|
+
fields: FormFields;
|
|
11
7
|
data: GiftCardPurchase;
|
|
8
|
+
errors: {};
|
|
12
9
|
submitting: boolean;
|
|
13
10
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
14
|
-
handleSubmit: (evt
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
15
12
|
};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useGiftCardForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
const useGiftCardForm = (
|
|
6
|
+
const useGiftCardForm = (giftCardId, creditCards, loading, error, update, add, callback) => {
|
|
7
7
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
8
|
const inputRef = (0, react_1.useRef)(null);
|
|
9
9
|
const customerCardId = creditCards[0].customer_card_id;
|
|
@@ -16,9 +16,22 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
16
16
|
const options = creditCards.map(i => {
|
|
17
17
|
return {
|
|
18
18
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
19
|
-
value: i.customer_card_id
|
|
19
|
+
value: `${i.customer_card_id}`
|
|
20
20
|
};
|
|
21
21
|
});
|
|
22
|
+
const fields = [
|
|
23
|
+
{
|
|
24
|
+
label: 'Amount',
|
|
25
|
+
name: 'amount',
|
|
26
|
+
type: 'text'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Credit Card',
|
|
30
|
+
name: 'customer_card_id',
|
|
31
|
+
type: 'select',
|
|
32
|
+
options
|
|
33
|
+
}
|
|
34
|
+
];
|
|
22
35
|
(0, react_1.useEffect)(() => {
|
|
23
36
|
var _a, _b;
|
|
24
37
|
if (loading === 'idle') {
|
|
@@ -44,17 +57,15 @@ const useGiftCardForm = (giftCard, creditCards, loading, error, update, add, cal
|
|
|
44
57
|
data.customer_card_id = customerCardId;
|
|
45
58
|
}
|
|
46
59
|
data.customer_card_id = parseInt(`${data.customer_card_id}`);
|
|
47
|
-
|
|
48
|
-
? update(giftCard.gift_card_id, data, callback)
|
|
49
|
-
: add(data, callback);
|
|
60
|
+
giftCardId ? update(giftCardId, data, callback) : add(data, callback);
|
|
50
61
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
51
62
|
};
|
|
52
63
|
return {
|
|
53
64
|
submitRef,
|
|
54
65
|
inputRef,
|
|
55
|
-
|
|
56
|
-
errors,
|
|
66
|
+
fields,
|
|
57
67
|
data,
|
|
68
|
+
errors,
|
|
58
69
|
submitting,
|
|
59
70
|
handleChange,
|
|
60
71
|
handleSubmit
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useGiftCardAssignOtherForm: (loading: RequestStatus, error:
|
|
2
|
+
import { FormFields, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardAssignOtherForm: (loading: RequestStatus, error: RequestError, giftCardId: number, assign: (id: number, email: string, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
fields: FormFields;
|
|
7
|
+
data: {
|
|
8
|
+
email: string;
|
|
9
|
+
};
|
|
10
|
+
errors: Record<string, string>;
|
|
8
11
|
submitting: boolean;
|
|
9
|
-
handleChange: (value: string) => void;
|
|
10
|
-
handleSubmit: (evt
|
|
12
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
13
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
11
14
|
};
|
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { makeFormErrors } from '../utils';
|
|
2
3
|
export const useGiftCardAssignOtherForm = (loading, error, giftCardId, assign, callback) => {
|
|
3
4
|
const submitRef = useRef(null);
|
|
4
5
|
const inputRef = useRef(null);
|
|
5
|
-
const [
|
|
6
|
+
const [data, setData] = useState({ email: '' });
|
|
6
7
|
const [errors, setErrors] = useState({});
|
|
7
8
|
const [submitting, setSubmitting] = useState(false);
|
|
9
|
+
const fields = [
|
|
10
|
+
{
|
|
11
|
+
label: 'Email',
|
|
12
|
+
name: 'email',
|
|
13
|
+
type: 'text'
|
|
14
|
+
}
|
|
15
|
+
];
|
|
8
16
|
useEffect(() => {
|
|
9
17
|
var _a, _b;
|
|
10
18
|
if (loading === 'idle') {
|
|
11
19
|
setSubmitting(false);
|
|
12
20
|
if (error) {
|
|
13
|
-
setErrors(error);
|
|
21
|
+
setErrors(makeFormErrors(error));
|
|
14
22
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
15
23
|
}
|
|
16
24
|
}
|
|
17
25
|
}, [loading, error]);
|
|
18
|
-
const handleChange = (value) => {
|
|
19
|
-
|
|
26
|
+
const handleChange = (name, value) => {
|
|
27
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
20
28
|
};
|
|
21
29
|
const handleSubmit = (evt) => {
|
|
22
30
|
var _a, _b;
|
|
23
31
|
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
24
32
|
setSubmitting(true);
|
|
25
|
-
assign(giftCardId, email, callback);
|
|
33
|
+
assign(giftCardId, data.email, callback);
|
|
26
34
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
27
35
|
};
|
|
28
36
|
return {
|
|
29
37
|
submitRef,
|
|
30
38
|
inputRef,
|
|
31
|
-
|
|
39
|
+
fields,
|
|
40
|
+
data,
|
|
32
41
|
errors,
|
|
33
42
|
submitting,
|
|
34
43
|
handleChange,
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CreditCards,
|
|
3
|
-
export declare const useGiftCardForm: (
|
|
2
|
+
import { CreditCards, FormFields, GiftCardPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardForm: (giftCardId: number, creditCards: CreditCards, loading: RequestStatus, error: RequestError, update: (id: number, data: GiftCardPurchase, callback: () => void) => void, add: (data: GiftCardPurchase, callback: () => void) => void, callback: () => void) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
|
-
|
|
7
|
-
name: string;
|
|
8
|
-
value: number;
|
|
9
|
-
}[];
|
|
10
|
-
errors: {};
|
|
6
|
+
fields: FormFields;
|
|
11
7
|
data: GiftCardPurchase;
|
|
8
|
+
errors: {};
|
|
12
9
|
submitting: boolean;
|
|
13
10
|
handleChange: (name: string, value: string | number | boolean) => void;
|
|
14
|
-
handleSubmit: (evt
|
|
11
|
+
handleSubmit: (evt: React.FormEvent<HTMLFormElement>) => void;
|
|
15
12
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors } from '../utils';
|
|
3
|
-
export const useGiftCardForm = (
|
|
3
|
+
export const useGiftCardForm = (giftCardId, creditCards, loading, error, update, add, callback) => {
|
|
4
4
|
const submitRef = useRef(null);
|
|
5
5
|
const inputRef = useRef(null);
|
|
6
6
|
const customerCardId = creditCards[0].customer_card_id;
|
|
@@ -13,9 +13,22 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
|
|
|
13
13
|
const options = creditCards.map(i => {
|
|
14
14
|
return {
|
|
15
15
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
16
|
-
value: i.customer_card_id
|
|
16
|
+
value: `${i.customer_card_id}`
|
|
17
17
|
};
|
|
18
18
|
});
|
|
19
|
+
const fields = [
|
|
20
|
+
{
|
|
21
|
+
label: 'Amount',
|
|
22
|
+
name: 'amount',
|
|
23
|
+
type: 'text'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: 'Credit Card',
|
|
27
|
+
name: 'customer_card_id',
|
|
28
|
+
type: 'select',
|
|
29
|
+
options
|
|
30
|
+
}
|
|
31
|
+
];
|
|
19
32
|
useEffect(() => {
|
|
20
33
|
var _a, _b;
|
|
21
34
|
if (loading === 'idle') {
|
|
@@ -41,17 +54,15 @@ export const useGiftCardForm = (giftCard, creditCards, loading, error, update, a
|
|
|
41
54
|
data.customer_card_id = customerCardId;
|
|
42
55
|
}
|
|
43
56
|
data.customer_card_id = parseInt(`${data.customer_card_id}`);
|
|
44
|
-
|
|
45
|
-
? update(giftCard.gift_card_id, data, callback)
|
|
46
|
-
: add(data, callback);
|
|
57
|
+
giftCardId ? update(giftCardId, data, callback) : add(data, callback);
|
|
47
58
|
((_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.blur) && ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur());
|
|
48
59
|
};
|
|
49
60
|
return {
|
|
50
61
|
submitRef,
|
|
51
62
|
inputRef,
|
|
52
|
-
|
|
53
|
-
errors,
|
|
63
|
+
fields,
|
|
54
64
|
data,
|
|
65
|
+
errors,
|
|
55
66
|
submitting,
|
|
56
67
|
handleChange,
|
|
57
68
|
handleSubmit
|
package/package.json
CHANGED