@open-tender/utils 0.1.52 → 0.1.53
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,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,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,
|
package/package.json
CHANGED