@open-mercato/core 0.6.6-develop.6529.1.e1de4b3f27 → 0.6.6-develop.6531.1.87e9d31db6
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/.turbo/turbo-build.log +1 -1
- package/dist/modules/dictionaries/fields/dictionary.js +56 -41
- package/dist/modules/dictionaries/fields/dictionary.js.map +2 -2
- package/dist/modules/entities/backend/entities/system/[entityId]/page.meta.js +1 -0
- package/dist/modules/entities/backend/entities/system/[entityId]/page.meta.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/page.js +49 -49
- package/dist/modules/entities/backend/entities/user/[entityId]/page.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/page.meta.js +1 -0
- package/dist/modules/entities/backend/entities/user/[entityId]/page.meta.js.map +2 -2
- package/dist/modules/sales/components/documents/AddressesSection.js +6 -2
- package/dist/modules/sales/components/documents/AddressesSection.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesDocumentForm.js +44 -0
- package/dist/modules/sales/components/documents/SalesDocumentForm.js.map +2 -2
- package/dist/modules/sales/components/documents/ShipmentDialog.js +59 -38
- package/dist/modules/sales/components/documents/ShipmentDialog.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/dictionaries/fields/dictionary.tsx +55 -32
- package/src/modules/dictionaries/i18n/de.json +2 -0
- package/src/modules/dictionaries/i18n/en.json +2 -0
- package/src/modules/dictionaries/i18n/es.json +2 -0
- package/src/modules/dictionaries/i18n/pl.json +2 -0
- package/src/modules/entities/backend/entities/system/[entityId]/page.meta.ts +1 -0
- package/src/modules/entities/backend/entities/user/[entityId]/page.meta.ts +1 -0
- package/src/modules/entities/backend/entities/user/[entityId]/page.tsx +51 -49
- package/src/modules/entities/i18n/de.json +34 -0
- package/src/modules/entities/i18n/en.json +34 -0
- package/src/modules/entities/i18n/es.json +34 -0
- package/src/modules/entities/i18n/pl.json +34 -0
- package/src/modules/sales/components/documents/AddressesSection.tsx +6 -2
- package/src/modules/sales/components/documents/SalesDocumentForm.tsx +46 -0
- package/src/modules/sales/components/documents/ShipmentDialog.tsx +65 -40
|
@@ -183,6 +183,10 @@ function ShipmentDialog({
|
|
|
183
183
|
const [addressOptions, setAddressOptions] = React.useState([]);
|
|
184
184
|
const [addressLoading, setAddressLoading] = React.useState(false);
|
|
185
185
|
const [addressError, setAddressError] = React.useState(null);
|
|
186
|
+
const addressLoadPromiseRef = React.useRef(null);
|
|
187
|
+
const currentAddressOrderIdRef = React.useRef(orderId);
|
|
188
|
+
currentAddressOrderIdRef.current = orderId;
|
|
189
|
+
const initializedDialogKeyRef = React.useRef(null);
|
|
186
190
|
const [documentStatuses, setDocumentStatuses] = React.useState([]);
|
|
187
191
|
const [lineStatuses, setLineStatuses] = React.useState([]);
|
|
188
192
|
const [shipmentStatuses, setShipmentStatuses] = React.useState([]);
|
|
@@ -340,35 +344,49 @@ function ShipmentDialog({
|
|
|
340
344
|
}),
|
|
341
345
|
[]
|
|
342
346
|
);
|
|
343
|
-
const loadAddressOptions = React.useCallback(
|
|
347
|
+
const loadAddressOptions = React.useCallback(() => {
|
|
348
|
+
const activeRequest = addressLoadPromiseRef.current;
|
|
349
|
+
if (activeRequest?.orderId === orderId) return activeRequest.promise;
|
|
344
350
|
setAddressLoading(true);
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
351
|
+
const request = (async () => {
|
|
352
|
+
try {
|
|
353
|
+
const params = new URLSearchParams({
|
|
354
|
+
page: "1",
|
|
355
|
+
pageSize: "100",
|
|
356
|
+
documentId: orderId,
|
|
357
|
+
documentKind: "order"
|
|
358
|
+
});
|
|
359
|
+
const response = await apiCall(
|
|
360
|
+
`/api/sales/document-addresses?${params.toString()}`,
|
|
361
|
+
void 0,
|
|
362
|
+
{ fallback: { items: [] } }
|
|
363
|
+
);
|
|
364
|
+
const items = Array.isArray(response.result?.items) ? response.result.items : [];
|
|
365
|
+
const mapped = items.map((item) => mapDocumentAddressOption(item)).filter((entry) => Boolean(entry));
|
|
366
|
+
const loadedOptions = dedupeAddressOptions([...baseAddressOptions, ...mapped]);
|
|
367
|
+
if (currentAddressOrderIdRef.current !== orderId) return baseAddressOptions;
|
|
368
|
+
mergeAddressOptions(loadedOptions);
|
|
369
|
+
setAddressError(null);
|
|
370
|
+
return loadedOptions;
|
|
371
|
+
} catch (err) {
|
|
372
|
+
logger.error("sales.shipments.addresses.load", { err });
|
|
373
|
+
if (currentAddressOrderIdRef.current === orderId) {
|
|
374
|
+
setAddressError(
|
|
375
|
+
t("sales.documents.shipments.addressLoadError", "Failed to load addresses.")
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return baseAddressOptions;
|
|
379
|
+
}
|
|
380
|
+
})();
|
|
381
|
+
addressLoadPromiseRef.current = { orderId, promise: request };
|
|
382
|
+
void request.then(() => {
|
|
383
|
+
if (addressLoadPromiseRef.current?.promise === request) {
|
|
384
|
+
addressLoadPromiseRef.current = null;
|
|
385
|
+
setAddressLoading(false);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
return request;
|
|
389
|
+
}, [baseAddressOptions, mapDocumentAddressOption, mergeAddressOptions, orderId, t]);
|
|
372
390
|
const buildPriceSubtitle = React.useCallback(
|
|
373
391
|
(option) => {
|
|
374
392
|
const currency = option.currencyCode ?? currencyCode ?? void 0;
|
|
@@ -638,16 +656,20 @@ function ShipmentDialog({
|
|
|
638
656
|
[renderStatusIcon, shipmentStatuses]
|
|
639
657
|
);
|
|
640
658
|
React.useEffect(() => {
|
|
641
|
-
if (!open)
|
|
659
|
+
if (!open) {
|
|
660
|
+
initializedDialogKeyRef.current = null;
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const dialogKey = `${orderId}:${mode}:${shipment?.id ?? "new"}`;
|
|
664
|
+
if (initializedDialogKeyRef.current === dialogKey) return;
|
|
665
|
+
initializedDialogKeyRef.current = dialogKey;
|
|
642
666
|
setFormResetKey((prev) => prev + 1);
|
|
643
667
|
if (!shippingMethods.length) {
|
|
644
668
|
void loadShippingMethods();
|
|
645
669
|
}
|
|
646
670
|
setAddressOptions(baseAddressOptions);
|
|
647
671
|
setAddressError(null);
|
|
648
|
-
|
|
649
|
-
void loadAddressOptions();
|
|
650
|
-
}
|
|
672
|
+
void loadAddressOptions();
|
|
651
673
|
if (!shipmentStatuses.length) {
|
|
652
674
|
void loadShipmentStatuses();
|
|
653
675
|
}
|
|
@@ -658,7 +680,6 @@ function ShipmentDialog({
|
|
|
658
680
|
void loadLineStatuses();
|
|
659
681
|
}
|
|
660
682
|
}, [
|
|
661
|
-
addressOptions.length,
|
|
662
683
|
baseAddressOptions,
|
|
663
684
|
documentStatuses.length,
|
|
664
685
|
loadAddressOptions,
|
|
@@ -668,6 +689,8 @@ function ShipmentDialog({
|
|
|
668
689
|
loadShippingMethods,
|
|
669
690
|
mode,
|
|
670
691
|
open,
|
|
692
|
+
orderId,
|
|
693
|
+
shipment?.id,
|
|
671
694
|
lineStatuses.length,
|
|
672
695
|
shipmentStatuses.length,
|
|
673
696
|
shippingMethods.length
|
|
@@ -718,11 +741,9 @@ function ShipmentDialog({
|
|
|
718
741
|
}, [baseAddressOptions, mergeAddressOptions, open]);
|
|
719
742
|
const fetchAddressItems = React.useCallback(
|
|
720
743
|
async (query) => {
|
|
721
|
-
|
|
722
|
-
await loadAddressOptions();
|
|
723
|
-
}
|
|
744
|
+
const options = addressOptions.length ? addressOptions : await loadAddressOptions();
|
|
724
745
|
const needle = query?.trim().toLowerCase() ?? "";
|
|
725
|
-
return
|
|
746
|
+
return options.filter((option) => {
|
|
726
747
|
if (!needle) return true;
|
|
727
748
|
return option.label.toLowerCase().includes(needle) || option.summary.toLowerCase().includes(needle);
|
|
728
749
|
}).map((option) => ({
|
|
@@ -732,7 +753,7 @@ function ShipmentDialog({
|
|
|
732
753
|
icon: /* @__PURE__ */ jsx("div", { className: "flex h-8 w-8 items-center justify-center rounded-md bg-muted text-muted-foreground", children: /* @__PURE__ */ jsx(MapPin, { className: "h-4 w-4" }) })
|
|
733
754
|
}));
|
|
734
755
|
},
|
|
735
|
-
[
|
|
756
|
+
[addressOptions, loadAddressOptions]
|
|
736
757
|
);
|
|
737
758
|
const validateItems = React.useCallback(
|
|
738
759
|
(itemsValue) => {
|