@open-tender/utils 0.1.63 → 0.1.64
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,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment:
|
|
3
|
+
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: OrderFulfillment | null, loading: RequestStatus, error: RequestError, update: (orderId: number, data: OrderFulfillment) => void, settings: ConfigFulfillment, showAllFields?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
fields: import("@open-tender/types").ConfigFulfillmentField[]
|
|
6
|
-
data:
|
|
5
|
+
fields: import("@open-tender/types").ConfigFulfillmentField[];
|
|
6
|
+
data: OrderFulfillment;
|
|
7
7
|
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
9
|
-
handleChange: (name: string,
|
|
10
|
-
handleSubmit: (evt?:
|
|
9
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
10
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
11
|
};
|
|
@@ -3,25 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useOrderFulfillmentForm = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const initState = {
|
|
7
|
+
arrival_info: '',
|
|
8
|
+
has_arrived: false,
|
|
9
|
+
vehicle_color: '',
|
|
10
|
+
vehicle_id: '',
|
|
11
|
+
vehicle_type: ''
|
|
12
|
+
};
|
|
6
13
|
const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
7
14
|
const submitRef = (0, react_1.useRef)(null);
|
|
8
|
-
const [data, setData] = (0, react_1.useState)(
|
|
15
|
+
const [data, setData] = (0, react_1.useState)(fulfillment || initState);
|
|
16
|
+
const [errors, setErrors] = (0, react_1.useState)({});
|
|
9
17
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
10
|
-
const
|
|
11
|
-
const empty = Object.values(fulfillment).every(i => !i);
|
|
18
|
+
const empty = fulfillment ? Object.values(fulfillment).every(i => !i) : true;
|
|
12
19
|
const fields = !empty && !showAllFields
|
|
13
20
|
? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
14
21
|
: settings === null || settings === void 0 ? void 0 : settings.fields;
|
|
15
22
|
(0, react_1.useEffect)(() => {
|
|
16
|
-
if (loading === 'idle')
|
|
23
|
+
if (loading === 'idle') {
|
|
17
24
|
setSubmitting(false);
|
|
18
|
-
|
|
25
|
+
if (error) {
|
|
26
|
+
setErrors((0, utils_1.makeFormErrors)(error));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}, [loading, error]);
|
|
19
30
|
(0, react_1.useEffect)(() => {
|
|
20
|
-
|
|
31
|
+
if (fulfillment)
|
|
32
|
+
setData(fulfillment);
|
|
21
33
|
}, [fulfillment]);
|
|
22
|
-
const handleChange = (name,
|
|
23
|
-
|
|
24
|
-
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
34
|
+
const handleChange = (name, value) => {
|
|
35
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
25
36
|
};
|
|
26
37
|
const handleSubmit = (evt) => {
|
|
27
38
|
var _a, _b;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
-
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment:
|
|
3
|
+
export declare const useOrderFulfillmentForm: (orderId: number, fulfillment: OrderFulfillment | null, loading: RequestStatus, error: RequestError, update: (orderId: number, data: OrderFulfillment) => void, settings: ConfigFulfillment, showAllFields?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
5
|
-
fields: import("@open-tender/types").ConfigFulfillmentField[]
|
|
6
|
-
data:
|
|
5
|
+
fields: import("@open-tender/types").ConfigFulfillmentField[];
|
|
6
|
+
data: OrderFulfillment;
|
|
7
7
|
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
9
|
-
handleChange: (name: string,
|
|
10
|
-
handleSubmit: (evt?:
|
|
9
|
+
handleChange: (name: string, value: string | number | boolean) => void;
|
|
10
|
+
handleSubmit: (evt?: React.FormEvent<HTMLFormElement>) => void;
|
|
11
11
|
};
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { makeFormErrors } from '../utils';
|
|
3
|
+
const initState = {
|
|
4
|
+
arrival_info: '',
|
|
5
|
+
has_arrived: false,
|
|
6
|
+
vehicle_color: '',
|
|
7
|
+
vehicle_id: '',
|
|
8
|
+
vehicle_type: ''
|
|
9
|
+
};
|
|
3
10
|
export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, settings, showAllFields = false) => {
|
|
4
11
|
const submitRef = useRef(null);
|
|
5
|
-
const [data, setData] = useState(
|
|
12
|
+
const [data, setData] = useState(fulfillment || initState);
|
|
13
|
+
const [errors, setErrors] = useState({});
|
|
6
14
|
const [submitting, setSubmitting] = useState(false);
|
|
7
|
-
const
|
|
8
|
-
const empty = Object.values(fulfillment).every(i => !i);
|
|
15
|
+
const empty = fulfillment ? Object.values(fulfillment).every(i => !i) : true;
|
|
9
16
|
const fields = !empty && !showAllFields
|
|
10
17
|
? settings === null || settings === void 0 ? void 0 : settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
11
18
|
: settings === null || settings === void 0 ? void 0 : settings.fields;
|
|
12
19
|
useEffect(() => {
|
|
13
|
-
if (loading === 'idle')
|
|
20
|
+
if (loading === 'idle') {
|
|
14
21
|
setSubmitting(false);
|
|
15
|
-
|
|
22
|
+
if (error) {
|
|
23
|
+
setErrors(makeFormErrors(error));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, [loading, error]);
|
|
16
27
|
useEffect(() => {
|
|
17
|
-
|
|
28
|
+
if (fulfillment)
|
|
29
|
+
setData(fulfillment);
|
|
18
30
|
}, [fulfillment]);
|
|
19
|
-
const handleChange = (name,
|
|
20
|
-
|
|
21
|
-
setData(Object.assign(Object.assign({}, data), { [name]: inputValue }));
|
|
31
|
+
const handleChange = (name, value) => {
|
|
32
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
22
33
|
};
|
|
23
34
|
const handleSubmit = (evt) => {
|
|
24
35
|
var _a, _b;
|
package/package.json
CHANGED