@mercurjs/vendor 2.1.6 → 2.2.0-canary.11

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.
Files changed (259) hide show
  1. package/dist/[id]-A55T2ORL.js +3066 -0
  2. package/dist/[id]-B4YZTANM.js +1571 -0
  3. package/dist/{[id]-UTKO3VG4.js → [id]-EKLRGVBA.js} +10 -10
  4. package/dist/{[id]-TO6KT3ZE.js → [id]-FE5GYYVZ.js} +28 -25
  5. package/dist/{[id]-4VCL3MMM.js → [id]-GBT6VB4S.js} +29 -23
  6. package/dist/{[id]-3G5G7ZFV.js → [id]-GC3ZYPK4.js} +25 -22
  7. package/dist/{[id]-6PXEWRG7.js → [id]-J6BZG5PU.js} +14 -14
  8. package/dist/{[id]-B3LHVQM5.js → [id]-QOEO3JOV.js} +29 -23
  9. package/dist/{[id]-H3C3ZSC6.js → [id]-QQU5HVFU.js} +29 -23
  10. package/dist/{[id]-PDGHF5J2.js → [id]-SHAJTJNZ.js} +43 -36
  11. package/dist/{[id]-X4DDKOMQ.js → [id]-T5ECVBPF.js} +30 -24
  12. package/dist/{[id]-T2ROPEGY.js → [id]-U5KZEQDR.js} +7 -7
  13. package/dist/{[id]-7RUAH3TI.js → [id]-YPCO3DJV.js} +5 -5
  14. package/dist/{[id]-Y7GAMNC5.js → [id]-ZCMSBEVM.js} +4 -4
  15. package/dist/{[location_id]-D55RQOXT.js → [location_id]-NUBXDDJC.js} +9 -9
  16. package/dist/{[province_id]-OFH2ZOFQ.js → [province_id]-6GUA4PV5.js} +23 -20
  17. package/dist/{add-C6OX5C54.js → add-NTRYWOJF.js} +42 -35
  18. package/dist/add-RU3WL4YB.js +428 -0
  19. package/dist/{add-customer-groups-PJRJUWS2.js → add-customer-groups-U5RZWW4B.js} +19 -16
  20. package/dist/{add-products-INOLNPO6.js → add-products-Q4MMDQKT.js} +26 -20
  21. package/dist/{add-promotions-AHDOP52Q.js → add-promotions-3AYXQXTP.js} +8 -8
  22. package/dist/{add-to-campaign-HL6NGRR4.js → add-to-campaign-QKYQCSR2.js} +4 -4
  23. package/dist/{address-KRENKSLP.js → address-77Y3AOQ3.js} +19 -16
  24. package/dist/{adjust-inventory-H4EUP7J3.js → adjust-inventory-AFJLWF5R.js} +2 -2
  25. package/dist/{allocate-items-SUCUZU4D.js → allocate-items-TCM5A55Y.js} +141 -126
  26. package/dist/{areas-UUMZDXLX.js → areas-XUC5V5UO.js} +8 -8
  27. package/dist/{attributes-CALEHJJG.js → attributes-SZP2MM5L.js} +3 -3
  28. package/dist/{breadcrumb-KQSFIXQ4.js → breadcrumb-2XA2WOK7.js} +1 -1
  29. package/dist/{breadcrumb-IG7VZGW2.js → breadcrumb-5NP23D6X.js} +15 -12
  30. package/dist/{breadcrumb-TW5JEOYS.js → breadcrumb-EVZIOB2G.js} +14 -11
  31. package/dist/{breadcrumb-OIGGCB3L.js → breadcrumb-FPWBT76A.js} +8 -2
  32. package/dist/{breadcrumb-BS7Y5OKF.js → breadcrumb-IK6XCQOQ.js} +2 -2
  33. package/dist/{breadcrumb-M5Z5WA6I.js → breadcrumb-KTARIL65.js} +2 -2
  34. package/dist/{breadcrumb-VNNZ3TTW.js → breadcrumb-PBR27GGX.js} +3 -3
  35. package/dist/breadcrumb-THJ2HPRB.js +26 -0
  36. package/dist/{breadcrumb-6W2VP3OZ.js → breadcrumb-TNJSGX4T.js} +15 -12
  37. package/dist/{campaigns-HS6MIO7X.js → campaigns-JAQTSA4Z.js} +6 -6
  38. package/dist/{categories-PKWR3FM3.js → categories-T4QJYX4R.js} +8 -8
  39. package/dist/{chunk-4URLUCTD.js → chunk-25E4KME5.js} +3 -3
  40. package/dist/chunk-27KRIXMQ.js +71 -0
  41. package/dist/{chunk-SFQKKIHA.js → chunk-27WLUOI2.js} +1 -1
  42. package/dist/{chunk-ZYOXKUKZ.js → chunk-2QTNCGKX.js} +1 -1
  43. package/dist/{chunk-5UD4P6YL.js → chunk-2USXZSTK.js} +4 -4
  44. package/dist/{chunk-PXYDR7WQ.js → chunk-3BXCPHN6.js} +3 -2
  45. package/dist/{chunk-VQ5EKDA3.js → chunk-3PMM6AMP.js} +3 -3
  46. package/dist/{chunk-J6BRLL3F.js → chunk-463CNCJC.js} +3 -3
  47. package/dist/{chunk-Y2QI7KWS.js → chunk-4LVP635F.js} +408 -664
  48. package/dist/{chunk-UL4O5M4S.js → chunk-4S6XGIC6.js} +1 -18
  49. package/dist/{chunk-RUE5BPC2.js → chunk-5QI3NDJG.js} +1 -1
  50. package/dist/{chunk-PPLC4IKI.js → chunk-5T6UWTRU.js} +10 -5
  51. package/dist/{chunk-WITQNQXN.js → chunk-6FUIK3PX.js} +4 -4
  52. package/dist/{chunk-HGQTL7NX.js → chunk-6K6EQOJF.js} +3 -3
  53. package/dist/{chunk-KAZ5BYTQ.js → chunk-6OUPJNYO.js} +5 -3
  54. package/dist/{chunk-PEKANQ3T.js → chunk-6UZERVBI.js} +2 -2
  55. package/dist/{chunk-RTAWYMQP.js → chunk-7CMRFP5Q.js} +2 -2
  56. package/dist/{chunk-I2IKYOZX.js → chunk-7IPCLQ5V.js} +19 -19
  57. package/dist/chunk-ADGVQVHP.js +101 -0
  58. package/dist/{chunk-IZ5RG5XI.js → chunk-AJLGY3LQ.js} +1 -21
  59. package/dist/chunk-BER45EYD.js +82 -0
  60. package/dist/{chunk-PCMNEUMV.js → chunk-BXRNZS5K.js} +1 -1
  61. package/dist/chunk-CFRWIQIZ.js +43 -0
  62. package/dist/{chunk-RL7SFZOF.js → chunk-DDJQRV6E.js} +1 -1
  63. package/dist/{chunk-D2MA5TAP.js → chunk-DO4F5FIO.js} +2 -2
  64. package/dist/{chunk-X4FLOQ45.js → chunk-DQKK43PR.js} +3 -3
  65. package/dist/{chunk-6WY5X4PE.js → chunk-E6W57UP3.js} +35 -125
  66. package/dist/chunk-FP6U6BPH.js +61 -0
  67. package/dist/chunk-FWPGOIFA.js +22 -0
  68. package/dist/{chunk-BLVJAKBA.js → chunk-FWS4YJ4B.js} +1 -1
  69. package/dist/chunk-GAE6TKOR.js +811 -0
  70. package/dist/{chunk-3CK6OINO.js → chunk-GDWBOQI5.js} +3 -5
  71. package/dist/{chunk-PDQSPKG5.js → chunk-GN6KB75Z.js} +1 -1
  72. package/dist/chunk-HDEOZN2Q.js +60 -0
  73. package/dist/chunk-IBEUR3J7.js +173 -0
  74. package/dist/chunk-J6XCRFBW.js +30 -0
  75. package/dist/{chunk-ZEVYT6IX.js → chunk-JAUZ73XE.js} +151 -266
  76. package/dist/{chunk-CNLP35S7.js → chunk-K6LOZ4S3.js} +54 -18
  77. package/dist/{chunk-JQP7MOFH.js → chunk-KIFSQOM2.js} +2 -2
  78. package/dist/{chunk-DARJTN4I.js → chunk-L4KBTV57.js} +9 -2
  79. package/dist/chunk-L57USMYC.js +39 -0
  80. package/dist/chunk-LARLBYU6.js +127 -0
  81. package/dist/chunk-LDZCCWJB.js +518 -0
  82. package/dist/chunk-LEWA4BPH.js +18 -0
  83. package/dist/chunk-LFX6WU4A.js +36 -0
  84. package/dist/{chunk-ITI54CII.js → chunk-LKUW5SV4.js} +6 -6
  85. package/dist/{chunk-LPOAVK6Y.js → chunk-LQD232FW.js} +47 -12
  86. package/dist/{chunk-4MFMCZEJ.js → chunk-MJCL3WID.js} +2 -2
  87. package/dist/{chunk-32RYSB2V.js → chunk-NBKWY6XN.js} +2 -2
  88. package/dist/{chunk-GYV6SKY7.js → chunk-O7VOGTLX.js} +4 -6
  89. package/dist/{chunk-KQGVSLUI.js → chunk-OYKUQXJX.js} +1926 -957
  90. package/dist/{chunk-CYTNBXWF.js → chunk-OZ44ATGE.js} +8 -8
  91. package/dist/{chunk-7Q5SDEK7.js → chunk-PAVZ6FPK.js} +7 -7
  92. package/dist/{chunk-2RHAI7WK.js → chunk-QLBIBLOY.js} +2 -2
  93. package/dist/chunk-RXV7INUV.js +426 -0
  94. package/dist/chunk-S23FD6FA.js +210 -0
  95. package/dist/{chunk-NYDJTWRL.js → chunk-SGR4DMCW.js} +4 -4
  96. package/dist/{chunk-OXXL4WQU.js → chunk-SPOHNK4X.js} +6 -6
  97. package/dist/{chunk-AIF2KTEE.js → chunk-SSUUT5LK.js} +12 -2
  98. package/dist/{chunk-QX45GVAL.js → chunk-SZBERGA4.js} +8 -8
  99. package/dist/{chunk-6SBMVLJ2.js → chunk-T5MJWWDX.js} +2 -2
  100. package/dist/chunk-T6LHVNWO.js +27 -0
  101. package/dist/chunk-TBYCZRZ7.js +248 -0
  102. package/dist/chunk-TF6V3TFG.js +438 -0
  103. package/dist/chunk-TW324MAT.js +185 -0
  104. package/dist/{chunk-4ZGFODSC.js → chunk-TYESCFYW.js} +1 -1
  105. package/dist/chunk-U5G3AVED.js +64 -0
  106. package/dist/chunk-U6PBLMXD.js +14 -0
  107. package/dist/{chunk-GZMXTNDN.js → chunk-UCYSCKZV.js} +1432 -1380
  108. package/dist/{chunk-P3ZTO6T2.js → chunk-UFFVRF4V.js} +2 -2
  109. package/dist/chunk-UM7ZR3VU.js +14 -0
  110. package/dist/chunk-UORPTGV2.js +114 -0
  111. package/dist/{chunk-5M3SL4UZ.js → chunk-VCOQ7WQ2.js} +30 -106
  112. package/dist/chunk-VCUUITW6.js +35 -0
  113. package/dist/{chunk-PTW7JNAP.js → chunk-VDHW6H5F.js} +5 -5
  114. package/dist/chunk-VZUA5SRD.js +62 -0
  115. package/dist/{chunk-DKQ4XMSN.js → chunk-X4GWB6AT.js} +6 -6
  116. package/dist/{chunk-6YA3C4NB.js → chunk-XCIMOIX6.js} +3 -12
  117. package/dist/chunk-XP23ZVQT.js +2183 -0
  118. package/dist/{chunk-WBI7FEGI.js → chunk-Y2MQ5EMD.js} +29 -24
  119. package/dist/chunk-YBF45CX5.js +23 -0
  120. package/dist/{chunk-N7OVXN72.js → chunk-YGJCJBPM.js} +1 -1
  121. package/dist/{chunk-WNVEMFIK.js → chunk-YHIJCI4U.js} +3 -3
  122. package/dist/{chunk-WFE6CT6M.js → chunk-YQZBAP3S.js} +22 -76
  123. package/dist/chunk-ZHFFTT3I.js +17 -0
  124. package/dist/{collections-DJZI2RM2.js → collections-URH2TCWJ.js} +28 -24
  125. package/dist/{configuration-GN3TO77H.js → configuration-7IYZ6GNP.js} +3 -3
  126. package/dist/{configuration-RHPIO2QT.js → configuration-C4IGBNXH.js} +1 -1
  127. package/dist/{create-7S7CZWEN.js → create-5PSOIHIT.js} +4 -4
  128. package/dist/create-7R6CZU53.js +215 -0
  129. package/dist/{create-3EK5CNNX.js → create-A7B3MLJX.js} +41 -34
  130. package/dist/create-F5R76QML.js +1178 -0
  131. package/dist/create-FKRYB7ZS.js +1784 -0
  132. package/dist/create-GGACODDN.js +1914 -0
  133. package/dist/{create-YO55Z3YD.js → create-HVZYJ3YC.js} +35 -38
  134. package/dist/{create-IDVCZHIX.js → create-JF2OUZQA.js} +16 -13
  135. package/dist/{create-3ZVXEPX5.js → create-JGYG5SBM.js} +29 -23
  136. package/dist/{create-G4T2PAJH.js → create-MS6KKFSV.js} +21 -18
  137. package/dist/{create-OCFPLNNY.js → create-MZYXMGKP.js} +6 -6
  138. package/dist/{create-HKJVSFB7.js → create-O35JRZEF.js} +25 -22
  139. package/dist/{create-OGLPDVOI.js → create-ODOFJF5N.js} +40 -37
  140. package/dist/{create-GHM7OTCR.js → create-R7K3ECN6.js} +1 -1
  141. package/dist/{create-D6EW3EWC.js → create-SFU3W3ZH.js} +1 -1
  142. package/dist/create-TKXH5KQY.js +239 -0
  143. package/dist/{create-33TRLASX.js → create-UPYB65PD.js} +1 -1
  144. package/dist/{create-KGYL7FBM.js → create-XVHOCZHJ.js} +1 -1
  145. package/dist/{create-4AE3VTWN.js → create-YBF4YGWG.js} +2 -2
  146. package/dist/{customers-6ZLE65UX.js → customers-SOLJ2KQQ.js} +5 -5
  147. package/dist/{edit-QBISX7D3.js → edit-2R5QCPTB.js} +16 -13
  148. package/dist/{edit-IR6V2IDN.js → edit-3E4ZO7HT.js} +21 -18
  149. package/dist/{edit-ZSOI56BQ.js → edit-4G5D7TES.js} +52 -40
  150. package/dist/{edit-B5B3XKDM.js → edit-522DG3BY.js} +1 -1
  151. package/dist/{edit-B75KK5ZX.js → edit-5CROKEJE.js} +41 -34
  152. package/dist/{edit-ATXE6CM5.js → edit-C4OCKQVU.js} +1 -1
  153. package/dist/{edit-7HTH2UJF.js → edit-FXNXTVIW.js} +3 -3
  154. package/dist/{edit-RNT555GP.js → edit-G2E5SNGU.js} +15 -12
  155. package/dist/{edit-4HZHLYI3.js → edit-GQNIINRR.js} +1 -1
  156. package/dist/{edit-2KRJIPRK.js → edit-HTLLYECP.js} +21 -18
  157. package/dist/{edit-LRRJTHV2.js → edit-KAKVPHZZ.js} +1 -1
  158. package/dist/{edit-GIJXLMC3.js → edit-O4JLGKQR.js} +2 -2
  159. package/dist/{edit-FNDDSSMT.js → edit-OKU6FMHJ.js} +60 -9
  160. package/dist/{edit-5CJZRHAA.js → edit-ORXS3A2Y.js} +1 -1
  161. package/dist/{edit-FC64DWB2.js → edit-Q3UQIOLS.js} +1 -1
  162. package/dist/edit-VVLITC2E.js +910 -0
  163. package/dist/edit-XSICGAVO.js +176 -0
  164. package/dist/{edit-7GVP6SRA.js → edit-ZAHCMF5U.js} +1 -1
  165. package/dist/{edit-MYSWY6W4.js → edit-ZMERG3L7.js} +1 -1
  166. package/dist/{edit-budget-J27CSEZH.js → edit-budget-L3CCEWNF.js} +1 -1
  167. package/dist/{edit-inventory-item-US77M2FF.js → edit-inventory-item-ZKXXL3QK.js} +2 -2
  168. package/dist/{edit-inventory-item-attributes-UGAE2NAZ.js → edit-inventory-item-attributes-GSKUMORD.js} +3 -3
  169. package/dist/{fulfillment-DCS67LTK.js → fulfillment-76IVZ266.js} +32 -22
  170. package/dist/{fulfillment-providers-GM5PO6N3.js → fulfillment-providers-G2L6LEVO.js} +24 -20
  171. package/dist/index.css +104 -65
  172. package/dist/index.d.ts +3 -10
  173. package/dist/index.js +549 -456
  174. package/dist/{inventory-OPZ2FSEE.js → inventory-WSFLTA6Z.js} +7 -7
  175. package/dist/{invite-KEJLNXEZ.js → invite-2673PU4I.js} +17 -13
  176. package/dist/{invite-CQCKEQW2.js → invite-HRXZ5YBP.js} +28 -24
  177. package/dist/loader-VDYPD3RI.js +31 -0
  178. package/dist/{locations-ZVPTQCQY.js → locations-INS6FTMJ.js} +4 -4
  179. package/dist/{login-OUHRNNXA.js → login-TWUBU6I6.js} +14 -11
  180. package/dist/{manage-locations-YUKEFCBJ.js → manage-locations-XHH5DVIR.js} +2 -2
  181. package/dist/{media-4KYFHB5V.js → media-Z4N5MKFG.js} +42 -9
  182. package/dist/{metadata-AWUKZ25V.js → metadata-5BPOBBU2.js} +3 -3
  183. package/dist/{metadata-OCE6A3JE.js → metadata-D6M66NQK.js} +17 -14
  184. package/dist/{metadata-PYY4IB7K.js → metadata-NIDIBXJT.js} +17 -14
  185. package/dist/{metadata-XP3ZYW2M.js → metadata-Q74OJWUD.js} +18 -15
  186. package/dist/{metadata-NYYL26MQ.js → metadata-REQIFWWH.js} +18 -15
  187. package/dist/{metadata-G7KZXVNE.js → metadata-YVHJPDLD.js} +17 -14
  188. package/dist/offer-create-page-E4FLSDJQ.js +743 -0
  189. package/dist/offer-detail-page-6SIBQTLP.js +492 -0
  190. package/dist/offer-edit-page-3MO566RP.js +151 -0
  191. package/dist/offer-inventory-batch-page-BD6PMDLW.js +290 -0
  192. package/dist/offer-pricing-edit-page-4TINK42V.js +199 -0
  193. package/dist/offers-GVN5LCK6.js +32 -0
  194. package/dist/{onboarding-WXZHW62K.js → onboarding-MK2RIFD4.js} +24 -21
  195. package/dist/{orders-LWJ472VM.js → orders-TVQDR4OJ.js} +30 -26
  196. package/dist/organization-XO3T2K2X.js +340 -0
  197. package/dist/{organize-RFOMQCBG.js → organize-5XRZWD5C.js} +4 -4
  198. package/dist/{organize-OVKJ3HZO.js → organize-Z7JTTDH4.js} +4 -4
  199. package/dist/pages/index.d.ts +439 -758
  200. package/dist/pages/index.js +85 -78
  201. package/dist/{payment-details-UVXYCTUK.js → payment-details-CFTX3QDL.js} +19 -16
  202. package/dist/{payouts-TR7K5I37.js → payouts-7Q7D4FET.js} +8 -8
  203. package/dist/{price-lists-S2WNELFZ.js → price-lists-6TFLA53G.js} +9 -9
  204. package/dist/{pricing-UF27DAXA.js → pricing-ECXV6K7G.js} +41 -37
  205. package/dist/{product-tags-2CKH2M6D.js → product-tags-5O7ZG6SA.js} +40 -33
  206. package/dist/{product-types-FX43JEO2.js → product-types-PKUEL7X5.js} +6 -6
  207. package/dist/product-variant-detail-PUWOMVHQ.js +210 -0
  208. package/dist/{product-variant-edit-P3DSIFE3.js → product-variant-edit-WZNO4CQX.js} +134 -66
  209. package/dist/{products-H5EMRJYS.js → products-BM3IIH5P.js} +27 -21
  210. package/dist/{products-2LHGS7X3.js → products-CPTRYL2Z.js} +44 -45
  211. package/dist/{professional-details-HYKTH44B.js → professional-details-ED4HNYXY.js} +18 -15
  212. package/dist/{profile-PB27WIRW.js → profile-6TGCNNUU.js} +21 -18
  213. package/dist/{promotions-5EYPGHJP.js → promotions-4336KI7E.js} +9 -9
  214. package/dist/receive-224KLULH.js +578 -0
  215. package/dist/refund-IGMSXQNX.js +268 -0
  216. package/dist/{register-X45K325N.js → register-OZ5CRANZ.js} +18 -15
  217. package/dist/{reset-password-GTWLBOFK.js → reset-password-5UHZU4D3.js} +1 -1
  218. package/dist/{return-reasons-LOKYRGMI.js → return-reasons-QJRA2ZX6.js} +21 -17
  219. package/dist/{sales-channels-Y4LRP7JC.js → sales-channels-CZDU7VTE.js} +7 -6
  220. package/dist/{sales-channels-7R2IY3KG.js → sales-channels-U55MUDQP.js} +7 -6
  221. package/dist/{settings-2XDLFYMS.js → settings-2GCQQTO6.js} +47 -40
  222. package/dist/shipment-HWQHMX2L.js +242 -0
  223. package/dist/{shipping-profile-R3NABPQF.js → shipping-profile-ZP7M6VSS.js} +2 -2
  224. package/dist/{shipping-profiles-QVKNFLCW.js → shipping-profiles-C5WBXWZ2.js} +21 -18
  225. package/dist/{stock-5RXNUPUT.js → stock-MQA7PRO6.js} +21 -18
  226. package/dist/{store-MPYOWMZT.js → store-5ZHZR4JI.js} +84 -149
  227. package/dist/{store-closure-DNMCHUXD.js → store-closure-H5WHV3LA.js} +24 -16
  228. package/dist/{store-select-UTPJ7DM7.js → store-select-PZS556FB.js} +19 -16
  229. package/dist/{tax-regions-UD6P5FVC.js → tax-regions-HDLBFZVG.js} +6 -6
  230. package/dist/{team-IMS66MVP.js → team-CLKJCZNH.js} +29 -26
  231. package/dist/types-CtCEtTE6.d.ts +16 -0
  232. package/package.json +5 -5
  233. package/dist/[id]-BYP37PU4.js +0 -1314
  234. package/dist/[id]-INOFZHL7.js +0 -1219
  235. package/dist/add-KRAGFFBJ.js +0 -158
  236. package/dist/bulk-edit-3SMBLIOA.js +0 -244
  237. package/dist/chunk-47SXTGLN.js +0 -397
  238. package/dist/chunk-4KX6CBJ4.js +0 -178
  239. package/dist/chunk-DLNNTQRY.js +0 -217
  240. package/dist/chunk-FX4V5JCF.js +0 -37
  241. package/dist/chunk-GC33DBKG.js +0 -143
  242. package/dist/chunk-LQYMBSRQ.js +0 -66
  243. package/dist/chunk-NK4NR6MN.js +0 -173
  244. package/dist/chunk-PFU6FSXY.js +0 -430
  245. package/dist/chunk-QJEOPT2P.js +0 -330
  246. package/dist/chunk-QSGR43JM.js +0 -30
  247. package/dist/chunk-STR3NGWE.js +0 -3736
  248. package/dist/create-3DOO3RNH.js +0 -716
  249. package/dist/create-I7HV3RM6.js +0 -150
  250. package/dist/edit-K2AD335I.js +0 -237
  251. package/dist/edit-VO5XLIEL.js +0 -362
  252. package/dist/edit-stocks-and-prices-MHHQFWFA.js +0 -408
  253. package/dist/organization-LPYQRTQC.js +0 -303
  254. package/dist/prices-3OXV5RGY.js +0 -270
  255. package/dist/product-variant-detail-WV4KXVXR.js +0 -590
  256. package/dist/shipment-4GW2JFWB.js +0 -174
  257. package/dist/stock-GPC3BCL6.js +0 -500
  258. package/dist/{chunk-SDSEW72R.js → chunk-E2HQPY32.js} +3 -3
  259. /package/dist/{chunk-CAS74NLJ.js → chunk-YV6MK4PZ.js} +0 -0
@@ -0,0 +1,1914 @@
1
+ import {
2
+ getOfferRestockPreview
3
+ } from "./chunk-J6XCRFBW.js";
4
+ import {
5
+ ItemPlaceholder
6
+ } from "./chunk-ZHFFTT3I.js";
7
+ import {
8
+ useReturnReasons
9
+ } from "./chunk-LHKHQAAY.js";
10
+ import {
11
+ useAddExchangeInboundItems,
12
+ useAddExchangeInboundShipping,
13
+ useAddExchangeOutboundItems,
14
+ useAddExchangeOutboundShipping,
15
+ useCancelExchangeBegin,
16
+ useCreateExchange,
17
+ useRemoveExchangeInboundItem,
18
+ useRemoveExchangeOutboundItem,
19
+ useRequestExchange,
20
+ useUpdateExchangeInboundItem,
21
+ useUpdateExchangeOutboundItem
22
+ } from "./chunk-TW324MAT.js";
23
+ import {
24
+ EXCHANGE_POLICY_DAYS
25
+ } from "./chunk-VCUUITW6.js";
26
+ import {
27
+ getReturnableQuantity
28
+ } from "./chunk-UM7ZR3VU.js";
29
+ import {
30
+ MoneyAmountCell
31
+ } from "./chunk-L57USMYC.js";
32
+ import {
33
+ getStylizedAmount
34
+ } from "./chunk-3BXCPHN6.js";
35
+ import {
36
+ ProductCell,
37
+ ProductHeader
38
+ } from "./chunk-FWPGOIFA.js";
39
+ import "./chunk-FQERBIVS.js";
40
+ import {
41
+ PlaceholderCell
42
+ } from "./chunk-PHOCVOZ5.js";
43
+ import {
44
+ _DataTable,
45
+ useDataTable
46
+ } from "./chunk-SSUUT5LK.js";
47
+ import "./chunk-YN3FGNJM.js";
48
+ import "./chunk-6OUPJNYO.js";
49
+ import "./chunk-3EF54XFY.js";
50
+ import "./chunk-IQPN4PZJ.js";
51
+ import {
52
+ Combobox
53
+ } from "./chunk-VBRTC2VU.js";
54
+ import "./chunk-TKGWSUEI.js";
55
+ import {
56
+ KeyboundForm
57
+ } from "./chunk-U2ZFCAPX.js";
58
+ import {
59
+ RouteFocusModal,
60
+ StackedFocusModal,
61
+ useRouteModal,
62
+ useStackedModal
63
+ } from "./chunk-GDWBOQI5.js";
64
+ import {
65
+ Form
66
+ } from "./chunk-3QSRE5LS.js";
67
+ import {
68
+ useQueryParams
69
+ } from "./chunk-THHRRYRS.js";
70
+ import "./chunk-LRD242C7.js";
71
+ import {
72
+ Thumbnail
73
+ } from "./chunk-WIYFXWRI.js";
74
+ import "./chunk-INNFZYX2.js";
75
+ import {
76
+ useShippingOptions
77
+ } from "./chunk-VXMOPVRH.js";
78
+ import {
79
+ useStockLocations
80
+ } from "./chunk-NBPMNUKZ.js";
81
+ import {
82
+ useOffers
83
+ } from "./chunk-UORPTGV2.js";
84
+ import {
85
+ useOrder,
86
+ useOrderPreview
87
+ } from "./chunk-Y2MQ5EMD.js";
88
+ import {
89
+ ActionMenu
90
+ } from "./chunk-BDGZ4EQO.js";
91
+ import "./chunk-LAVHRER2.js";
92
+ import "./chunk-QHQWEERJ.js";
93
+ import "./chunk-Y7QKP6QU.js";
94
+ import "./chunk-JAUZ73XE.js";
95
+ import "./chunk-A5DJIOHN.js";
96
+ import "./chunk-RHKRREUU.js";
97
+ import "./chunk-ZA2KFUFR.js";
98
+ import "./chunk-RIN4CBRB.js";
99
+ import "./chunk-NBMM2TZK.js";
100
+
101
+ // src/pages/orders/[id]/exchanges/create/index.tsx
102
+ import { useTranslation as useTranslation12 } from "react-i18next";
103
+
104
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-create-form.tsx
105
+ import { zodResolver } from "@hookform/resolvers/zod";
106
+ import { Button as Button3, Heading as Heading3, Switch, Text as Text5, toast as toast3, usePrompt } from "@medusajs/ui";
107
+ import { useEffect as useEffect3, useMemo as useMemo7, useState as useState3 } from "react";
108
+ import { useForm } from "react-hook-form";
109
+ import { useNavigate, useParams } from "react-router-dom";
110
+ import { useTranslation as useTranslation11 } from "react-i18next";
111
+
112
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-section.tsx
113
+ import { Button, Heading, Text as Text2, toast } from "@medusajs/ui";
114
+ import { useEffect, useMemo as useMemo3 } from "react";
115
+ import { useFieldArray } from "react-hook-form";
116
+ import { useTranslation as useTranslation5 } from "react-i18next";
117
+
118
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
119
+ import { useMemo as useMemo2, useState } from "react";
120
+ import { useTranslation as useTranslation3 } from "react-i18next";
121
+
122
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-columns.tsx
123
+ import { Checkbox } from "@medusajs/ui";
124
+ import { createColumnHelper } from "@tanstack/react-table";
125
+ import { useMemo } from "react";
126
+ import { useTranslation } from "react-i18next";
127
+ import { jsx } from "react/jsx-runtime";
128
+ var columnHelper = createColumnHelper();
129
+ var useExchangeItemTableColumns = (currencyCode) => {
130
+ const { t } = useTranslation();
131
+ return useMemo(
132
+ () => [
133
+ columnHelper.display({
134
+ id: "select",
135
+ header: ({ table }) => {
136
+ return /* @__PURE__ */ jsx(
137
+ Checkbox,
138
+ {
139
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
140
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
141
+ }
142
+ );
143
+ },
144
+ cell: ({ row }) => {
145
+ const isSelectable = row.getCanSelect();
146
+ return /* @__PURE__ */ jsx(
147
+ Checkbox,
148
+ {
149
+ disabled: !isSelectable,
150
+ checked: row.getIsSelected(),
151
+ onCheckedChange: (value) => row.toggleSelected(!!value),
152
+ onClick: (e) => {
153
+ e.stopPropagation();
154
+ }
155
+ }
156
+ );
157
+ }
158
+ }),
159
+ columnHelper.display({
160
+ id: "product",
161
+ header: () => /* @__PURE__ */ jsx(ProductHeader, {}),
162
+ cell: ({ row }) => /* @__PURE__ */ jsx(
163
+ ProductCell,
164
+ {
165
+ product: {
166
+ thumbnail: row.original.thumbnail,
167
+ title: row.original.product_title
168
+ }
169
+ }
170
+ )
171
+ }),
172
+ columnHelper.accessor("variant.sku", {
173
+ header: t("fields.sku"),
174
+ cell: ({ getValue }) => {
175
+ return getValue() || "-";
176
+ }
177
+ }),
178
+ columnHelper.accessor("variant.title", {
179
+ header: t("fields.variant")
180
+ }),
181
+ columnHelper.accessor("quantity", {
182
+ header: () => /* @__PURE__ */ jsx("div", { className: "flex size-full items-center overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.quantity") }) }),
183
+ cell: ({ row }) => {
184
+ return getReturnableQuantity(row.original);
185
+ }
186
+ }),
187
+ columnHelper.accessor("refundable_total", {
188
+ header: () => /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-end overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.price") }) }),
189
+ cell: ({ getValue }) => {
190
+ const amount = getValue() || 0;
191
+ const stylized = getStylizedAmount(amount, currencyCode);
192
+ return /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-end overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: stylized }) });
193
+ }
194
+ })
195
+ ],
196
+ [t, currencyCode]
197
+ );
198
+ };
199
+
200
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-filters.tsx
201
+ import { useTranslation as useTranslation2 } from "react-i18next";
202
+ var useExchangeItemTableFilters = () => {
203
+ const { t } = useTranslation2();
204
+ const filters = [
205
+ {
206
+ key: "created_at",
207
+ label: t("fields.createdAt"),
208
+ type: "date"
209
+ },
210
+ {
211
+ key: "updated_at",
212
+ label: t("fields.updatedAt"),
213
+ type: "date"
214
+ }
215
+ ];
216
+ return filters;
217
+ };
218
+
219
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/use-exchange-item-table-query.tsx
220
+ var useExchangeItemTableQuery = ({
221
+ pageSize = 50,
222
+ prefix
223
+ }) => {
224
+ const raw = useQueryParams(
225
+ ["q", "offset", "order", "created_at", "updated_at"],
226
+ prefix
227
+ );
228
+ const { offset, created_at, updated_at, ...rest } = raw;
229
+ const searchParams = {
230
+ ...rest,
231
+ limit: pageSize,
232
+ offset: offset ? Number(offset) : 0,
233
+ created_at: created_at ? JSON.parse(created_at) : void 0,
234
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
235
+ };
236
+ return { searchParams, raw };
237
+ };
238
+
239
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
240
+ import { jsx as jsx2 } from "react/jsx-runtime";
241
+ var PAGE_SIZE = 50;
242
+ var PREFIX = "rit";
243
+ var AddExchangeInboundItemsTable = ({
244
+ onSelectionChange,
245
+ selectedItems,
246
+ items,
247
+ currencyCode
248
+ }) => {
249
+ const { t } = useTranslation3();
250
+ const [rowSelection, setRowSelection] = useState(
251
+ selectedItems.reduce((acc, id) => {
252
+ acc[id] = true;
253
+ return acc;
254
+ }, {})
255
+ );
256
+ const updater = (fn) => {
257
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
258
+ setRowSelection(newState);
259
+ onSelectionChange(Object.keys(newState));
260
+ };
261
+ const { searchParams, raw } = useExchangeItemTableQuery({
262
+ pageSize: PAGE_SIZE,
263
+ prefix: PREFIX
264
+ });
265
+ const queriedItems = useMemo2(() => {
266
+ const { order, offset, limit, q, created_at, updated_at } = searchParams;
267
+ let results = items;
268
+ if (q) {
269
+ const needle = q.toLowerCase();
270
+ results = results.filter((i) => {
271
+ return i.product_title?.toLowerCase().includes(needle) || i.variant_title?.toLowerCase().includes(needle) || i.variant_sku?.toLowerCase().includes(needle);
272
+ });
273
+ }
274
+ if (order) {
275
+ const direction = order[0] === "-" ? "desc" : "asc";
276
+ const field = order.replace("-", "");
277
+ results = sortItems(results, field, direction);
278
+ }
279
+ if (created_at) {
280
+ results = filterByDate(
281
+ results,
282
+ created_at,
283
+ "created_at"
284
+ );
285
+ }
286
+ if (updated_at) {
287
+ results = filterByDate(
288
+ results,
289
+ updated_at,
290
+ "updated_at"
291
+ );
292
+ }
293
+ return results.slice(offset, offset + limit);
294
+ }, [items, searchParams]);
295
+ const columns = useExchangeItemTableColumns(currencyCode);
296
+ const filters = useExchangeItemTableFilters();
297
+ const { table } = useDataTable({
298
+ data: queriedItems,
299
+ columns,
300
+ count: queriedItems.length,
301
+ enablePagination: true,
302
+ getRowId: (row) => row.id,
303
+ pageSize: PAGE_SIZE,
304
+ enableRowSelection: (row) => {
305
+ return getReturnableQuantity(row.original) > 0;
306
+ },
307
+ rowSelection: {
308
+ state: rowSelection,
309
+ updater
310
+ }
311
+ });
312
+ return /* @__PURE__ */ jsx2("div", { className: "flex size-full flex-col overflow-hidden", children: /* @__PURE__ */ jsx2(
313
+ _DataTable,
314
+ {
315
+ table,
316
+ columns,
317
+ pageSize: PAGE_SIZE,
318
+ count: queriedItems.length,
319
+ filters,
320
+ pagination: true,
321
+ layout: "fill",
322
+ search: true,
323
+ orderBy: [
324
+ { key: "product_title", label: t("fields.product") },
325
+ { key: "variant_title", label: t("fields.variant") },
326
+ { key: "sku", label: t("fields.sku") }
327
+ ],
328
+ prefix: PREFIX,
329
+ queryObject: raw
330
+ }
331
+ ) });
332
+ };
333
+ var sortItems = (items, field, direction) => {
334
+ return items.sort((a, b) => {
335
+ let aValue;
336
+ let bValue;
337
+ if (field === "product_title") {
338
+ aValue = a.product_title;
339
+ bValue = b.product_title;
340
+ } else if (field === "variant_title") {
341
+ aValue = a.variant_title;
342
+ bValue = b.variant_title;
343
+ } else if (field === "sku") {
344
+ aValue = a.variant_sku;
345
+ bValue = b.variant_sku;
346
+ }
347
+ const aSafe = aValue ?? "";
348
+ const bSafe = bValue ?? "";
349
+ if (aSafe < bSafe) {
350
+ return direction === "asc" ? -1 : 1;
351
+ }
352
+ if (aSafe > bSafe) {
353
+ return direction === "asc" ? 1 : -1;
354
+ }
355
+ return 0;
356
+ });
357
+ };
358
+ var filterByDate = (items, date, field) => {
359
+ const { gt, gte, lt, lte } = date;
360
+ return items.filter((i) => {
361
+ const itemDate = new Date(i[field]);
362
+ let isValid = true;
363
+ if (gt) {
364
+ isValid = isValid && itemDate > new Date(gt);
365
+ }
366
+ if (gte) {
367
+ isValid = isValid && itemDate >= new Date(gte);
368
+ }
369
+ if (lt) {
370
+ isValid = isValid && itemDate < new Date(lt);
371
+ }
372
+ if (lte) {
373
+ isValid = isValid && itemDate <= new Date(lte);
374
+ }
375
+ return isValid;
376
+ });
377
+ };
378
+
379
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-item.tsx
380
+ import { ChatBubble, DocumentText, XCircle, XMark } from "@medusajs/icons";
381
+ import { IconButton, Input, Text } from "@medusajs/ui";
382
+ import { useTranslation as useTranslation4 } from "react-i18next";
383
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
384
+ function ExchangeInboundItem({
385
+ item,
386
+ previewItem,
387
+ currencyCode,
388
+ form,
389
+ onRemove,
390
+ onUpdate,
391
+ index,
392
+ locationName
393
+ }) {
394
+ const { t } = useTranslation4();
395
+ const { return_reasons = [] } = useReturnReasons({ fields: "+label" });
396
+ const returnReasons = return_reasons;
397
+ const formItem = form.watch(`inbound_items.${index}`);
398
+ const showReturnReason = typeof formItem?.reason_id === "string";
399
+ const showNote = typeof formItem?.note === "string";
400
+ const quantity = formItem?.quantity ?? 0;
401
+ const appliedPromoCodes = (previewItem?.adjustments ?? []).map((adjustment) => adjustment.code).filter((code) => Boolean(code));
402
+ return /* @__PURE__ */ jsxs(
403
+ "div",
404
+ {
405
+ className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl",
406
+ "data-testid": `exchange-inbound-item-${item.id}`,
407
+ children: [
408
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-x-3 gap-y-2 p-3 text-sm md:flex-row", children: [
409
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-x-3", children: [
410
+ /* @__PURE__ */ jsx3(Thumbnail, { src: item.thumbnail }),
411
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-grow flex-col", children: [
412
+ /* @__PURE__ */ jsxs("div", { children: [
413
+ /* @__PURE__ */ jsxs(Text, { className: "txt-small", as: "span", weight: "plus", children: [
414
+ item.title,
415
+ " "
416
+ ] }),
417
+ item.variant_sku && /* @__PURE__ */ jsxs("span", { children: [
418
+ "(",
419
+ item.variant_sku,
420
+ ")"
421
+ ] })
422
+ ] }),
423
+ /* @__PURE__ */ jsx3(Text, { as: "div", className: "text-ui-fg-subtle txt-small", children: item.product_title })
424
+ ] }),
425
+ appliedPromoCodes.length > 0 && /* @__PURE__ */ jsx3(
426
+ "div",
427
+ {
428
+ className: "flex flex-shrink",
429
+ title: appliedPromoCodes.join(", ")
430
+ }
431
+ )
432
+ ] }),
433
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 justify-between", children: [
434
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-grow items-center gap-2", children: [
435
+ /* @__PURE__ */ jsx3(
436
+ Form.Field,
437
+ {
438
+ control: form.control,
439
+ name: `inbound_items.${index}.quantity`,
440
+ render: ({ field }) => {
441
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
442
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
443
+ Input,
444
+ {
445
+ ...field,
446
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
447
+ min: 1,
448
+ max: item.quantity,
449
+ type: "number",
450
+ "data-testid": `exchange-inbound-item-${item.id}-qty`,
451
+ onBlur: (e) => {
452
+ const val = e.target.value;
453
+ const payload = val === "" ? null : Number(val);
454
+ field.onChange(payload);
455
+ if (payload) {
456
+ onUpdate({ quantity: payload });
457
+ }
458
+ }
459
+ }
460
+ ) }),
461
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
462
+ ] });
463
+ }
464
+ }
465
+ ),
466
+ /* @__PURE__ */ jsx3(Text, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
467
+ ] }),
468
+ /* @__PURE__ */ jsx3("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx3(
469
+ MoneyAmountCell,
470
+ {
471
+ currencyCode,
472
+ amount: previewItem?.return_requested_total ?? 0
473
+ }
474
+ ) }),
475
+ /* @__PURE__ */ jsx3(
476
+ ActionMenu,
477
+ {
478
+ groups: [
479
+ {
480
+ actions: [
481
+ !showReturnReason && {
482
+ label: t("actions.addReason"),
483
+ onClick: () => form.setValue(`inbound_items.${index}.reason_id`, ""),
484
+ icon: /* @__PURE__ */ jsx3(ChatBubble, {})
485
+ },
486
+ !showNote && {
487
+ label: t("actions.addNote"),
488
+ onClick: () => form.setValue(`inbound_items.${index}.note`, ""),
489
+ icon: /* @__PURE__ */ jsx3(DocumentText, {})
490
+ },
491
+ {
492
+ label: t("actions.remove"),
493
+ onClick: onRemove,
494
+ icon: /* @__PURE__ */ jsx3(XCircle, {})
495
+ }
496
+ ].filter(Boolean)
497
+ }
498
+ ]
499
+ }
500
+ )
501
+ ] })
502
+ ] }),
503
+ locationName && quantity > 0 && /* @__PURE__ */ jsx3(
504
+ ExchangeRestockPreview,
505
+ {
506
+ item,
507
+ quantity,
508
+ locationName
509
+ }
510
+ ),
511
+ showReturnReason && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
512
+ /* @__PURE__ */ jsxs("div", { children: [
513
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.reason") }),
514
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.reasonHint") })
515
+ ] }),
516
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
517
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
518
+ Form.Field,
519
+ {
520
+ control: form.control,
521
+ name: `inbound_items.${index}.reason_id`,
522
+ render: ({ field: { value, onChange, ref: _ref, ...field } }) => {
523
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
524
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
525
+ Combobox,
526
+ {
527
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover",
528
+ value: value ?? void 0,
529
+ onChange: (v) => {
530
+ onUpdate({ reason_id: v ?? null });
531
+ onChange(v);
532
+ },
533
+ ...field,
534
+ options: returnReasons.map((reason) => ({
535
+ label: reason.label ?? reason.value ?? reason.id,
536
+ value: reason.id
537
+ }))
538
+ }
539
+ ) }),
540
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
541
+ ] });
542
+ }
543
+ }
544
+ ) }),
545
+ /* @__PURE__ */ jsx3(
546
+ IconButton,
547
+ {
548
+ type: "button",
549
+ className: "flex-shrink",
550
+ variant: "transparent",
551
+ onClick: () => {
552
+ form.setValue(`inbound_items.${index}.reason_id`, null);
553
+ onUpdate({ reason_id: null });
554
+ },
555
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
556
+ }
557
+ )
558
+ ] })
559
+ ] }),
560
+ showNote && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
561
+ /* @__PURE__ */ jsxs("div", { children: [
562
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.note") }),
563
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.noteHint") })
564
+ ] }),
565
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
566
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
567
+ Form.Field,
568
+ {
569
+ control: form.control,
570
+ name: `inbound_items.${index}.note`,
571
+ render: ({ field: { ref: _ref, value, ...field } }) => {
572
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
573
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
574
+ Input,
575
+ {
576
+ ...field,
577
+ value: value ?? "",
578
+ "data-testid": `exchange-inbound-item-${item.id}-note`,
579
+ onBlur: (e) => {
580
+ const next = e.target.value;
581
+ field.onChange(next);
582
+ onUpdate({ internal_note: next || null });
583
+ },
584
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover"
585
+ }
586
+ ) }),
587
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
588
+ ] });
589
+ }
590
+ }
591
+ ) }),
592
+ /* @__PURE__ */ jsx3(
593
+ IconButton,
594
+ {
595
+ type: "button",
596
+ className: "flex-shrink",
597
+ variant: "transparent",
598
+ onClick: () => {
599
+ form.setValue(`inbound_items.${index}.note`, null);
600
+ onUpdate({ internal_note: null });
601
+ },
602
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
603
+ }
604
+ )
605
+ ] })
606
+ ] })
607
+ ]
608
+ }
609
+ );
610
+ }
611
+ var ExchangeRestockPreview = ({
612
+ item,
613
+ quantity,
614
+ locationName
615
+ }) => {
616
+ const { t } = useTranslation4();
617
+ const preview = getOfferRestockPreview(item, quantity);
618
+ if (!preview.length) {
619
+ return null;
620
+ }
621
+ const offerSku = item.offer?.sku ?? item.variant_sku ?? null;
622
+ return /* @__PURE__ */ jsx3("div", { className: "bg-ui-bg-subtle flex flex-col gap-y-1 rounded-md px-3 py-2", children: preview.map((row) => /* @__PURE__ */ jsx3(
623
+ Text,
624
+ {
625
+ size: "xsmall",
626
+ className: "text-ui-fg-subtle",
627
+ "data-testid": `exchange-inbound-item-${item.id}-restock-${row.inventoryItemId}`,
628
+ children: t("orders.returns.restockPreview", {
629
+ quantity,
630
+ offerSku: offerSku ?? "\u2014",
631
+ delta: row.delta,
632
+ inventoryItem: row.inventoryItemLabel,
633
+ location: locationName ?? "\u2014"
634
+ })
635
+ },
636
+ row.inventoryItemId
637
+ )) });
638
+ };
639
+
640
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-inbound-section.tsx
641
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
642
+ var itemsToAdd = [];
643
+ var itemsToRemove = [];
644
+ var ExchangeInboundSection = ({
645
+ order,
646
+ preview,
647
+ exchange,
648
+ form,
649
+ orderReturn
650
+ }) => {
651
+ const { t } = useTranslation5();
652
+ const { setIsOpen } = useStackedModal();
653
+ const { mutateAsync: addInboundShipping } = useAddExchangeInboundShipping(
654
+ exchange.id,
655
+ order.id
656
+ );
657
+ const { mutateAsync: addInboundItem } = useAddExchangeInboundItems(
658
+ exchange.id,
659
+ order.id
660
+ );
661
+ const { mutateAsync: updateInboundItem } = useUpdateExchangeInboundItem(
662
+ exchange.id,
663
+ order.id
664
+ );
665
+ const { mutateAsync: removeInboundItem } = useRemoveExchangeInboundItem(
666
+ exchange.id,
667
+ order.id
668
+ );
669
+ const previewInboundItems = useMemo3(
670
+ () => (preview?.items ?? []).filter(
671
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchange.id)
672
+ ),
673
+ [preview.items, exchange.id]
674
+ );
675
+ const inboundPreviewItems = previewInboundItems.filter(
676
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
677
+ );
678
+ const itemsMap = useMemo3(
679
+ () => new Map((order?.items ?? []).map((i) => [i.id, i])),
680
+ [order.items]
681
+ );
682
+ const locationId = form.watch("location_id");
683
+ const { stock_locations = [] } = useStockLocations({
684
+ limit: 999
685
+ });
686
+ const { shipping_options = [] } = useShippingOptions(
687
+ {
688
+ limit: 999,
689
+ stock_location_id: locationId
690
+ },
691
+ { enabled: !!locationId }
692
+ );
693
+ const inboundShippingOptions = shipping_options.filter(
694
+ (shippingOption) => !!shippingOption.rules?.find(
695
+ (r) => r.attribute === "is_return" && r.value === "true"
696
+ )
697
+ );
698
+ const {
699
+ fields: inboundItems,
700
+ append,
701
+ remove,
702
+ update
703
+ } = useFieldArray({
704
+ name: "inbound_items",
705
+ control: form.control
706
+ });
707
+ const inboundItemsMap = useMemo3(
708
+ () => new Map(previewInboundItems.map((i) => [i.id, i])),
709
+ [previewInboundItems, inboundItems]
710
+ );
711
+ useEffect(() => {
712
+ const existingItemsMap = {};
713
+ inboundPreviewItems.forEach((i) => {
714
+ const ind = inboundItems.findIndex((field) => field.item_id === i.id);
715
+ const requested = i.detail?.return_requested_quantity ?? 0;
716
+ existingItemsMap[i.id] = true;
717
+ if (ind > -1) {
718
+ if (inboundItems[ind].quantity !== requested) {
719
+ const returnItemAction = i.actions?.find(
720
+ (a) => a.action === "RETURN_ITEM"
721
+ );
722
+ update(ind, {
723
+ ...inboundItems[ind],
724
+ quantity: requested,
725
+ note: returnItemAction?.internal_note ?? void 0,
726
+ reason_id: returnItemAction?.details?.reason_id
727
+ });
728
+ }
729
+ } else {
730
+ append(
731
+ { item_id: i.id, quantity: requested },
732
+ { shouldFocus: false }
733
+ );
734
+ }
735
+ });
736
+ inboundItems.forEach((i, ind) => {
737
+ if (!(i.item_id in existingItemsMap)) {
738
+ remove(ind);
739
+ }
740
+ });
741
+ }, [previewInboundItems]);
742
+ useEffect(() => {
743
+ const inboundShippingMethod = (preview.shipping_methods ?? []).find(
744
+ (s) => s.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
745
+ );
746
+ if (inboundShippingMethod?.shipping_option_id) {
747
+ form.setValue("inbound_option_id", inboundShippingMethod.shipping_option_id);
748
+ } else {
749
+ form.setValue("inbound_option_id", "");
750
+ }
751
+ }, [preview.shipping_methods]);
752
+ useEffect(() => {
753
+ if (orderReturn?.location_id) {
754
+ form.setValue("location_id", orderReturn.location_id);
755
+ }
756
+ }, [orderReturn]);
757
+ const showInboundItemsPlaceholder = !inboundItems.length;
758
+ const onItemsSelected = async () => {
759
+ if (itemsToAdd.length) {
760
+ await addInboundItem(
761
+ {
762
+ items: itemsToAdd.map((id) => ({
763
+ id,
764
+ quantity: 1
765
+ }))
766
+ },
767
+ {
768
+ onError: (error) => {
769
+ toast.error(error.message);
770
+ }
771
+ }
772
+ );
773
+ }
774
+ for (const itemToRemove of itemsToRemove) {
775
+ const actionId = previewInboundItems.find((i) => i.id === itemToRemove)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
776
+ if (actionId) {
777
+ await removeInboundItem(actionId, {
778
+ onError: (error) => {
779
+ toast.error(error.message);
780
+ }
781
+ });
782
+ }
783
+ }
784
+ setIsOpen("inbound-items", false);
785
+ };
786
+ const onLocationChange = (_selectedLocationId) => {
787
+ };
788
+ const onShippingOptionChange = async (selectedOptionId) => {
789
+ if (selectedOptionId) {
790
+ await addInboundShipping(
791
+ { shipping_option_id: selectedOptionId },
792
+ {
793
+ onError: (error) => {
794
+ toast.error(error.message);
795
+ }
796
+ }
797
+ );
798
+ }
799
+ };
800
+ return /* @__PURE__ */ jsxs2("div", { children: [
801
+ /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex items-center justify-between", children: [
802
+ /* @__PURE__ */ jsx4(Heading, { level: "h2", children: t("orders.returns.inbound") }),
803
+ /* @__PURE__ */ jsxs2(StackedFocusModal, { id: "inbound-items", children: [
804
+ /* @__PURE__ */ jsx4(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx4("a", { className: "focus-visible:shadow-borders-focus transition-fg txt-compact-small-plus cursor-pointer text-blue-500 outline-none hover:text-blue-400", children: t("actions.addItems") }) }),
805
+ /* @__PURE__ */ jsxs2(StackedFocusModal.Content, { children: [
806
+ /* @__PURE__ */ jsx4(StackedFocusModal.Header, {}),
807
+ /* @__PURE__ */ jsx4(
808
+ AddExchangeInboundItemsTable,
809
+ {
810
+ items: order.items ?? [],
811
+ selectedItems: inboundItems.map((i) => i.item_id),
812
+ currencyCode: order.currency_code,
813
+ onSelectionChange: (finalSelection) => {
814
+ const alreadySelected = inboundItems.map((i) => i.item_id);
815
+ itemsToAdd = finalSelection.filter(
816
+ (selection) => !alreadySelected.includes(selection)
817
+ );
818
+ itemsToRemove = alreadySelected.filter(
819
+ (selection) => !finalSelection.includes(selection)
820
+ );
821
+ }
822
+ }
823
+ ),
824
+ /* @__PURE__ */ jsx4(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsx4("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-x-2", children: [
825
+ /* @__PURE__ */ jsx4(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx4(Button, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
826
+ /* @__PURE__ */ jsx4(
827
+ Button,
828
+ {
829
+ type: "submit",
830
+ variant: "primary",
831
+ size: "small",
832
+ role: "button",
833
+ onClick: async () => await onItemsSelected(),
834
+ children: t("actions.save")
835
+ },
836
+ "submit-button"
837
+ )
838
+ ] }) }) })
839
+ ] })
840
+ ] })
841
+ ] }),
842
+ showInboundItemsPlaceholder && /* @__PURE__ */ jsx4(ItemPlaceholder, {}),
843
+ inboundItems.map((item, index) => {
844
+ const previewItem = inboundItemsMap.get(item.item_id);
845
+ const sourceItem = itemsMap.get(item.item_id);
846
+ if (!previewItem || !sourceItem) {
847
+ return null;
848
+ }
849
+ const locationName = stock_locations.find(
850
+ (l) => l.id === locationId
851
+ )?.name ?? null;
852
+ return /* @__PURE__ */ jsx4(
853
+ ExchangeInboundItem,
854
+ {
855
+ item: sourceItem,
856
+ previewItem,
857
+ currencyCode: order.currency_code,
858
+ form,
859
+ locationName,
860
+ onRemove: () => {
861
+ const actionId = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
862
+ if (actionId) {
863
+ removeInboundItem(actionId, {
864
+ onError: (error) => {
865
+ toast.error(error.message);
866
+ }
867
+ });
868
+ }
869
+ },
870
+ onUpdate: (payload) => {
871
+ const action = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM");
872
+ if (action?.id) {
873
+ updateInboundItem(
874
+ { $actionId: action.id, ...payload },
875
+ {
876
+ onError: (error) => {
877
+ if (action.details?.quantity && payload.quantity) {
878
+ form.setValue(
879
+ `inbound_items.${index}.quantity`,
880
+ action.details.quantity
881
+ );
882
+ }
883
+ toast.error(error.message);
884
+ }
885
+ }
886
+ );
887
+ }
888
+ },
889
+ index
890
+ },
891
+ item.id
892
+ );
893
+ }),
894
+ !showInboundItemsPlaceholder && /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex flex-col gap-y-4", children: [
895
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
896
+ /* @__PURE__ */ jsxs2("div", { children: [
897
+ /* @__PURE__ */ jsx4(Form.Label, { children: t("orders.returns.location") }),
898
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.locationHint") })
899
+ ] }),
900
+ /* @__PURE__ */ jsx4(
901
+ Form.Field,
902
+ {
903
+ control: form.control,
904
+ name: "location_id",
905
+ render: ({ field: { value, onChange, ...field } }) => {
906
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
907
+ Combobox,
908
+ {
909
+ ...field,
910
+ value: value ?? void 0,
911
+ onChange: (v) => {
912
+ onChange(v);
913
+ onLocationChange(v);
914
+ },
915
+ options: stock_locations.map((stockLocation) => ({
916
+ label: stockLocation.name,
917
+ value: stockLocation.id
918
+ }))
919
+ }
920
+ ) }) });
921
+ }
922
+ }
923
+ )
924
+ ] }),
925
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
926
+ /* @__PURE__ */ jsxs2("div", { children: [
927
+ /* @__PURE__ */ jsxs2(Form.Label, { children: [
928
+ t("orders.returns.inboundShipping"),
929
+ /* @__PURE__ */ jsxs2(
930
+ Text2,
931
+ {
932
+ size: "small",
933
+ leading: "compact",
934
+ className: "text-ui-fg-muted ml-1 inline",
935
+ children: [
936
+ "(",
937
+ t("fields.optional"),
938
+ ")"
939
+ ]
940
+ }
941
+ )
942
+ ] }),
943
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.inboundShippingHint") })
944
+ ] }),
945
+ /* @__PURE__ */ jsx4(
946
+ Form.Field,
947
+ {
948
+ control: form.control,
949
+ name: "inbound_option_id",
950
+ render: ({ field: { value, onChange, ...field } }) => {
951
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
952
+ Combobox,
953
+ {
954
+ allowClear: true,
955
+ value: value ?? void 0,
956
+ onChange: (val) => {
957
+ onChange(val);
958
+ onShippingOptionChange(val);
959
+ },
960
+ ...field,
961
+ options: inboundShippingOptions.map((so) => ({
962
+ label: so.name,
963
+ value: so.id
964
+ })),
965
+ disabled: !locationId
966
+ }
967
+ ) }) });
968
+ }
969
+ }
970
+ )
971
+ ] })
972
+ ] })
973
+ ] });
974
+ };
975
+
976
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-section.tsx
977
+ import { Button as Button2, Heading as Heading2, toast as toast2 } from "@medusajs/ui";
978
+ import { useEffect as useEffect2, useMemo as useMemo6 } from "react";
979
+ import { useFieldArray as useFieldArray2 } from "react-hook-form";
980
+ import { useTranslation as useTranslation10 } from "react-i18next";
981
+
982
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
983
+ import { useMemo as useMemo5, useState as useState2 } from "react";
984
+ import { useTranslation as useTranslation8 } from "react-i18next";
985
+
986
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-columns.tsx
987
+ import { Checkbox as Checkbox2, Text as Text3 } from "@medusajs/ui";
988
+ import { createColumnHelper as createColumnHelper2 } from "@tanstack/react-table";
989
+ import { useMemo as useMemo4 } from "react";
990
+ import { useTranslation as useTranslation6 } from "react-i18next";
991
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
992
+ var columnHelper2 = createColumnHelper2();
993
+ var useExchangeOutboundItemTableColumns = () => {
994
+ const { t } = useTranslation6();
995
+ return useMemo4(
996
+ () => [
997
+ columnHelper2.display({
998
+ id: "select",
999
+ header: ({ table }) => /* @__PURE__ */ jsx5(
1000
+ Checkbox2,
1001
+ {
1002
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
1003
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
1004
+ }
1005
+ ),
1006
+ cell: ({ row }) => {
1007
+ const isSelectable = row.getCanSelect();
1008
+ return /* @__PURE__ */ jsx5(
1009
+ Checkbox2,
1010
+ {
1011
+ disabled: !isSelectable,
1012
+ checked: row.getIsSelected(),
1013
+ onCheckedChange: (value) => row.toggleSelected(!!value),
1014
+ onClick: (e) => {
1015
+ e.stopPropagation();
1016
+ }
1017
+ }
1018
+ );
1019
+ }
1020
+ }),
1021
+ columnHelper2.display({
1022
+ id: "product",
1023
+ header: t("fields.product"),
1024
+ cell: ({ row }) => {
1025
+ const variant = row.original.product_variant;
1026
+ const productTitle = variant?.product?.title;
1027
+ if (!productTitle) {
1028
+ return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1029
+ }
1030
+ return /* @__PURE__ */ jsxs3("div", { className: "flex h-full w-full max-w-[300px] items-center gap-x-3 overflow-hidden", children: [
1031
+ /* @__PURE__ */ jsx5(Thumbnail, { src: variant?.product?.thumbnail }),
1032
+ /* @__PURE__ */ jsx5(
1033
+ Text3,
1034
+ {
1035
+ size: "small",
1036
+ leading: "compact",
1037
+ className: "truncate",
1038
+ title: productTitle,
1039
+ children: productTitle
1040
+ }
1041
+ )
1042
+ ] });
1043
+ }
1044
+ }),
1045
+ columnHelper2.accessor("sku", {
1046
+ header: t("fields.sku"),
1047
+ cell: ({ getValue }) => {
1048
+ const sku = getValue();
1049
+ if (!sku) return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1050
+ return /* @__PURE__ */ jsx5(Text3, { size: "small", leading: "compact", className: "truncate", children: sku });
1051
+ }
1052
+ }),
1053
+ columnHelper2.display({
1054
+ id: "variant_title",
1055
+ header: t("fields.title"),
1056
+ cell: ({ row }) => {
1057
+ const title = row.original.product_variant?.title;
1058
+ if (!title) return /* @__PURE__ */ jsx5(PlaceholderCell, {});
1059
+ return /* @__PURE__ */ jsx5(Text3, { size: "small", leading: "compact", className: "truncate", children: title });
1060
+ }
1061
+ })
1062
+ ],
1063
+ [t]
1064
+ );
1065
+ };
1066
+
1067
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-filters.tsx
1068
+ import { useTranslation as useTranslation7 } from "react-i18next";
1069
+ var useExchangeOutboundItemTableFilters = () => {
1070
+ const { t } = useTranslation7();
1071
+ const filters = [
1072
+ {
1073
+ key: "created_at",
1074
+ label: t("fields.createdAt"),
1075
+ type: "date"
1076
+ },
1077
+ {
1078
+ key: "updated_at",
1079
+ label: t("fields.updatedAt"),
1080
+ type: "date"
1081
+ }
1082
+ ];
1083
+ return filters;
1084
+ };
1085
+
1086
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-query.tsx
1087
+ var useExchangeOutboundItemTableQuery = ({
1088
+ pageSize = 50,
1089
+ prefix
1090
+ }) => {
1091
+ const raw = useQueryParams(
1092
+ ["q", "offset", "order", "created_at", "updated_at"],
1093
+ prefix
1094
+ );
1095
+ const { offset, created_at, updated_at, ...rest } = raw;
1096
+ const searchParams = {
1097
+ ...rest,
1098
+ limit: pageSize,
1099
+ offset: offset ? Number(offset) : 0,
1100
+ created_at: created_at ? JSON.parse(created_at) : void 0,
1101
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
1102
+ };
1103
+ return { searchParams, raw };
1104
+ };
1105
+
1106
+ // src/pages/orders/[id]/exchanges/create/_components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
1107
+ import { jsx as jsx6 } from "react/jsx-runtime";
1108
+ var PAGE_SIZE2 = 50;
1109
+ var PREFIX2 = "rit";
1110
+ var OFFER_PICKER_FIELDS = [
1111
+ "id",
1112
+ "sku",
1113
+ "variant_id",
1114
+ "seller_id",
1115
+ "prices.amount",
1116
+ "prices.currency_code",
1117
+ "product_variant.id",
1118
+ "product_variant.title",
1119
+ "product_variant.product.id",
1120
+ "product_variant.product.title",
1121
+ "product_variant.product.thumbnail",
1122
+ "product_variant.manage_inventory",
1123
+ "product_variant.inventory_quantity",
1124
+ "product_variant.inventory_items.required_quantity",
1125
+ "product_variant.inventory_items.inventory.location_levels.available_quantity"
1126
+ ].join(",");
1127
+ var offerHasInventory = (offer) => {
1128
+ const variant = offer.product_variant;
1129
+ if (!variant) return false;
1130
+ if (variant.manage_inventory === false) return true;
1131
+ const links = variant.inventory_items ?? [];
1132
+ if (!links.length) {
1133
+ return (variant.inventory_quantity ?? 0) > 0;
1134
+ }
1135
+ return links.every((link) => {
1136
+ const available = (link.inventory?.location_levels ?? []).reduce(
1137
+ (acc, lvl) => acc + (lvl.available_quantity ?? 0),
1138
+ 0
1139
+ );
1140
+ const required = link.required_quantity ?? 1;
1141
+ return required > 0 && available >= required;
1142
+ });
1143
+ };
1144
+ var AddExchangeOutboundItemsTable = ({
1145
+ currencyCode,
1146
+ onSelectionChange,
1147
+ selectedItems = []
1148
+ }) => {
1149
+ const { t } = useTranslation8();
1150
+ const [rowSelection, setRowSelection] = useState2(
1151
+ selectedItems.reduce((acc, id) => {
1152
+ acc[id] = true;
1153
+ return acc;
1154
+ }, {})
1155
+ );
1156
+ const updater = (fn) => {
1157
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
1158
+ setRowSelection(newState);
1159
+ onSelectionChange(Object.keys(newState));
1160
+ };
1161
+ const { searchParams, raw } = useExchangeOutboundItemTableQuery({
1162
+ pageSize: PAGE_SIZE2,
1163
+ prefix: PREFIX2
1164
+ });
1165
+ const offersResponse = useOffers({
1166
+ ...searchParams,
1167
+ fields: OFFER_PICKER_FIELDS
1168
+ });
1169
+ const rawOffers = offersResponse.offers ?? [];
1170
+ const rawCount = offersResponse.count ?? 0;
1171
+ const offers = useMemo5(() => {
1172
+ return rawOffers.filter((offer) => {
1173
+ if (currencyCode) {
1174
+ const hasPrice = (offer.prices ?? []).some(
1175
+ (p) => p.currency_code === currencyCode
1176
+ );
1177
+ if (!hasPrice) return false;
1178
+ }
1179
+ return offerHasInventory(offer);
1180
+ });
1181
+ }, [rawOffers, currencyCode]);
1182
+ const count = offers.length;
1183
+ void rawCount;
1184
+ const columns = useExchangeOutboundItemTableColumns();
1185
+ const filters = useExchangeOutboundItemTableFilters();
1186
+ const { table } = useDataTable({
1187
+ data: offers,
1188
+ columns,
1189
+ count,
1190
+ enablePagination: true,
1191
+ // Row id = offer id so onSelectionChange yields offer_ids that the
1192
+ // modal layer sends to the backend item-add routes (which accept
1193
+ // `offer_id` and resolve to variant_id + unit_price server-side).
1194
+ getRowId: (row) => row.id,
1195
+ pageSize: PAGE_SIZE2,
1196
+ enableRowSelection: () => true,
1197
+ rowSelection: {
1198
+ state: rowSelection,
1199
+ updater
1200
+ }
1201
+ });
1202
+ return /* @__PURE__ */ jsx6(
1203
+ "div",
1204
+ {
1205
+ className: "flex size-full flex-col overflow-hidden",
1206
+ "data-testid": "add-offers-picker",
1207
+ children: /* @__PURE__ */ jsx6(
1208
+ _DataTable,
1209
+ {
1210
+ table,
1211
+ columns,
1212
+ pageSize: PAGE_SIZE2,
1213
+ count,
1214
+ filters,
1215
+ pagination: true,
1216
+ layout: "fill",
1217
+ search: true,
1218
+ orderBy: [
1219
+ { key: "sku", label: t("fields.sku") },
1220
+ { key: "created_at", label: t("fields.createdAt") },
1221
+ { key: "updated_at", label: t("fields.updatedAt") }
1222
+ ],
1223
+ prefix: PREFIX2,
1224
+ queryObject: raw
1225
+ }
1226
+ )
1227
+ }
1228
+ );
1229
+ };
1230
+
1231
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-item.tsx
1232
+ import { XCircle as XCircle2 } from "@medusajs/icons";
1233
+ import { Input as Input2, Text as Text4 } from "@medusajs/ui";
1234
+ import { useTranslation as useTranslation9 } from "react-i18next";
1235
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
1236
+ function ExchangeOutboundItem({
1237
+ previewItem,
1238
+ currencyCode,
1239
+ form,
1240
+ onRemove,
1241
+ onUpdate,
1242
+ index
1243
+ }) {
1244
+ const { t } = useTranslation9();
1245
+ const appliedPromoCodes = (previewItem.adjustments ?? []).map((adjustment) => adjustment.code).filter((code) => Boolean(code));
1246
+ return /* @__PURE__ */ jsx7(
1247
+ "div",
1248
+ {
1249
+ className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl",
1250
+ "data-testid": `exchange-outbound-item-${previewItem.id}`,
1251
+ children: /* @__PURE__ */ jsxs4("div", { className: "flex flex-col items-center gap-x-3 gap-y-2 p-3 text-sm md:flex-row", children: [
1252
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 items-center gap-x-3", children: [
1253
+ /* @__PURE__ */ jsx7(Thumbnail, { src: previewItem.thumbnail ?? void 0 }),
1254
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-grow flex-col", children: [
1255
+ /* @__PURE__ */ jsxs4("div", { children: [
1256
+ /* @__PURE__ */ jsxs4(Text4, { className: "txt-small", as: "span", weight: "plus", children: [
1257
+ previewItem.title,
1258
+ " "
1259
+ ] }),
1260
+ previewItem.variant_sku && /* @__PURE__ */ jsxs4("span", { children: [
1261
+ "(",
1262
+ previewItem.variant_sku,
1263
+ ")"
1264
+ ] })
1265
+ ] }),
1266
+ /* @__PURE__ */ jsx7(Text4, { as: "div", className: "text-ui-fg-subtle txt-small", children: previewItem.subtitle ?? previewItem.variant_title ?? "" })
1267
+ ] }),
1268
+ appliedPromoCodes.length > 0 && /* @__PURE__ */ jsx7(
1269
+ "div",
1270
+ {
1271
+ className: "flex flex-shrink",
1272
+ title: appliedPromoCodes.join(", ")
1273
+ }
1274
+ )
1275
+ ] }),
1276
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 justify-between", children: [
1277
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-grow items-center gap-2", children: [
1278
+ /* @__PURE__ */ jsx7(
1279
+ Form.Field,
1280
+ {
1281
+ control: form.control,
1282
+ name: `outbound_items.${index}.quantity`,
1283
+ render: ({ field }) => {
1284
+ return /* @__PURE__ */ jsxs4(Form.Item, { children: [
1285
+ /* @__PURE__ */ jsx7(Form.Control, { children: /* @__PURE__ */ jsx7(
1286
+ Input2,
1287
+ {
1288
+ ...field,
1289
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
1290
+ min: 1,
1291
+ type: "number",
1292
+ "data-testid": `exchange-outbound-item-${previewItem.id}-qty`,
1293
+ onBlur: (e) => {
1294
+ const val = e.target.value;
1295
+ const payload = val === "" ? null : Number(val);
1296
+ field.onChange(payload);
1297
+ if (payload) {
1298
+ onUpdate({ quantity: payload });
1299
+ }
1300
+ }
1301
+ }
1302
+ ) }),
1303
+ /* @__PURE__ */ jsx7(Form.ErrorMessage, {})
1304
+ ] });
1305
+ }
1306
+ }
1307
+ ),
1308
+ /* @__PURE__ */ jsx7(Text4, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
1309
+ ] }),
1310
+ /* @__PURE__ */ jsx7("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx7(
1311
+ MoneyAmountCell,
1312
+ {
1313
+ currencyCode,
1314
+ amount: previewItem.total ?? 0
1315
+ }
1316
+ ) }),
1317
+ /* @__PURE__ */ jsx7(
1318
+ ActionMenu,
1319
+ {
1320
+ groups: [
1321
+ {
1322
+ actions: [
1323
+ {
1324
+ label: t("actions.remove"),
1325
+ onClick: onRemove,
1326
+ icon: /* @__PURE__ */ jsx7(XCircle2, {})
1327
+ }
1328
+ ]
1329
+ }
1330
+ ]
1331
+ }
1332
+ )
1333
+ ] })
1334
+ ] })
1335
+ }
1336
+ );
1337
+ }
1338
+
1339
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-outbound-section.tsx
1340
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1341
+ var offersToAdd = [];
1342
+ var offersToRemove = [];
1343
+ var ExchangeOutboundSection = ({
1344
+ order,
1345
+ preview,
1346
+ exchange,
1347
+ form
1348
+ }) => {
1349
+ const { t } = useTranslation10();
1350
+ const { setIsOpen } = useStackedModal();
1351
+ const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping(
1352
+ exchange.id,
1353
+ order.id
1354
+ );
1355
+ const { mutateAsync: addOutboundItem } = useAddExchangeOutboundItems(
1356
+ exchange.id,
1357
+ order.id
1358
+ );
1359
+ const { mutateAsync: updateOutboundItem } = useUpdateExchangeOutboundItem(
1360
+ exchange.id,
1361
+ order.id
1362
+ );
1363
+ const { mutateAsync: removeOutboundItem } = useRemoveExchangeOutboundItem(
1364
+ exchange.id,
1365
+ order.id
1366
+ );
1367
+ const previewOutboundItems = useMemo6(
1368
+ () => (preview?.items ?? []).filter(
1369
+ (i) => !!i.actions?.find(
1370
+ (a) => a.exchange_id === exchange.id && a.action === "ITEM_ADD"
1371
+ )
1372
+ ),
1373
+ [preview.items, exchange.id]
1374
+ );
1375
+ const {
1376
+ fields: outboundItems,
1377
+ append,
1378
+ remove,
1379
+ update
1380
+ } = useFieldArray2({
1381
+ name: "outbound_items",
1382
+ control: form.control
1383
+ });
1384
+ const previewItemsMap = useMemo6(
1385
+ () => new Map(previewOutboundItems.map((i) => [i.id, i])),
1386
+ [previewOutboundItems, outboundItems]
1387
+ );
1388
+ useEffect2(() => {
1389
+ const existingItemsMap = {};
1390
+ previewOutboundItems.forEach((i) => {
1391
+ const ind = outboundItems.findIndex((field) => field.item_id === i.id);
1392
+ const requested = i.detail?.quantity ?? 0;
1393
+ existingItemsMap[i.id] = true;
1394
+ if (ind > -1) {
1395
+ if (outboundItems[ind].quantity !== requested) {
1396
+ update(ind, {
1397
+ ...outboundItems[ind],
1398
+ quantity: requested
1399
+ });
1400
+ }
1401
+ } else {
1402
+ append(
1403
+ {
1404
+ item_id: i.id,
1405
+ quantity: requested,
1406
+ variant_id: i.variant_id ?? void 0
1407
+ },
1408
+ { shouldFocus: false }
1409
+ );
1410
+ }
1411
+ });
1412
+ outboundItems.forEach((i, ind) => {
1413
+ if (!(i.item_id in existingItemsMap)) {
1414
+ remove(ind);
1415
+ }
1416
+ });
1417
+ }, [previewOutboundItems]);
1418
+ const showOutboundItemsPlaceholder = !outboundItems.length;
1419
+ const onItemsSelected = async () => {
1420
+ if (offersToAdd.length) {
1421
+ await addOutboundItem(
1422
+ {
1423
+ // Vendor route resolves `offer_id` server-side.
1424
+ items: offersToAdd.map((offer_id) => ({
1425
+ offer_id,
1426
+ quantity: 1
1427
+ }))
1428
+ },
1429
+ {
1430
+ onError: (error) => {
1431
+ toast2.error(error.message);
1432
+ }
1433
+ }
1434
+ );
1435
+ }
1436
+ for (const offerToRemove of offersToRemove) {
1437
+ const field = outboundItems.find(
1438
+ (f) => f.offer_id === offerToRemove
1439
+ );
1440
+ const previewMatch = field ? previewOutboundItems.find((i) => i.id === field.item_id) : void 0;
1441
+ const actionId = previewMatch?.actions?.find(
1442
+ (a) => a.action === "ITEM_ADD"
1443
+ )?.id;
1444
+ if (actionId) {
1445
+ await removeOutboundItem(actionId, {
1446
+ onError: (error) => {
1447
+ toast2.error(error.message);
1448
+ }
1449
+ });
1450
+ }
1451
+ }
1452
+ setIsOpen("outbound-items", false);
1453
+ };
1454
+ useEffect2(() => {
1455
+ const outboundShipping = (preview.shipping_methods ?? []).find(
1456
+ (s) => !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1457
+ );
1458
+ if (outboundShipping?.shipping_option_id) {
1459
+ form.setValue("outbound_option_id", outboundShipping.shipping_option_id);
1460
+ } else {
1461
+ form.setValue("outbound_option_id", "");
1462
+ }
1463
+ }, [preview.shipping_methods]);
1464
+ const onShippingOptionChange = async (selectedOptionId) => {
1465
+ if (selectedOptionId) {
1466
+ await addOutboundShipping(
1467
+ { shipping_option_id: selectedOptionId },
1468
+ {
1469
+ onError: (error) => {
1470
+ toast2.error(error.message);
1471
+ }
1472
+ }
1473
+ );
1474
+ }
1475
+ };
1476
+ return /* @__PURE__ */ jsxs5("div", { children: [
1477
+ /* @__PURE__ */ jsxs5("div", { className: "mt-8 flex items-center justify-between", children: [
1478
+ /* @__PURE__ */ jsx8(Heading2, { level: "h2", children: t("orders.returns.outbound") }),
1479
+ /* @__PURE__ */ jsxs5(StackedFocusModal, { id: "outbound-items", children: [
1480
+ /* @__PURE__ */ jsx8(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx8("a", { className: "focus-visible:shadow-borders-focus transition-fg txt-compact-small-plus cursor-pointer text-blue-500 outline-none hover:text-blue-400", children: t("actions.addItems") }) }),
1481
+ /* @__PURE__ */ jsxs5(StackedFocusModal.Content, { children: [
1482
+ /* @__PURE__ */ jsx8(StackedFocusModal.Header, {}),
1483
+ /* @__PURE__ */ jsx8(
1484
+ AddExchangeOutboundItemsTable,
1485
+ {
1486
+ selectedItems: outboundItems.map((i) => i.offer_id).filter(Boolean),
1487
+ currencyCode: order.currency_code,
1488
+ onSelectionChange: (finalSelection) => {
1489
+ const alreadySelected = outboundItems.map((i) => i.offer_id).filter(Boolean);
1490
+ offersToAdd = finalSelection.filter(
1491
+ (selection) => !alreadySelected.includes(selection)
1492
+ );
1493
+ offersToRemove = alreadySelected.filter(
1494
+ (selection) => !finalSelection.includes(selection)
1495
+ );
1496
+ }
1497
+ }
1498
+ ),
1499
+ /* @__PURE__ */ jsx8(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsx8("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-end gap-x-2", children: [
1500
+ /* @__PURE__ */ jsx8(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx8(Button2, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
1501
+ /* @__PURE__ */ jsx8(
1502
+ Button2,
1503
+ {
1504
+ type: "submit",
1505
+ variant: "primary",
1506
+ size: "small",
1507
+ role: "button",
1508
+ onClick: async () => await onItemsSelected(),
1509
+ children: t("actions.save")
1510
+ },
1511
+ "submit-button"
1512
+ )
1513
+ ] }) }) })
1514
+ ] })
1515
+ ] })
1516
+ ] }),
1517
+ showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8(ItemPlaceholder, {}),
1518
+ outboundItems.map((item, index) => {
1519
+ const previewItem = previewItemsMap.get(item.item_id);
1520
+ if (!previewItem) {
1521
+ return null;
1522
+ }
1523
+ return /* @__PURE__ */ jsx8(
1524
+ ExchangeOutboundItem,
1525
+ {
1526
+ previewItem,
1527
+ currencyCode: order.currency_code,
1528
+ form,
1529
+ onRemove: () => {
1530
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1531
+ if (actionId) {
1532
+ removeOutboundItem(actionId, {
1533
+ onError: (error) => {
1534
+ toast2.error(error.message);
1535
+ }
1536
+ });
1537
+ }
1538
+ },
1539
+ onUpdate: (payload) => {
1540
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1541
+ if (actionId) {
1542
+ updateOutboundItem(
1543
+ { $actionId: actionId, ...payload },
1544
+ {
1545
+ onError: (error) => {
1546
+ toast2.error(error.message);
1547
+ }
1548
+ }
1549
+ );
1550
+ }
1551
+ },
1552
+ index
1553
+ },
1554
+ item.id
1555
+ );
1556
+ }),
1557
+ !showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8("div", { className: "mt-8 flex flex-col gap-y-4", children: /* @__PURE__ */ jsxs5("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
1558
+ /* @__PURE__ */ jsxs5("div", { children: [
1559
+ /* @__PURE__ */ jsx8(Form.Label, { children: t("orders.exchanges.outboundShipping") }),
1560
+ /* @__PURE__ */ jsx8(Form.Hint, { className: "!mt-1", children: t("orders.exchanges.outboundShippingHint") })
1561
+ ] }),
1562
+ /* @__PURE__ */ jsx8(
1563
+ Form.Field,
1564
+ {
1565
+ control: form.control,
1566
+ name: "outbound_option_id",
1567
+ render: ({ field: { value, onChange, ...field } }) => {
1568
+ return /* @__PURE__ */ jsx8(Form.Item, { children: /* @__PURE__ */ jsx8(Form.Control, { children: /* @__PURE__ */ jsx8(
1569
+ Combobox,
1570
+ {
1571
+ allowClear: true,
1572
+ value: value ?? void 0,
1573
+ onChange: (val) => {
1574
+ onChange(val);
1575
+ onShippingOptionChange(val);
1576
+ },
1577
+ ...field,
1578
+ options: [],
1579
+ disabled: true
1580
+ }
1581
+ ) }) });
1582
+ }
1583
+ }
1584
+ )
1585
+ ] }) })
1586
+ ] });
1587
+ };
1588
+
1589
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/schema.ts
1590
+ import { z } from "zod";
1591
+ var ExchangeCreateSchema = z.object({
1592
+ inbound_items: z.array(
1593
+ z.object({
1594
+ item_id: z.string(),
1595
+ variant_id: z.string().nullish(),
1596
+ quantity: z.number(),
1597
+ reason_id: z.string().nullish(),
1598
+ note: z.string().nullish()
1599
+ })
1600
+ ),
1601
+ outbound_items: z.array(
1602
+ z.object({
1603
+ item_id: z.string(),
1604
+ offer_id: z.string().nullish(),
1605
+ variant_id: z.string().nullish(),
1606
+ quantity: z.number()
1607
+ })
1608
+ ),
1609
+ location_id: z.string().optional(),
1610
+ inbound_option_id: z.string().nullish(),
1611
+ outbound_option_id: z.string().nullish(),
1612
+ send_notification: z.boolean().optional()
1613
+ });
1614
+
1615
+ // src/pages/orders/[id]/exchanges/create/_components/exchange-create-form/exchange-create-form.tsx
1616
+ import { Fragment, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1617
+ var readExchangeId = (change) => {
1618
+ if (change && typeof change === "object" && "exchange_id" in change && typeof change.exchange_id === "string") {
1619
+ return change.exchange_id;
1620
+ }
1621
+ return void 0;
1622
+ };
1623
+ var IS_REQUEST_RUNNING = false;
1624
+ var ExchangeCreateForm = () => {
1625
+ const { id } = useParams();
1626
+ const { t } = useTranslation11();
1627
+ const navigate = useNavigate();
1628
+ const { handleSuccess } = useRouteModal();
1629
+ const orderId = id ?? "";
1630
+ const { order } = useOrder(orderId, {
1631
+ fields: "currency_code,total,items.*,items.variant.*"
1632
+ });
1633
+ const { order: preview } = useOrderPreview(orderId);
1634
+ const [exchangeId, setExchangeId] = useState3("");
1635
+ const [submitting, setSubmitting] = useState3(false);
1636
+ const [canceling, setCanceling] = useState3(false);
1637
+ const form = useForm({
1638
+ defaultValues: {
1639
+ inbound_items: [],
1640
+ outbound_items: [],
1641
+ location_id: void 0,
1642
+ inbound_option_id: null,
1643
+ outbound_option_id: null,
1644
+ send_notification: false
1645
+ },
1646
+ resolver: zodResolver(ExchangeCreateSchema)
1647
+ });
1648
+ const { mutateAsync: createExchange } = useCreateExchange(orderId);
1649
+ const { mutateAsync: cancelBegin } = useCancelExchangeBegin(
1650
+ exchangeId,
1651
+ orderId
1652
+ );
1653
+ const { mutateAsync: requestExchange, isPending: isConfirming } = useRequestExchange(exchangeId, orderId);
1654
+ useEffect3(() => {
1655
+ async function run() {
1656
+ if (IS_REQUEST_RUNNING || exchangeId || !preview) {
1657
+ return;
1658
+ }
1659
+ if (preview.order_change) {
1660
+ if (preview.order_change.change_type !== "exchange") {
1661
+ navigate(`/orders/${orderId}`, { replace: true });
1662
+ toast3.error(t("orders.exchanges.activeChangeError"));
1663
+ return;
1664
+ }
1665
+ const existingExchangeId = readExchangeId(preview.order_change);
1666
+ if (existingExchangeId) {
1667
+ setExchangeId(existingExchangeId);
1668
+ }
1669
+ return;
1670
+ }
1671
+ IS_REQUEST_RUNNING = true;
1672
+ try {
1673
+ const { exchange } = await createExchange({ order_id: orderId });
1674
+ setExchangeId(exchange.id);
1675
+ } catch (e) {
1676
+ toast3.error(
1677
+ e instanceof Error ? e.message : t("errorBoundary.defaultTitle")
1678
+ );
1679
+ navigate(`/orders/${orderId}`, { replace: true });
1680
+ } finally {
1681
+ IS_REQUEST_RUNNING = false;
1682
+ }
1683
+ }
1684
+ run();
1685
+ }, [preview, orderId, exchangeId]);
1686
+ const inboundItemsWatch = form.watch("inbound_items");
1687
+ const outboundItemsWatch = form.watch("outbound_items");
1688
+ const hasSelection = useMemo7(
1689
+ () => (inboundItemsWatch?.length ?? 0) > 0 || (outboundItemsWatch?.length ?? 0) > 0,
1690
+ [inboundItemsWatch, outboundItemsWatch]
1691
+ );
1692
+ const previewItems = useMemo7(() => {
1693
+ if (!exchangeId) return [];
1694
+ return (preview?.items ?? []).filter(
1695
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchangeId)
1696
+ );
1697
+ }, [preview, exchangeId]);
1698
+ const inboundPreviewItems = useMemo7(
1699
+ () => previewItems.filter(
1700
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
1701
+ ),
1702
+ [previewItems]
1703
+ );
1704
+ const outboundPreviewItems = useMemo7(
1705
+ () => previewItems.filter(
1706
+ (item) => !!item.actions?.find((a) => a.action === "ITEM_ADD")
1707
+ ),
1708
+ [previewItems]
1709
+ );
1710
+ const currencyCode = order?.currency_code ?? "";
1711
+ const inboundTotal = useMemo7(() => {
1712
+ return inboundPreviewItems.reduce((acc, item) => {
1713
+ const action = item.actions?.find((a) => a.action === "RETURN_ITEM");
1714
+ const requested = Number(action?.details?.quantity || 0);
1715
+ const itemQty = item.quantity ?? 0;
1716
+ const itemTotal = item.total ?? 0;
1717
+ if (!itemQty) return acc;
1718
+ return acc + requested / itemQty * itemTotal;
1719
+ }, 0);
1720
+ }, [inboundPreviewItems]);
1721
+ const outboundTotal = useMemo7(() => {
1722
+ return outboundPreviewItems.reduce(
1723
+ (acc, item) => acc + (item.total ?? 0),
1724
+ 0
1725
+ );
1726
+ }, [outboundPreviewItems]);
1727
+ const inboundShippingTotal = useMemo7(() => {
1728
+ const methods = preview?.shipping_methods ?? [];
1729
+ const method = methods.find(
1730
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
1731
+ );
1732
+ return method?.total ?? 0;
1733
+ }, [preview]);
1734
+ const outboundShippingTotal = useMemo7(() => {
1735
+ const methods = preview?.shipping_methods ?? [];
1736
+ const method = methods.find(
1737
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1738
+ );
1739
+ return method?.total ?? 0;
1740
+ }, [preview]);
1741
+ const estimatedDifference = useMemo7(() => {
1742
+ const summary = preview?.summary;
1743
+ return (summary?.pending_difference ?? 0) - inboundTotal;
1744
+ }, [preview, inboundTotal]);
1745
+ const prompt = usePrompt();
1746
+ const handleSubmit = form.handleSubmit(async (data) => {
1747
+ if (!exchangeId) {
1748
+ return;
1749
+ }
1750
+ const res = await prompt({
1751
+ title: t("general.areYouSure"),
1752
+ description: t("orders.exchanges.confirmText"),
1753
+ confirmText: t("actions.continue"),
1754
+ cancelText: t("actions.cancel"),
1755
+ variant: "confirmation"
1756
+ });
1757
+ if (!res) {
1758
+ return;
1759
+ }
1760
+ setSubmitting(true);
1761
+ try {
1762
+ await requestExchange(
1763
+ { no_notification: !data.send_notification }
1764
+ );
1765
+ toast3.success(t("orders.exchanges.toast.confirmedSuccessfully"));
1766
+ handleSuccess(`/orders/${orderId}`);
1767
+ } catch (e) {
1768
+ toast3.error(t("general.error"), {
1769
+ description: e instanceof Error ? e.message : t("errorBoundary.defaultTitle")
1770
+ });
1771
+ } finally {
1772
+ setSubmitting(false);
1773
+ }
1774
+ });
1775
+ const handleClose = async () => {
1776
+ if (!exchangeId) {
1777
+ navigate(`/orders/${orderId}`, { replace: true });
1778
+ return;
1779
+ }
1780
+ setCanceling(true);
1781
+ try {
1782
+ await cancelBegin();
1783
+ toast3.success(t("orders.exchanges.toast.canceledSuccessfully"));
1784
+ } catch {
1785
+ } finally {
1786
+ setCanceling(false);
1787
+ navigate(`/orders/${orderId}`, { replace: true });
1788
+ }
1789
+ };
1790
+ const ready = !!order && !!preview && !!exchangeId;
1791
+ return /* @__PURE__ */ jsx9(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs6(KeyboundForm, { onSubmit: handleSubmit, className: "flex h-full flex-col", children: [
1792
+ /* @__PURE__ */ jsx9(RouteFocusModal.Header, {}),
1793
+ /* @__PURE__ */ jsx9(RouteFocusModal.Body, { className: "flex size-full justify-center overflow-y-auto", children: /* @__PURE__ */ jsxs6("div", { className: "mt-16 w-[720px] max-w-[100%] px-4 md:p-0", children: [
1794
+ /* @__PURE__ */ jsx9(Heading3, { level: "h1", children: t("orders.exchanges.create") }),
1795
+ /* @__PURE__ */ jsx9(Text5, { size: "small", className: "text-ui-fg-subtle mt-2", children: t("orders.exchanges.policyHint", {
1796
+ days: EXCHANGE_POLICY_DAYS
1797
+ }) }),
1798
+ ready && /* @__PURE__ */ jsxs6(Fragment, { children: [
1799
+ /* @__PURE__ */ jsx9(
1800
+ ExchangeInboundSection,
1801
+ {
1802
+ form,
1803
+ preview,
1804
+ order,
1805
+ exchange: { id: exchangeId }
1806
+ }
1807
+ ),
1808
+ /* @__PURE__ */ jsx9(
1809
+ ExchangeOutboundSection,
1810
+ {
1811
+ form,
1812
+ preview,
1813
+ order,
1814
+ exchange: { id: exchangeId }
1815
+ }
1816
+ ),
1817
+ /* @__PURE__ */ jsxs6("div", { className: "mt-8 border-y border-dotted py-4", children: [
1818
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1819
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.returns.inboundTotal") }),
1820
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(-1 * inboundTotal, currencyCode) })
1821
+ ] }),
1822
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1823
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.exchanges.outboundTotal") }),
1824
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(outboundTotal, currencyCode) })
1825
+ ] }),
1826
+ /* @__PURE__ */ jsxs6("div", { className: "mb-2 flex items-center justify-between", children: [
1827
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.returns.inboundShipping") }),
1828
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(inboundShippingTotal, currencyCode) })
1829
+ ] }),
1830
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between", children: [
1831
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.exchanges.outboundShipping") }),
1832
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: getStylizedAmount(outboundShippingTotal, currencyCode) })
1833
+ ] }),
1834
+ /* @__PURE__ */ jsxs6("div", { className: "mt-4 flex items-center justify-between border-t border-dotted pt-4", children: [
1835
+ /* @__PURE__ */ jsx9("span", { className: "txt-small font-medium", children: t("orders.exchanges.refundAmount") }),
1836
+ /* @__PURE__ */ jsx9("span", { className: "txt-small font-medium", children: getStylizedAmount(estimatedDifference, currencyCode) })
1837
+ ] })
1838
+ ] })
1839
+ ] }),
1840
+ /* @__PURE__ */ jsx9("div", { className: "bg-ui-bg-field mt-8 rounded-lg border py-2 pl-2 pr-4", children: /* @__PURE__ */ jsx9(
1841
+ Form.Field,
1842
+ {
1843
+ control: form.control,
1844
+ name: "send_notification",
1845
+ render: ({ field: { onChange, value, ...field } }) => /* @__PURE__ */ jsxs6(Form.Item, { children: [
1846
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center", children: [
1847
+ /* @__PURE__ */ jsx9(Form.Control, { className: "mr-4 self-start", children: /* @__PURE__ */ jsx9(
1848
+ Switch,
1849
+ {
1850
+ dir: "ltr",
1851
+ className: "mt-[2px] rtl:rotate-180",
1852
+ checked: !!value,
1853
+ onCheckedChange: onChange,
1854
+ ...field,
1855
+ "data-testid": "exchange-create-notify"
1856
+ }
1857
+ ) }),
1858
+ /* @__PURE__ */ jsxs6("div", { className: "block", children: [
1859
+ /* @__PURE__ */ jsx9(Form.Label, { children: t("orders.returns.sendNotification") }),
1860
+ /* @__PURE__ */ jsx9(Form.Hint, { className: "!mt-1", children: t("orders.returns.sendNotificationHint") })
1861
+ ] })
1862
+ ] }),
1863
+ /* @__PURE__ */ jsx9(Form.ErrorMessage, {})
1864
+ ] })
1865
+ }
1866
+ ) }),
1867
+ /* @__PURE__ */ jsx9("div", { className: "p-8" })
1868
+ ] }) }),
1869
+ /* @__PURE__ */ jsx9(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx9("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-end gap-x-2", children: [
1870
+ /* @__PURE__ */ jsx9(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx9(
1871
+ Button3,
1872
+ {
1873
+ type: "button",
1874
+ onClick: handleClose,
1875
+ variant: "secondary",
1876
+ size: "small",
1877
+ isLoading: canceling,
1878
+ disabled: submitting,
1879
+ "data-testid": "exchange-cancel",
1880
+ children: t("orders.exchanges.cancel.title")
1881
+ }
1882
+ ) }),
1883
+ /* @__PURE__ */ jsx9(
1884
+ Button3,
1885
+ {
1886
+ type: "submit",
1887
+ variant: "primary",
1888
+ size: "small",
1889
+ isLoading: submitting || isConfirming,
1890
+ disabled: !exchangeId || canceling || !hasSelection,
1891
+ "data-testid": "exchange-confirm",
1892
+ children: t("orders.exchanges.confirm")
1893
+ },
1894
+ "submit-button"
1895
+ )
1896
+ ] }) }) })
1897
+ ] }) });
1898
+ };
1899
+
1900
+ // src/pages/orders/[id]/exchanges/create/index.tsx
1901
+ import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
1902
+ var Component = () => {
1903
+ const { t } = useTranslation12();
1904
+ return /* @__PURE__ */ jsxs7(RouteFocusModal, { children: [
1905
+ /* @__PURE__ */ jsx10(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx10("span", { className: "sr-only", children: t("orders.exchanges.title") }) }),
1906
+ /* @__PURE__ */ jsx10(RouteFocusModal.Description, { className: "sr-only", children: t("orders.exchanges.title") }),
1907
+ /* @__PURE__ */ jsx10(ExchangeCreateForm, {})
1908
+ ] });
1909
+ };
1910
+ var create_default = Component;
1911
+ export {
1912
+ Component,
1913
+ create_default as default
1914
+ };