@open-tender/utils 0.1.64 → 0.1.65
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,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { ConfigFulfillment, FormFields, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
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:
|
|
5
|
+
fields: FormFields;
|
|
6
6
|
data: OrderFulfillment;
|
|
7
7
|
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
@@ -16,9 +16,20 @@ const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, update, s
|
|
|
16
16
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
17
17
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
18
18
|
const empty = fulfillment ? Object.values(fulfillment).every(i => !i) : true;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const arrivalOnly = !empty && !showAllFields;
|
|
20
|
+
const hasArrived = data.has_arrived;
|
|
21
|
+
const allFields = arrivalOnly
|
|
22
|
+
? settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
23
|
+
: settings.fields;
|
|
24
|
+
const fields = allFields
|
|
25
|
+
.filter(i => i.name !== 'has_arrived')
|
|
26
|
+
.map(i => ({
|
|
27
|
+
label: i.label,
|
|
28
|
+
name: i.name,
|
|
29
|
+
placeholder: i.placeholder,
|
|
30
|
+
type: 'text',
|
|
31
|
+
disabled: hasArrived
|
|
32
|
+
}));
|
|
22
33
|
(0, react_1.useEffect)(() => {
|
|
23
34
|
if (loading === 'idle') {
|
|
24
35
|
setSubmitting(false);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ConfigFulfillment, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
2
|
+
import { ConfigFulfillment, FormFields, OrderFulfillment, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
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:
|
|
5
|
+
fields: FormFields;
|
|
6
6
|
data: OrderFulfillment;
|
|
7
7
|
errors: Record<string, string>;
|
|
8
8
|
submitting: boolean;
|
|
@@ -13,9 +13,20 @@ export const useOrderFulfillmentForm = (orderId, fulfillment, loading, error, up
|
|
|
13
13
|
const [errors, setErrors] = useState({});
|
|
14
14
|
const [submitting, setSubmitting] = useState(false);
|
|
15
15
|
const empty = fulfillment ? Object.values(fulfillment).every(i => !i) : true;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const arrivalOnly = !empty && !showAllFields;
|
|
17
|
+
const hasArrived = data.has_arrived;
|
|
18
|
+
const allFields = arrivalOnly
|
|
19
|
+
? settings.fields.filter(i => i.name.startsWith('arrival'))
|
|
20
|
+
: settings.fields;
|
|
21
|
+
const fields = allFields
|
|
22
|
+
.filter(i => i.name !== 'has_arrived')
|
|
23
|
+
.map(i => ({
|
|
24
|
+
label: i.label,
|
|
25
|
+
name: i.name,
|
|
26
|
+
placeholder: i.placeholder,
|
|
27
|
+
type: 'text',
|
|
28
|
+
disabled: hasArrived
|
|
29
|
+
}));
|
|
19
30
|
useEffect(() => {
|
|
20
31
|
if (loading === 'idle') {
|
|
21
32
|
setSubmitting(false);
|
package/package.json
CHANGED