@mercurjs/vendor 2.2.0-canary.13 → 2.2.0-canary.14
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/{[id]-RFEYRBLI.js → [id]-2TI2PRRJ.js} +12 -12
- package/dist/{[id]-J6BZG5PU.js → [id]-ASXERAZ4.js} +3 -3
- package/dist/{[id]-ET35KT2M.js → [id]-CDA4INC4.js} +5 -5
- package/dist/{[id]-ZMLS73X5.js → [id]-DZC5AXL5.js} +11 -11
- package/dist/{[id]-YZSVSJWU.js → [id]-IBI7RQ5U.js} +10 -10
- package/dist/{[id]-IW2AZE77.js → [id]-JMO5ONLU.js} +13 -13
- package/dist/{[id]-FALIOGXK.js → [id]-KZ4AUWKS.js} +12 -12
- package/dist/{[id]-GY5R652O.js → [id]-NGAIPW6P.js} +12 -12
- package/dist/{[id]-US6IULL2.js → [id]-OQ2LU74O.js} +53 -24
- package/dist/{[id]-OTK2NOXT.js → [id]-WFTES472.js} +11 -11
- package/dist/{[id]-IGQTT3AM.js → [id]-WLX5IYWH.js} +11 -11
- package/dist/{[id]-PEUI67SP.js → [id]-Z47IMQRW.js} +2 -2
- package/dist/{[province_id]-J3OB2LZ4.js → [province_id]-24DPO3NE.js} +11 -11
- package/dist/{add-RU3WL4YB.js → add-KHYOS24M.js} +3 -3
- package/dist/{add-XEUXK63F.js → add-RK7LC7HS.js} +13 -13
- package/dist/{add-customer-groups-HZNWWRVG.js → add-customer-groups-IYXY4KM4.js} +10 -10
- package/dist/{add-products-E5GULF6B.js → add-products-GX5Z63TJ.js} +11 -11
- package/dist/{add-promotions-KW5YZHLS.js → add-promotions-HDJ7XR6Z.js} +5 -5
- package/dist/{address-6T4H6P7O.js → address-X5L7Q2VF.js} +8 -8
- package/dist/{adjust-inventory-AFJLWF5R.js → adjust-inventory-MCPV25XO.js} +1 -1
- package/dist/allocate-items-HI7KLPIB.js +654 -0
- package/dist/{areas-XUC5V5UO.js → areas-IHZROM6V.js} +3 -3
- package/dist/{attributes-SZP2MM5L.js → attributes-2JXH2BT2.js} +1 -1
- package/dist/{breadcrumb-L3MFH4I2.js → breadcrumb-4CK7LE6V.js} +1 -1
- package/dist/{breadcrumb-IK6XCQOQ.js → breadcrumb-6MIWWTK2.js} +2 -2
- package/dist/{breadcrumb-ZMACILH3.js → breadcrumb-DCWCXAFT.js} +2 -2
- package/dist/{breadcrumb-LKLWHB63.js → breadcrumb-NNFO7JCI.js} +9 -9
- package/dist/{breadcrumb-PBR27GGX.js → breadcrumb-PEKYMNVH.js} +2 -2
- package/dist/{breadcrumb-5HYIEPCL.js → breadcrumb-PV4XAZQW.js} +8 -8
- package/dist/{breadcrumb-KTARIL65.js → breadcrumb-PZCTXZ7Y.js} +2 -2
- package/dist/{breadcrumb-HL7NKNX4.js → breadcrumb-T5AIM6N3.js} +8 -8
- package/dist/{breadcrumb-FPWBT76A.js → breadcrumb-VOZAYLW3.js} +2 -2
- package/dist/{breadcrumb-2XA2WOK7.js → breadcrumb-XDTRPJYA.js} +1 -1
- package/dist/{campaigns-JAQTSA4Z.js → campaigns-4I2T6EDZ.js} +3 -3
- package/dist/{categories-T4QJYX4R.js → categories-LGV4X26B.js} +5 -5
- package/dist/{chunk-QLBIBLOY.js → chunk-22CIYLKO.js} +1 -1
- package/dist/{chunk-T5MJWWDX.js → chunk-2H4FGZ4U.js} +1 -1
- package/dist/{chunk-YHIJCI4U.js → chunk-2XOEFFYB.js} +2 -2
- package/dist/{chunk-PAVZ6FPK.js → chunk-3Z46N7A4.js} +4 -3
- package/dist/{chunk-YPTJETJQ.js → chunk-4NQJN4KR.js} +1 -1
- package/dist/{chunk-VAOJVT7R.js → chunk-5EIRIDGB.js} +2 -2
- package/dist/{chunk-VDHW6H5F.js → chunk-5QG6P6EU.js} +1 -1
- package/dist/{chunk-SIEEMXNZ.js → chunk-5ZJE3O2T.js} +1 -1
- package/dist/{chunk-4WCPN4OA.js → chunk-6EATIA34.js} +1 -1
- package/dist/{chunk-JAUZ73XE.js → chunk-6ORRPSPG.js} +3 -0
- package/dist/{chunk-KIFSQOM2.js → chunk-6QS6IZC6.js} +1 -1
- package/dist/{chunk-463CNCJC.js → chunk-7DDRUUXI.js} +2 -2
- package/dist/{chunk-GAE6TKOR.js → chunk-7GKAK7SG.js} +2 -4
- package/dist/{chunk-3PMM6AMP.js → chunk-AG6KIAUD.js} +1 -1
- package/dist/{chunk-DDJQRV6E.js → chunk-AQ7HHCHJ.js} +1 -1
- package/dist/{chunk-KJWVLGXG.js → chunk-AUMAF6RS.js} +5 -5
- package/dist/{chunk-A6QH53CS.js → chunk-BSBEIZPO.js} +7 -6
- package/dist/{chunk-LARLBYU6.js → chunk-CCGKFRKX.js} +1 -1
- package/dist/{chunk-BXRNZS5K.js → chunk-D2KMKWPI.js} +1 -1
- package/dist/chunk-EXRCJ2KI.js +33 -0
- package/dist/{chunk-BPVMJN2D.js → chunk-FQKVJALF.js} +5 -5
- package/dist/{chunk-STWHJLVV.js → chunk-FW6NLFW2.js} +1 -1
- package/dist/{chunk-AQTEEQWX.js → chunk-GDME2OBZ.js} +1 -1
- package/dist/{chunk-UDOBGAP7.js → chunk-GXZTYSQA.js} +1 -1
- package/dist/{chunk-VMFC2UDJ.js → chunk-HDPP7NAH.js} +3 -3
- package/dist/{chunk-DQKK43PR.js → chunk-ITEXO6BI.js} +2 -2
- package/dist/{chunk-5T6UWTRU.js → chunk-IV57G2CB.js} +19 -11
- package/dist/{chunk-IBEUR3J7.js → chunk-JI5BZTBK.js} +2 -2
- package/dist/{chunk-MVYAN2RR.js → chunk-K5H7FQPJ.js} +202 -474
- package/dist/{chunk-6OUPJNYO.js → chunk-KCHYLLVG.js} +2 -2
- package/dist/{chunk-ZBSFGCWY.js → chunk-MGKFVZFH.js} +2 -2
- package/dist/{chunk-ZPH3WXJ6.js → chunk-MQ7AZH5E.js} +1 -1
- package/dist/{chunk-TF6V3TFG.js → chunk-N7RHA7GE.js} +1 -1
- package/dist/{chunk-5YCDZ4AU.js → chunk-NN7E6UBM.js} +1 -2
- package/dist/{chunk-2QTNCGKX.js → chunk-NXSUJYZ4.js} +1 -1
- package/dist/{chunk-TW324MAT.js → chunk-PR4GU3GB.js} +1 -1
- package/dist/{chunk-Y2MQ5EMD.js → chunk-QCAMAXTE.js} +1 -1
- package/dist/{chunk-7CMRFP5Q.js → chunk-QS35HWC5.js} +1 -1
- package/dist/{chunk-U6PBLMXD.js → chunk-REUNEGSN.js} +3 -0
- package/dist/{chunk-DEJIBIQZ.js → chunk-RIF5X77T.js} +3 -3
- package/dist/{chunk-J7ZU2HZZ.js → chunk-SL4HFNPH.js} +2 -2
- package/dist/{chunk-5QI3NDJG.js → chunk-TFGWDC2N.js} +1 -1
- package/dist/{chunk-6FUIK3PX.js → chunk-U6AAK4OP.js} +3 -3
- package/dist/{chunk-R5QZO3QY.js → chunk-UZQKGNIW.js} +1 -1
- package/dist/{chunk-6UZERVBI.js → chunk-VKMU4ONH.js} +1 -1
- package/dist/{chunk-SSUUT5LK.js → chunk-WKRW5OPL.js} +1 -1
- package/dist/{chunk-XCIMOIX6.js → chunk-XBKWFLJG.js} +1 -1
- package/dist/{chunk-UFFVRF4V.js → chunk-Y34BG5JZ.js} +1 -1
- package/dist/{chunk-SJT6A4AV.js → chunk-YMDSGETV.js} +4 -4
- package/dist/{chunk-VZUA5SRD.js → chunk-Z2OUSXGV.js} +1 -1
- package/dist/{collections-HO2F62RN.js → collections-R7DDMVEO.js} +13 -13
- package/dist/{configuration-7IYZ6GNP.js → configuration-O6BMBYJZ.js} +2 -2
- package/dist/{create-DB4EYPJ5.js → create-5NSIF5BL.js} +8 -8
- package/dist/{create-J5OLH7OJ.js → create-5T2D7D4M.js} +8 -8
- package/dist/create-AP4P3L3F.js +216 -0
- package/dist/{create-FBPPNBLQ.js → create-C5VKLWPC.js} +8 -8
- package/dist/{create-WQ5TM5IZ.js → create-E75FI4OZ.js} +6 -6
- package/dist/{create-QZBCYHHQ.js → create-G2IW6LIT.js} +15 -15
- package/dist/{create-7EVR4N6N.js → create-G5DHEV55.js} +7 -7
- package/dist/{create-EFMCNOR5.js → create-IJDGWFHH.js} +12 -12
- package/dist/{create-SLJ2BMH7.js → create-JQSABIR4.js} +13 -13
- package/dist/{create-MZYXMGKP.js → create-OKYCDS6U.js} +3 -3
- package/dist/{create-TKXH5KQY.js → create-SHDZQLXT.js} +1 -1
- package/dist/{create-F5R76QML.js → create-VH33IROG.js} +5 -5
- package/dist/{create-QAEOARJO.js → create-VWZMWLSB.js} +8 -8
- package/dist/{customers-SOLJ2KQQ.js → customers-PPCUFKDS.js} +3 -3
- package/dist/{edit-G57GESSR.js → edit-3HTGOJCC.js} +6 -6
- package/dist/{edit-WPX2ANVI.js → edit-66N4HDDX.js} +8 -8
- package/dist/{edit-FXNXTVIW.js → edit-CDSNMD4A.js} +2 -2
- package/dist/{edit-YW4RBDPH.js → edit-IOM4RMSJ.js} +10 -10
- package/dist/{edit-RJE7L3PH.js → edit-KP5W2WAX.js} +8 -8
- package/dist/{edit-XSICGAVO.js → edit-M5KYT35E.js} +2 -2
- package/dist/{edit-3O6WVIMM.js → edit-QM7LQGYO.js} +10 -10
- package/dist/{edit-PUZ23M7V.js → edit-SY3POWMU.js} +2 -2
- package/dist/{edit-TIRMXOLT.js → edit-TNLEIQJX.js} +10 -10
- package/dist/{edit-W6WKYNOG.js → edit-WHRMHGLX.js} +13 -13
- package/dist/{edit-PVJ3S4TW.js → edit-XZL6WZRK.js} +8 -8
- package/dist/{edit-inventory-item-ZKXXL3QK.js → edit-inventory-item-EQRH4IH7.js} +1 -1
- package/dist/{edit-inventory-item-attributes-GSKUMORD.js → edit-inventory-item-attributes-J3NRDMGO.js} +1 -1
- package/dist/{edit-price-5ICQPJ42.js → edit-price-BVHSQFEU.js} +2 -2
- package/dist/{edit-stock-KS2NFC2Z.js → edit-stock-Y4KJHMYJ.js} +2 -2
- package/dist/{fulfillment-ZV2R43N2.js → fulfillment-FU5QETOZ.js} +8 -8
- package/dist/{fulfillment-providers-KKCL25KA.js → fulfillment-providers-XOXXACFQ.js} +11 -11
- package/dist/index.css +21 -4
- package/dist/index.js +152 -148
- package/dist/{inventory-5UNDKYDL.js → inventory-FCP7K3G3.js} +2 -2
- package/dist/{inventory-WSFLTA6Z.js → inventory-ILMHOB43.js} +4 -4
- package/dist/{invite-P7I5BGOJ.js → invite-HSK2XQRX.js} +11 -11
- package/dist/{invite-KKIJNMER.js → invite-QLA3ZZLF.js} +11 -11
- package/dist/{loader-WEJZTX5Q.js → loader-2X7OWRHW.js} +2 -2
- package/dist/{loader-UZTTBKYF.js → loader-R5KO7E6G.js} +1 -1
- package/dist/{login-A65IAXSI.js → login-7GCYZIPX.js} +9 -9
- package/dist/{manage-locations-XHH5DVIR.js → manage-locations-BGOYWQEM.js} +1 -1
- package/dist/{media-EM3K4AWO.js → media-CYFQMAEX.js} +11 -11
- package/dist/media-QMQ27X4G.js +314 -0
- package/dist/{metadata-JFLFWXOS.js → metadata-43O67QUY.js} +8 -8
- package/dist/{metadata-A5XZKPL4.js → metadata-DBVAS7ZM.js} +8 -8
- package/dist/{metadata-USXOQUIX.js → metadata-HDA6BLVR.js} +8 -8
- package/dist/{metadata-SFO3J5O5.js → metadata-IIN4NLRH.js} +8 -8
- package/dist/{metadata-WJ4CNB6I.js → metadata-KMWGUE7G.js} +8 -8
- package/dist/{offer-create-page-3PIJXHWZ.js → offer-create-page-FHT4JKVU.js} +14 -14
- package/dist/{offer-detail-page-SPHP3XKC.js → offer-detail-page-ZZLNGK27.js} +4 -5
- package/dist/{offer-variant-detail-page-KTHKV6WW.js → offer-variant-detail-page-ZYLRLCUO.js} +4 -4
- package/dist/{offers-GWMIEPCM.js → offers-ZM3AEZNM.js} +12 -12
- package/dist/{onboarding-JOGRNDPI.js → onboarding-SLDOWDFW.js} +8 -8
- package/dist/{orders-Q2IKEJIM.js → orders-2L73IOGC.js} +13 -13
- package/dist/{organization-HRYDC66D.js → organization-A4IG4WAR.js} +9 -9
- package/dist/{organize-5XRZWD5C.js → organize-STHGGW6P.js} +3 -3
- package/dist/{organize-Z7JTTDH4.js → organize-YQUFBBJY.js} +3 -3
- package/dist/pages/index.js +41 -41
- package/dist/{payment-details-YLPIR52N.js → payment-details-DBRT7W2N.js} +8 -8
- package/dist/{payouts-7Q7D4FET.js → payouts-D4A4CILI.js} +3 -3
- package/dist/{price-lists-6TFLA53G.js → price-lists-GO3BESTP.js} +6 -6
- package/dist/{pricing-ECJH4VXZ.js → pricing-2YFK2AR5.js} +8 -8
- package/dist/{pricing-EPNQ63NT.js → pricing-MQBWOWKW.js} +2 -2
- package/dist/{product-tags-WMC7G3C4.js → product-tags-AQN35DDX.js} +13 -13
- package/dist/{product-types-PKUEL7X5.js → product-types-XXU7X42K.js} +3 -3
- package/dist/product-variant-detail-4Q4YCN3E.js +369 -0
- package/dist/{product-variant-edit-GACQHD46.js → product-variant-edit-7OCP6ZT7.js} +1 -1
- package/dist/{products-PQ3FG5KC.js → products-FGL7RHWE.js} +11 -11
- package/dist/{products-LGQMESEZ.js → products-K2OPKRB2.js} +19 -19
- package/dist/{professional-details-AASVGTUO.js → professional-details-IPTTXX52.js} +8 -8
- package/dist/{profile-ZNQEDSDM.js → profile-7AUYSTIZ.js} +8 -8
- package/dist/{promotions-MFAFFHF3.js → promotions-75P5F3ZB.js} +6 -6
- package/dist/{receive-224KLULH.js → receive-4IQGDJZU.js} +3 -3
- package/dist/{refund-IGMSXQNX.js → refund-BVIKFQVS.js} +3 -3
- package/dist/{register-3A6G6QNI.js → register-CUKIMHHO.js} +10 -10
- package/dist/{reset-password-FV5762CA.js → reset-password-MVLTJWIR.js} +1 -1
- package/dist/{return-reasons-QJRA2ZX6.js → return-reasons-WAS4YMAP.js} +3 -3
- package/dist/{sales-channels-CZDU7VTE.js → sales-channels-E6OYLORW.js} +2 -2
- package/dist/{sales-channels-U55MUDQP.js → sales-channels-NNQGBEEH.js} +2 -2
- package/dist/{settings-OKNGWUKL.js → settings-4OJUBMGV.js} +19 -19
- package/dist/{shipment-ZF7IRKKS.js → shipment-2UN3V3OO.js} +8 -8
- package/dist/{shipping-HWJPX34K.js → shipping-AYEJMMT6.js} +2 -2
- package/dist/{shipping-profile-3QKTQI6L.js → shipping-profile-6DNDCV3D.js} +1 -1
- package/dist/{shipping-profiles-FZCKGCBU.js → shipping-profiles-CUCOF54J.js} +11 -11
- package/dist/{stock-FI5WXVWN.js → stock-UWTFM2V7.js} +8 -8
- package/dist/{store-VFRKJYMD.js → store-DSU25BJD.js} +9 -9
- package/dist/{store-closure-WZIWGESD.js → store-closure-7NGEFWM2.js} +8 -8
- package/dist/{store-select-GKRDFGEY.js → store-select-XICZEMFW.js} +9 -9
- package/dist/{tax-regions-HDLBFZVG.js → tax-regions-2JCIB4T7.js} +2 -2
- package/dist/{team-CXEAYN7O.js → team-U6XLUSDE.js} +11 -11
- package/package.json +1 -1
- package/dist/allocate-items-TCM5A55Y.js +0 -548
- package/dist/create-WBZJFMA7.js +0 -224
- package/dist/product-variant-detail-BQL2NGVE.js +0 -209
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFulfillableQuantity
|
|
3
|
+
} from "./chunk-RXM4B6HR.js";
|
|
4
|
+
import "./chunk-TKGWSUEI.js";
|
|
5
|
+
import {
|
|
6
|
+
KeyboundForm
|
|
7
|
+
} from "./chunk-U2ZFCAPX.js";
|
|
8
|
+
import {
|
|
9
|
+
RouteFocusModal,
|
|
10
|
+
useRouteModal
|
|
11
|
+
} from "./chunk-GDWBOQI5.js";
|
|
12
|
+
import {
|
|
13
|
+
Form
|
|
14
|
+
} from "./chunk-3QSRE5LS.js";
|
|
15
|
+
import {
|
|
16
|
+
Thumbnail
|
|
17
|
+
} from "./chunk-WIYFXWRI.js";
|
|
18
|
+
import {
|
|
19
|
+
useStockLocations
|
|
20
|
+
} from "./chunk-NBPMNUKZ.js";
|
|
21
|
+
import {
|
|
22
|
+
ordersQueryKeys,
|
|
23
|
+
useCreateReservationItem,
|
|
24
|
+
useOrder
|
|
25
|
+
} from "./chunk-QCAMAXTE.js";
|
|
26
|
+
import "./chunk-6ORRPSPG.js";
|
|
27
|
+
import "./chunk-A5DJIOHN.js";
|
|
28
|
+
import {
|
|
29
|
+
queryClient
|
|
30
|
+
} from "./chunk-RHKRREUU.js";
|
|
31
|
+
import "./chunk-ZA2KFUFR.js";
|
|
32
|
+
import "./chunk-RIN4CBRB.js";
|
|
33
|
+
import "./chunk-NBMM2TZK.js";
|
|
34
|
+
|
|
35
|
+
// src/pages/orders/[id]/allocate-items/index.tsx
|
|
36
|
+
import { useParams } from "react-router-dom";
|
|
37
|
+
|
|
38
|
+
// src/pages/orders/[id]/allocate-items/order-create-fulfillment-form/order-allocate-items-form.tsx
|
|
39
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
40
|
+
import { useEffect, useMemo as useMemo2, useState as useState2 } from "react";
|
|
41
|
+
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
42
|
+
import { Alert, Button, Heading, Input as Input2, Select, toast } from "@medusajs/ui";
|
|
43
|
+
import { useForm, useWatch as useWatch2 } from "react-hook-form";
|
|
44
|
+
|
|
45
|
+
// src/pages/orders/[id]/allocate-items/order-create-fulfillment-form/constants.ts
|
|
46
|
+
import { z } from "zod";
|
|
47
|
+
var AllocateItemsSchema = z.object({
|
|
48
|
+
location_id: z.string(),
|
|
49
|
+
quantity: z.record(z.string(), z.number().or(z.string())),
|
|
50
|
+
// Keyed by line item id. Defaults to selected; deselected items are
|
|
51
|
+
// excluded from the allocation payload.
|
|
52
|
+
selected: z.record(z.string(), z.boolean())
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/pages/orders/[id]/allocate-items/order-create-fulfillment-form/order-allocate-items-item.tsx
|
|
56
|
+
import { useMemo, useState } from "react";
|
|
57
|
+
import { useTranslation } from "react-i18next";
|
|
58
|
+
import {
|
|
59
|
+
Component,
|
|
60
|
+
ExclamationCircleSolid,
|
|
61
|
+
TriangleDownMini
|
|
62
|
+
} from "@medusajs/icons";
|
|
63
|
+
import { useWatch } from "react-hook-form";
|
|
64
|
+
import { Checkbox, Input, Text, clx } from "@medusajs/ui";
|
|
65
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
66
|
+
var resolveInventoryItemId = (link) => link.inventory_item?.id ?? link.inventory_item_id ?? null;
|
|
67
|
+
function OrderAllocateItemsItem({
|
|
68
|
+
item,
|
|
69
|
+
form,
|
|
70
|
+
locationId,
|
|
71
|
+
onQuantityChange,
|
|
72
|
+
onToggleSelected
|
|
73
|
+
}) {
|
|
74
|
+
const { t } = useTranslation();
|
|
75
|
+
const inventoryLinks = item.offer?.inventory_item_link ?? [];
|
|
76
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
77
|
+
const quantityField = useWatch({
|
|
78
|
+
control: form.control,
|
|
79
|
+
name: "quantity"
|
|
80
|
+
});
|
|
81
|
+
const isSelected = useWatch({
|
|
82
|
+
control: form.control,
|
|
83
|
+
name: `selected.${item.id}`
|
|
84
|
+
}) !== false;
|
|
85
|
+
const hasInventoryKit = inventoryLinks.length > 1;
|
|
86
|
+
const firstLink = inventoryLinks[0];
|
|
87
|
+
const firstLinkId = firstLink ? resolveInventoryItemId(firstLink) : null;
|
|
88
|
+
const { availableQuantity, inStockQuantity } = useMemo(() => {
|
|
89
|
+
if (!firstLink || !locationId) {
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
const locationInventory = firstLink.inventory_item?.location_levels?.find(
|
|
93
|
+
(inv) => inv.location_id === locationId
|
|
94
|
+
);
|
|
95
|
+
if (!locationInventory) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
availableQuantity: locationInventory.available_quantity,
|
|
100
|
+
inStockQuantity: locationInventory.stocked_quantity
|
|
101
|
+
};
|
|
102
|
+
}, [firstLink, locationId]);
|
|
103
|
+
const hasQuantityError = !hasInventoryKit && availableQuantity && firstLinkId && quantityField[`${item.id}-${firstLinkId}`] && Number(quantityField[`${item.id}-${firstLinkId}`]) > availableQuantity;
|
|
104
|
+
const minValue = 0;
|
|
105
|
+
const maxValue = Math.min(
|
|
106
|
+
getFulfillableQuantity(item) ?? 0,
|
|
107
|
+
availableQuantity || Number.MAX_SAFE_INTEGER
|
|
108
|
+
);
|
|
109
|
+
return /* @__PURE__ */ jsxs(
|
|
110
|
+
"div",
|
|
111
|
+
{
|
|
112
|
+
className: clx(
|
|
113
|
+
"bg-ui-bg-subtle shadow-elevation-card-rest min-w-[720px] divide-y divide-dashed rounded-xl",
|
|
114
|
+
!isSelected && "opacity-60"
|
|
115
|
+
),
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 p-3 text-sm", children: [
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
Checkbox,
|
|
120
|
+
{
|
|
121
|
+
checked: isSelected,
|
|
122
|
+
onCheckedChange: (value) => onToggleSelected(item.id, value === true),
|
|
123
|
+
"data-testid": `allocate-item-${item.id}-checkbox`
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
127
|
+
hasQuantityError && /* @__PURE__ */ jsx(ExclamationCircleSolid, { className: "text-ui-fg-error" }),
|
|
128
|
+
/* @__PURE__ */ jsx(Thumbnail, { src: item.thumbnail }),
|
|
129
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
130
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-x-1", children: [
|
|
131
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", as: "span", children: item.product_title }),
|
|
132
|
+
(item.offer?.sku ?? item.variant_sku) && /* @__PURE__ */ jsxs(
|
|
133
|
+
Text,
|
|
134
|
+
{
|
|
135
|
+
size: "small",
|
|
136
|
+
weight: "plus",
|
|
137
|
+
as: "span",
|
|
138
|
+
className: "text-ui-fg-subtle",
|
|
139
|
+
children: [
|
|
140
|
+
"(",
|
|
141
|
+
item.offer?.sku ?? item.variant_sku,
|
|
142
|
+
")"
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
hasInventoryKit && /* @__PURE__ */ jsx(Component, { className: "text-ui-fg-muted ml-1 overflow-visible" })
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ jsx(Text, { as: "div", className: "text-ui-fg-subtle txt-small", children: item.title })
|
|
149
|
+
] })
|
|
150
|
+
] }) }),
|
|
151
|
+
/* @__PURE__ */ jsxs(
|
|
152
|
+
"div",
|
|
153
|
+
{
|
|
154
|
+
className: clx(
|
|
155
|
+
"flex flex-1 items-center gap-x-3",
|
|
156
|
+
hasInventoryKit ? "justify-end" : "justify-between"
|
|
157
|
+
),
|
|
158
|
+
children: [
|
|
159
|
+
!hasInventoryKit && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
160
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
161
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
162
|
+
/* @__PURE__ */ jsxs("div", { className: "txt-small flex flex-col", children: [
|
|
163
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle font-medium", children: t("labels.available") }),
|
|
164
|
+
/* @__PURE__ */ jsxs("span", { className: "text-ui-fg-muted", children: [
|
|
165
|
+
availableQuantity || "-",
|
|
166
|
+
availableQuantity && !hasInventoryKit && firstLinkId && quantityField[`${item.id}-${firstLinkId}`] && /* @__PURE__ */ jsxs("span", { className: "text-ui-fg-error txt-small ml-1", children: [
|
|
167
|
+
"-",
|
|
168
|
+
quantityField[`${item.id}-${firstLinkId}`]
|
|
169
|
+
] })
|
|
170
|
+
] })
|
|
171
|
+
] })
|
|
172
|
+
] }),
|
|
173
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
174
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
175
|
+
/* @__PURE__ */ jsxs("div", { className: "txt-small flex flex-col", children: [
|
|
176
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle font-medium", children: t("labels.inStock") }),
|
|
177
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted", children: inStockQuantity || "-" })
|
|
178
|
+
] })
|
|
179
|
+
] })
|
|
180
|
+
] }),
|
|
181
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
182
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
183
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-row items-center gap-2", children: [
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
Form.Field,
|
|
186
|
+
{
|
|
187
|
+
control: form.control,
|
|
188
|
+
name: hasInventoryKit && firstLinkId ? `quantity.${item.id}-` : `quantity.${item.id}-${firstLinkId ?? ""}`,
|
|
189
|
+
rules: {
|
|
190
|
+
required: !hasInventoryKit,
|
|
191
|
+
min: !hasInventoryKit ? minValue : void 0,
|
|
192
|
+
max: maxValue > 0 ? maxValue : void 0
|
|
193
|
+
},
|
|
194
|
+
render: ({ field }) => {
|
|
195
|
+
return /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
|
|
196
|
+
Input,
|
|
197
|
+
{
|
|
198
|
+
className: "bg-ui-bg-base txt-small w-[46px] rounded-lg text-right [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
|
199
|
+
type: "number",
|
|
200
|
+
...field,
|
|
201
|
+
disabled: !locationId || !isSelected,
|
|
202
|
+
onChange: (e) => {
|
|
203
|
+
const val = e.target.value === "" ? null : Number(e.target.value);
|
|
204
|
+
if (firstLink) {
|
|
205
|
+
onQuantityChange(
|
|
206
|
+
firstLink,
|
|
207
|
+
item,
|
|
208
|
+
hasInventoryKit,
|
|
209
|
+
val,
|
|
210
|
+
true
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
) }) });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
),
|
|
219
|
+
" ",
|
|
220
|
+
"/ ",
|
|
221
|
+
item.quantity,
|
|
222
|
+
" ",
|
|
223
|
+
t("fields.qty")
|
|
224
|
+
] })
|
|
225
|
+
] })
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
] }),
|
|
230
|
+
hasInventoryKit && /* @__PURE__ */ jsx("div", { className: "px-4 py-2", children: /* @__PURE__ */ jsxs(
|
|
231
|
+
"div",
|
|
232
|
+
{
|
|
233
|
+
onClick: () => setIsOpen((o) => !o),
|
|
234
|
+
className: "flex items-center gap-x-2",
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsx(
|
|
237
|
+
TriangleDownMini,
|
|
238
|
+
{
|
|
239
|
+
style: { transform: `rotate(${isOpen ? -90 : 0}deg)` },
|
|
240
|
+
className: "text-ui-fg-muted -mt-[1px]"
|
|
241
|
+
}
|
|
242
|
+
),
|
|
243
|
+
/* @__PURE__ */ jsx("span", { className: "txt-small text-ui-fg-muted cursor-pointer", children: t("orders.allocateItems.consistsOf", {
|
|
244
|
+
num: inventoryLinks.length
|
|
245
|
+
}) })
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
) }),
|
|
249
|
+
isOpen && inventoryLinks.map((link, ind) => {
|
|
250
|
+
const inventoryItemId = resolveInventoryItemId(link);
|
|
251
|
+
const location = link.inventory_item?.location_levels?.find(
|
|
252
|
+
(l) => l.location_id === locationId
|
|
253
|
+
);
|
|
254
|
+
const required = link.required_quantity ?? 1;
|
|
255
|
+
const quantityKey = `${item.id}-${inventoryItemId ?? ""}`;
|
|
256
|
+
const childHasError = !!quantityField[quantityKey] && location && Number(quantityField[quantityKey]) > (location.available_quantity ?? 0);
|
|
257
|
+
return /* @__PURE__ */ jsxs(
|
|
258
|
+
"div",
|
|
259
|
+
{
|
|
260
|
+
className: "txt-small flex items-center gap-x-3 p-4",
|
|
261
|
+
children: [
|
|
262
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-row items-center gap-3", children: [
|
|
263
|
+
childHasError && /* @__PURE__ */ jsx(ExclamationCircleSolid, { className: "text-ui-fg-error" }),
|
|
264
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
265
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle", children: link.inventory_item?.title ?? link.inventory_item?.sku ?? `Inventory Item ${ind + 1}` }),
|
|
266
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted", children: t("orders.allocateItems.requires", {
|
|
267
|
+
num: required
|
|
268
|
+
}) })
|
|
269
|
+
] })
|
|
270
|
+
] }),
|
|
271
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-row justify-between", children: [
|
|
272
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
273
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
274
|
+
/* @__PURE__ */ jsxs("div", { className: "txt-small flex flex-col", children: [
|
|
275
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle font-medium", children: t("labels.available") }),
|
|
276
|
+
/* @__PURE__ */ jsxs("span", { className: "text-ui-fg-muted", children: [
|
|
277
|
+
location?.available_quantity || "-",
|
|
278
|
+
location?.available_quantity && quantityField[quantityKey] && /* @__PURE__ */ jsxs("span", { className: "text-ui-fg-error txt-small ml-1", children: [
|
|
279
|
+
"-",
|
|
280
|
+
quantityField[quantityKey]
|
|
281
|
+
] })
|
|
282
|
+
] })
|
|
283
|
+
] })
|
|
284
|
+
] }),
|
|
285
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
286
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
287
|
+
/* @__PURE__ */ jsxs("div", { className: "txt-small flex flex-col", children: [
|
|
288
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle font-medium", children: t("labels.inStock") }),
|
|
289
|
+
/* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted", children: location?.stocked_quantity || "-" })
|
|
290
|
+
] })
|
|
291
|
+
] }),
|
|
292
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
293
|
+
/* @__PURE__ */ jsx("div", { className: "bg-ui-border-strong block h-[12px] w-[1px]" }),
|
|
294
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle txt-small mr-1 flex flex-row items-center gap-2", children: [
|
|
295
|
+
/* @__PURE__ */ jsx(
|
|
296
|
+
Form.Field,
|
|
297
|
+
{
|
|
298
|
+
control: form.control,
|
|
299
|
+
name: `quantity.${item.id}-${inventoryItemId ?? ""}`,
|
|
300
|
+
rules: {
|
|
301
|
+
required: true,
|
|
302
|
+
min: 0,
|
|
303
|
+
max: location?.available_quantity ?? void 0
|
|
304
|
+
},
|
|
305
|
+
render: ({ field }) => {
|
|
306
|
+
return /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
|
|
307
|
+
Input,
|
|
308
|
+
{
|
|
309
|
+
className: "bg-ui-bg-base txt-small w-[46px] rounded-lg text-right [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
|
310
|
+
type: "number",
|
|
311
|
+
...field,
|
|
312
|
+
disabled: !locationId || !isSelected,
|
|
313
|
+
onChange: (e) => {
|
|
314
|
+
const val = e.target.value === "" ? null : Number(e.target.value);
|
|
315
|
+
onQuantityChange(
|
|
316
|
+
link,
|
|
317
|
+
item,
|
|
318
|
+
hasInventoryKit,
|
|
319
|
+
val
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
) }) });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
"/ ",
|
|
328
|
+
item.quantity * required,
|
|
329
|
+
" ",
|
|
330
|
+
t("fields.qty")
|
|
331
|
+
] })
|
|
332
|
+
] })
|
|
333
|
+
] })
|
|
334
|
+
]
|
|
335
|
+
},
|
|
336
|
+
link.id ?? inventoryItemId ?? `link-${ind}`
|
|
337
|
+
);
|
|
338
|
+
})
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/pages/orders/[id]/allocate-items/order-create-fulfillment-form/utils.ts
|
|
345
|
+
function buildAllocationPayload(quantity, selected) {
|
|
346
|
+
const rows = Object.entries(quantity).filter(([key]) => !key.endsWith("-")).map(([key, value]) => {
|
|
347
|
+
const separatorIndex = key.indexOf("-");
|
|
348
|
+
return {
|
|
349
|
+
lineItemId: key.slice(0, separatorIndex),
|
|
350
|
+
inventoryItemId: key.slice(separatorIndex + 1),
|
|
351
|
+
value
|
|
352
|
+
};
|
|
353
|
+
}).filter((row) => selected[row.lineItemId] !== false);
|
|
354
|
+
if (rows.length === 0) {
|
|
355
|
+
return { ok: false, reason: "no-items" };
|
|
356
|
+
}
|
|
357
|
+
const items = [];
|
|
358
|
+
for (const row of rows) {
|
|
359
|
+
if (row.value === "" || row.value === null || row.value === void 0) {
|
|
360
|
+
return { ok: false, reason: "invalid-quantity" };
|
|
361
|
+
}
|
|
362
|
+
const quantityNumber = Number(row.value);
|
|
363
|
+
if (!Number.isFinite(quantityNumber) || quantityNumber <= 0) {
|
|
364
|
+
return { ok: false, reason: "invalid-quantity" };
|
|
365
|
+
}
|
|
366
|
+
items.push({
|
|
367
|
+
line_item_id: row.lineItemId,
|
|
368
|
+
inventory_item_id: row.inventoryItemId,
|
|
369
|
+
quantity: quantityNumber
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return { ok: true, items };
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/pages/orders/[id]/allocate-items/order-create-fulfillment-form/order-allocate-items-form.tsx
|
|
376
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
377
|
+
function OrderAllocateItemsForm({ order }) {
|
|
378
|
+
const { t } = useTranslation2();
|
|
379
|
+
const { handleSuccess } = useRouteModal();
|
|
380
|
+
const [disableSubmit, setDisableSubmit] = useState2(false);
|
|
381
|
+
const [filterTerm, setFilterTerm] = useState2("");
|
|
382
|
+
const { mutateAsync: allocateItems, isPending: isMutating } = useCreateReservationItem();
|
|
383
|
+
const itemsToAllocate = useMemo2(
|
|
384
|
+
() => order.items.filter(
|
|
385
|
+
(item) => !!item.offer?.inventory_item_link?.length && item?.quantity - (item.detail?.fulfilled_quantity ?? 0) > 0
|
|
386
|
+
),
|
|
387
|
+
[order.items]
|
|
388
|
+
);
|
|
389
|
+
const filteredItems = useMemo2(() => {
|
|
390
|
+
return itemsToAllocate.filter(
|
|
391
|
+
(i) => i.variant_title?.toLowerCase().includes(filterTerm) || i.product_title?.toLowerCase().includes(filterTerm)
|
|
392
|
+
);
|
|
393
|
+
}, [itemsToAllocate, filterTerm]);
|
|
394
|
+
const form = useForm({
|
|
395
|
+
defaultValues: {
|
|
396
|
+
location_id: "",
|
|
397
|
+
quantity: defaultAllocations(itemsToAllocate),
|
|
398
|
+
selected: defaultSelected(itemsToAllocate)
|
|
399
|
+
},
|
|
400
|
+
resolver: zodResolver(AllocateItemsSchema)
|
|
401
|
+
});
|
|
402
|
+
const { stock_locations = [] } = useStockLocations();
|
|
403
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
404
|
+
try {
|
|
405
|
+
const result = buildAllocationPayload(data.quantity, data.selected);
|
|
406
|
+
if (!result.ok) {
|
|
407
|
+
form.setError("root.quantityNotAllocated", {
|
|
408
|
+
type: "manual",
|
|
409
|
+
message: result.reason === "no-items" ? t("orders.allocateItems.error.noItemsSelected") : t("orders.allocateItems.error.quantityNotAllocated")
|
|
410
|
+
});
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const promises = result.items.map(
|
|
414
|
+
(item) => allocateItems({
|
|
415
|
+
location_id: data.location_id,
|
|
416
|
+
inventory_item_id: item.inventory_item_id,
|
|
417
|
+
line_item_id: item.line_item_id,
|
|
418
|
+
quantity: item.quantity
|
|
419
|
+
})
|
|
420
|
+
);
|
|
421
|
+
await Promise.all(promises);
|
|
422
|
+
await queryClient.invalidateQueries({
|
|
423
|
+
queryKey: ordersQueryKeys.details()
|
|
424
|
+
});
|
|
425
|
+
handleSuccess(`/orders/${order.id}`);
|
|
426
|
+
toast.success(t("general.success"), {
|
|
427
|
+
description: t("orders.allocateItems.toast.created")
|
|
428
|
+
});
|
|
429
|
+
} catch (e) {
|
|
430
|
+
toast.error(t("general.error"), {
|
|
431
|
+
description: e instanceof Error ? e.message : "An unknown error occurred"
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
const onToggleSelected = (itemId, checked) => {
|
|
436
|
+
form.setValue(`selected.${itemId}`, checked);
|
|
437
|
+
form.clearErrors("root.quantityNotAllocated");
|
|
438
|
+
};
|
|
439
|
+
const onQuantityChange = (link, lineItem, hasInventoryKit, value, isRoot) => {
|
|
440
|
+
let shouldDisableSubmit = false;
|
|
441
|
+
const inventoryItemId = resolveInventoryItemId2(link);
|
|
442
|
+
const key = isRoot && hasInventoryKit ? `quantity.${lineItem.id}-` : `quantity.${lineItem.id}-${inventoryItemId ?? ""}`;
|
|
443
|
+
form.setValue(key, value ?? "");
|
|
444
|
+
const levels = link.inventory_item?.location_levels;
|
|
445
|
+
if (value && levels) {
|
|
446
|
+
const location = levels.find((l) => l.location_id === selectedLocationId);
|
|
447
|
+
if (location && (location.available_quantity ?? 0) < value) {
|
|
448
|
+
shouldDisableSubmit = true;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (hasInventoryKit && !isRoot) {
|
|
452
|
+
form.resetField(`quantity.${lineItem.id}-`, { defaultValue: "" });
|
|
453
|
+
}
|
|
454
|
+
if (hasInventoryKit && isRoot) {
|
|
455
|
+
const item = itemsToAllocate.find((i) => i.id === lineItem.id);
|
|
456
|
+
if (!item || !item.offer?.inventory_item_link) return;
|
|
457
|
+
item.offer.inventory_item_link.forEach((childLink) => {
|
|
458
|
+
const num = value || 0;
|
|
459
|
+
const childInventoryItemId = resolveInventoryItemId2(childLink);
|
|
460
|
+
if (!childInventoryItemId) return;
|
|
461
|
+
const required = childLink.required_quantity ?? 1;
|
|
462
|
+
form.setValue(
|
|
463
|
+
`quantity.${lineItem.id}-${childInventoryItemId}`,
|
|
464
|
+
num * required
|
|
465
|
+
);
|
|
466
|
+
const childLevels = childLink.inventory_item?.location_levels;
|
|
467
|
+
if (value && childLevels) {
|
|
468
|
+
const location = childLevels.find(
|
|
469
|
+
(l) => l.location_id === selectedLocationId
|
|
470
|
+
);
|
|
471
|
+
if (location && (location.available_quantity ?? 0) < num * required) {
|
|
472
|
+
shouldDisableSubmit = true;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
form.clearErrors("root.quantityNotAllocated");
|
|
478
|
+
setDisableSubmit(shouldDisableSubmit);
|
|
479
|
+
};
|
|
480
|
+
const selectedLocationId = useWatch2({
|
|
481
|
+
name: "location_id",
|
|
482
|
+
control: form.control
|
|
483
|
+
});
|
|
484
|
+
useEffect(() => {
|
|
485
|
+
if (selectedLocationId) {
|
|
486
|
+
form.setValue(
|
|
487
|
+
"quantity",
|
|
488
|
+
defaultAllocations(itemsToAllocate, selectedLocationId)
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
}, [
|
|
492
|
+
selectedLocationId,
|
|
493
|
+
form,
|
|
494
|
+
itemsToAllocate
|
|
495
|
+
]);
|
|
496
|
+
const allocationError = form.formState.errors?.root?.quantityNotAllocated?.message;
|
|
497
|
+
return /* @__PURE__ */ jsx2(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs2(
|
|
498
|
+
KeyboundForm,
|
|
499
|
+
{
|
|
500
|
+
onSubmit: handleSubmit,
|
|
501
|
+
className: "flex h-full flex-col overflow-hidden",
|
|
502
|
+
children: [
|
|
503
|
+
/* @__PURE__ */ jsx2(RouteFocusModal.Header, {}),
|
|
504
|
+
/* @__PURE__ */ jsx2(RouteFocusModal.Body, { className: "flex h-full w-full flex-col items-center divide-y overflow-y-auto", children: /* @__PURE__ */ jsx2("div", { className: "flex size-full flex-col items-center overflow-auto p-16", children: /* @__PURE__ */ jsx2("div", { className: "flex w-full max-w-[736px] flex-col justify-center px-2 pb-2", children: /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-8 divide-y divide-dashed", children: [
|
|
505
|
+
/* @__PURE__ */ jsx2(Heading, { children: t("orders.allocateItems.title") }),
|
|
506
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex-1 divide-y divide-dashed pt-8", children: [
|
|
507
|
+
/* @__PURE__ */ jsx2(
|
|
508
|
+
Form.Field,
|
|
509
|
+
{
|
|
510
|
+
control: form.control,
|
|
511
|
+
name: "location_id",
|
|
512
|
+
render: ({ field: { onChange, ref, ...field } }) => {
|
|
513
|
+
return /* @__PURE__ */ jsxs2(Form.Item, { children: [
|
|
514
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-3", children: [
|
|
515
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex-1", children: [
|
|
516
|
+
/* @__PURE__ */ jsx2(Form.Label, { children: t("fields.location") }),
|
|
517
|
+
/* @__PURE__ */ jsx2(Form.Hint, { children: t("orders.allocateItems.locationDescription") })
|
|
518
|
+
] }),
|
|
519
|
+
/* @__PURE__ */ jsx2("div", { className: "flex-1", children: /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsxs2(Select, { onValueChange: onChange, ...field, children: [
|
|
520
|
+
/* @__PURE__ */ jsx2(
|
|
521
|
+
Select.Trigger,
|
|
522
|
+
{
|
|
523
|
+
className: "bg-ui-bg-base",
|
|
524
|
+
ref,
|
|
525
|
+
children: /* @__PURE__ */ jsx2(Select.Value, {})
|
|
526
|
+
}
|
|
527
|
+
),
|
|
528
|
+
/* @__PURE__ */ jsx2(Select.Content, { children: stock_locations.map((l) => /* @__PURE__ */ jsx2(Select.Item, { value: l.id, children: l.name }, l.id)) })
|
|
529
|
+
] }) }) })
|
|
530
|
+
] }),
|
|
531
|
+
/* @__PURE__ */ jsx2(Form.ErrorMessage, {})
|
|
532
|
+
] });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
),
|
|
536
|
+
/* @__PURE__ */ jsxs2(Form.Item, { className: "mt-8 pt-8", children: [
|
|
537
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-row items-center", children: [
|
|
538
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex-1", children: [
|
|
539
|
+
/* @__PURE__ */ jsx2(Form.Label, { children: t("orders.allocateItems.itemsToAllocate") }),
|
|
540
|
+
/* @__PURE__ */ jsx2(Form.Hint, { children: t("orders.allocateItems.itemsToAllocateDesc") })
|
|
541
|
+
] }),
|
|
542
|
+
/* @__PURE__ */ jsx2("div", { className: "flex-1", children: /* @__PURE__ */ jsx2(
|
|
543
|
+
Input2,
|
|
544
|
+
{
|
|
545
|
+
value: filterTerm,
|
|
546
|
+
onChange: (e) => setFilterTerm(e.target.value),
|
|
547
|
+
placeholder: t("orders.allocateItems.search"),
|
|
548
|
+
autoComplete: "off",
|
|
549
|
+
type: "search"
|
|
550
|
+
}
|
|
551
|
+
) })
|
|
552
|
+
] }),
|
|
553
|
+
allocationError && /* @__PURE__ */ jsx2(Alert, { className: "mb-4", dismissible: true, variant: "error", children: allocationError }),
|
|
554
|
+
/* @__PURE__ */ jsx2("div", { className: "flex flex-col gap-y-2", children: filteredItems.map((item) => /* @__PURE__ */ jsx2(
|
|
555
|
+
OrderAllocateItemsItem,
|
|
556
|
+
{
|
|
557
|
+
form,
|
|
558
|
+
item,
|
|
559
|
+
locationId: selectedLocationId,
|
|
560
|
+
onQuantityChange,
|
|
561
|
+
onToggleSelected
|
|
562
|
+
},
|
|
563
|
+
item.id
|
|
564
|
+
)) })
|
|
565
|
+
] })
|
|
566
|
+
] })
|
|
567
|
+
] }) }) }) }),
|
|
568
|
+
/* @__PURE__ */ jsx2(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
569
|
+
/* @__PURE__ */ jsx2(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx2(Button, { size: "small", variant: "secondary", children: t("actions.cancel") }) }),
|
|
570
|
+
/* @__PURE__ */ jsx2(
|
|
571
|
+
Button,
|
|
572
|
+
{
|
|
573
|
+
size: "small",
|
|
574
|
+
type: "submit",
|
|
575
|
+
isLoading: isMutating,
|
|
576
|
+
disabled: !selectedLocationId || disableSubmit,
|
|
577
|
+
children: t("orders.allocateItems.action")
|
|
578
|
+
}
|
|
579
|
+
)
|
|
580
|
+
] }) })
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
) });
|
|
584
|
+
}
|
|
585
|
+
var resolveInventoryItemId2 = (link) => link.inventory_item?.id ?? link.inventory_item_id ?? null;
|
|
586
|
+
var clampToAvailable = (desired, link, locationId) => {
|
|
587
|
+
if (!locationId) {
|
|
588
|
+
return desired;
|
|
589
|
+
}
|
|
590
|
+
const level = link.inventory_item?.location_levels?.find(
|
|
591
|
+
(l) => l.location_id === locationId
|
|
592
|
+
);
|
|
593
|
+
const available = level?.available_quantity ?? Number.MAX_SAFE_INTEGER;
|
|
594
|
+
return Math.max(0, Math.min(desired, available));
|
|
595
|
+
};
|
|
596
|
+
function defaultAllocations(items, locationId) {
|
|
597
|
+
const ret = {};
|
|
598
|
+
items.forEach((item) => {
|
|
599
|
+
const links = item.offer?.inventory_item_link ?? [];
|
|
600
|
+
const hasInventoryKit = links.length > 1;
|
|
601
|
+
const firstLink = links[0];
|
|
602
|
+
const firstInventoryItemId = resolveInventoryItemId2(firstLink ?? {});
|
|
603
|
+
const fulfillable = getFulfillableQuantity(
|
|
604
|
+
item
|
|
605
|
+
);
|
|
606
|
+
if (hasInventoryKit) {
|
|
607
|
+
ret[`${item.id}-`] = fulfillable;
|
|
608
|
+
links.forEach((link) => {
|
|
609
|
+
const id = resolveInventoryItemId2(link);
|
|
610
|
+
if (!id) return;
|
|
611
|
+
const required = link.required_quantity ?? 1;
|
|
612
|
+
ret[`${item.id}-${id}`] = clampToAvailable(
|
|
613
|
+
fulfillable * required,
|
|
614
|
+
link,
|
|
615
|
+
locationId
|
|
616
|
+
);
|
|
617
|
+
});
|
|
618
|
+
} else {
|
|
619
|
+
ret[`${item.id}-${firstInventoryItemId ?? ""}`] = clampToAvailable(
|
|
620
|
+
fulfillable,
|
|
621
|
+
firstLink ?? {},
|
|
622
|
+
locationId
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
return ret;
|
|
627
|
+
}
|
|
628
|
+
function defaultSelected(items) {
|
|
629
|
+
const ret = {};
|
|
630
|
+
items.forEach((item) => {
|
|
631
|
+
ret[item.id] = true;
|
|
632
|
+
});
|
|
633
|
+
return ret;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/pages/orders/[id]/allocate-items/index.tsx
|
|
637
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
638
|
+
var Component2 = () => {
|
|
639
|
+
const { id } = useParams();
|
|
640
|
+
const { order, isLoading, isError, error } = useOrder(id, {
|
|
641
|
+
// `*foo,*foo.bar` or `+foo.bar.baz` makes Medusa's query parser try
|
|
642
|
+
// to look up a literal property `*items` / `+items` on Order and
|
|
643
|
+
// 500. Use `<rel>.*` plus bare scalar names.
|
|
644
|
+
fields: "currency_code,items.*,items.variant.*,items.variant.product.title,items.offer.*,items.offer.inventory_item_link.*,items.offer.inventory_item_link.required_quantity,items.offer.inventory_item_link.inventory_item.*,items.offer.inventory_item_link.inventory_item.location_levels.*,shipping_address.*"
|
|
645
|
+
});
|
|
646
|
+
if (isError) {
|
|
647
|
+
throw error;
|
|
648
|
+
}
|
|
649
|
+
const ready = !isLoading && order;
|
|
650
|
+
return /* @__PURE__ */ jsx3(RouteFocusModal, { children: ready && /* @__PURE__ */ jsx3(OrderAllocateItemsForm, { order }) });
|
|
651
|
+
};
|
|
652
|
+
export {
|
|
653
|
+
Component2 as Component
|
|
654
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GeoZoneForm
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5QG6P6EU.js";
|
|
4
4
|
import {
|
|
5
5
|
GEO_ZONE_STACKED_MODAL_ID
|
|
6
6
|
} from "./chunk-BCU3FKP2.js";
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
countries
|
|
9
9
|
} from "./chunk-JRTZWK77.js";
|
|
10
10
|
import "./chunk-FQERBIVS.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-WKRW5OPL.js";
|
|
12
12
|
import "./chunk-YN3FGNJM.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-KCHYLLVG.js";
|
|
14
14
|
import "./chunk-3EF54XFY.js";
|
|
15
15
|
import "./chunk-TKGWSUEI.js";
|
|
16
16
|
import {
|