@mercurjs/admin 2.0.0-canary.100

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 (447) hide show
  1. package/dist/add-campaign-promotions-CQDZBX3V.js +266 -0
  2. package/dist/adjust-inventory-3GPDYI3V.js +266 -0
  3. package/dist/api-key-management-create-GUNLFGNT.js +283 -0
  4. package/dist/api-key-management-detail-4IL3BQJW.js +87 -0
  5. package/dist/api-key-management-edit-SIXXFLNP.js +107 -0
  6. package/dist/api-key-management-list-XLRD4ASE.js +34 -0
  7. package/dist/api-key-management-sales-channels-GCUMV6YA.js +202 -0
  8. package/dist/campaign-budget-edit-GAP5KUI3.js +148 -0
  9. package/dist/campaign-configuration-LTHPZGYC.js +155 -0
  10. package/dist/campaign-create-TRNE6L26.js +30 -0
  11. package/dist/campaign-detail-GYMMDRUV.js +106 -0
  12. package/dist/campaign-edit-CRQCVEFT.js +207 -0
  13. package/dist/campaign-list-WEKSY62X.js +32 -0
  14. package/dist/categories-metadata-GESU3DEU.js +87 -0
  15. package/dist/category-create-PSAN6SA2.js +23 -0
  16. package/dist/category-detail-67ZTYE5M.js +106 -0
  17. package/dist/category-edit-QYKE3GAC.js +221 -0
  18. package/dist/category-list-ZRDWHPEI.js +33 -0
  19. package/dist/category-organize-D26G234L.js +112 -0
  20. package/dist/category-products-XMIZ2KRR.js +285 -0
  21. package/dist/chunk-25DQRKFS.js +102 -0
  22. package/dist/chunk-25LYVP3C.js +37 -0
  23. package/dist/chunk-26OOAKQ6.js +18 -0
  24. package/dist/chunk-2TDFXWGC.js +742 -0
  25. package/dist/chunk-2Y3WMGN6.js +39 -0
  26. package/dist/chunk-2ZFELO2L.js +13 -0
  27. package/dist/chunk-33XUAKRP.js +6 -0
  28. package/dist/chunk-35NDMIYZ.js +8 -0
  29. package/dist/chunk-3B6MTW5G.js +64 -0
  30. package/dist/chunk-3CKTAFTR.js +143 -0
  31. package/dist/chunk-3EF54XFY.js +64 -0
  32. package/dist/chunk-3GCRM6UM.js +1155 -0
  33. package/dist/chunk-3KOTDGC2.js +18 -0
  34. package/dist/chunk-3QSRE5LS.js +161 -0
  35. package/dist/chunk-3XPXUIK3.js +34 -0
  36. package/dist/chunk-4F5GP7J7.js +45 -0
  37. package/dist/chunk-4GPAS5GW.js +36 -0
  38. package/dist/chunk-4JYZU65L.js +2144 -0
  39. package/dist/chunk-4ZIQGDNH.js +184 -0
  40. package/dist/chunk-54EPH67T.js +34 -0
  41. package/dist/chunk-54RTJBYO.js +153 -0
  42. package/dist/chunk-54TMLQH3.js +9 -0
  43. package/dist/chunk-5A4JNOK3.js +109 -0
  44. package/dist/chunk-5HZT54X7.js +374 -0
  45. package/dist/chunk-5LI2P5VT.js +433 -0
  46. package/dist/chunk-5N24A4CX.js +296 -0
  47. package/dist/chunk-64B6RWZI.js +159 -0
  48. package/dist/chunk-64XMEZ5A.js +50 -0
  49. package/dist/chunk-6ERRELWD.js +3892 -0
  50. package/dist/chunk-6HJINLUB.js +94 -0
  51. package/dist/chunk-6IJMSVC6.js +16 -0
  52. package/dist/chunk-6S72GJRI.js +142 -0
  53. package/dist/chunk-77R2QD4O.js +337 -0
  54. package/dist/chunk-7AV5EJJ5.js +29 -0
  55. package/dist/chunk-7H2I3TA2.js +420 -0
  56. package/dist/chunk-7ITJ4725.js +185 -0
  57. package/dist/chunk-7JZMCLD3.js +165 -0
  58. package/dist/chunk-7KMDLRLG.js +248 -0
  59. package/dist/chunk-7NNA33IY.js +600 -0
  60. package/dist/chunk-7OSCNHHQ.js +69 -0
  61. package/dist/chunk-7RPRNVBS.js +45 -0
  62. package/dist/chunk-7SQW55FI.js +470 -0
  63. package/dist/chunk-7SVLKK6Q.js +31 -0
  64. package/dist/chunk-A2F5MDPU.js +79 -0
  65. package/dist/chunk-AEFDAU3Y.js +110 -0
  66. package/dist/chunk-AFQS6E4N.js +61 -0
  67. package/dist/chunk-AJQ6EVLE.js +501 -0
  68. package/dist/chunk-AW77UWCZ.js +363 -0
  69. package/dist/chunk-AYVH6Q5O.js +31 -0
  70. package/dist/chunk-AZVAL5E5.js +303 -0
  71. package/dist/chunk-BBZ6YISG.js +371 -0
  72. package/dist/chunk-BDGZ4EQO.js +86 -0
  73. package/dist/chunk-BLHFWBK3.js +199 -0
  74. package/dist/chunk-BPTVQM72.js +9496 -0
  75. package/dist/chunk-BYKTBURG.js +250 -0
  76. package/dist/chunk-C6OVKRMH.js +294 -0
  77. package/dist/chunk-C6SUTRP2.js +13 -0
  78. package/dist/chunk-CARSKIPW.js +87 -0
  79. package/dist/chunk-CJQRZEZU.js +614 -0
  80. package/dist/chunk-CMHI2RPL.js +20 -0
  81. package/dist/chunk-CP5IL4P6.js +98 -0
  82. package/dist/chunk-DB6ANJBO.js +35 -0
  83. package/dist/chunk-DBYUB2YI.js +174 -0
  84. package/dist/chunk-DPH3FG5H.js +528 -0
  85. package/dist/chunk-DY3XQPHC.js +31 -0
  86. package/dist/chunk-EEOEIXDA.js +112 -0
  87. package/dist/chunk-EF47ASFU.js +39 -0
  88. package/dist/chunk-EJY35WBK.js +60 -0
  89. package/dist/chunk-EOZUAYQL.js +6 -0
  90. package/dist/chunk-EWFOFSF7.js +78 -0
  91. package/dist/chunk-FD7OJEGQ.js +345 -0
  92. package/dist/chunk-FI474ADU.js +0 -0
  93. package/dist/chunk-FIVW6L2I.js +269 -0
  94. package/dist/chunk-FIYO3KTR.js +710 -0
  95. package/dist/chunk-FMFVTERD.js +0 -0
  96. package/dist/chunk-FQERBIVS.js +0 -0
  97. package/dist/chunk-FWPGOIFA.js +22 -0
  98. package/dist/chunk-G2N27VIE.js +164 -0
  99. package/dist/chunk-G4MIA23Y.js +100 -0
  100. package/dist/chunk-G5OVX555.js +26 -0
  101. package/dist/chunk-GCEOEV6P.js +241 -0
  102. package/dist/chunk-GR6JUIRU.js +32 -0
  103. package/dist/chunk-GVXAFQDF.js +170 -0
  104. package/dist/chunk-GYRTURN7.js +29 -0
  105. package/dist/chunk-HC25LNX7.js +45 -0
  106. package/dist/chunk-HDUVTTOW.js +396 -0
  107. package/dist/chunk-HGHJRKUC.js +223 -0
  108. package/dist/chunk-HINXQTCW.js +97 -0
  109. package/dist/chunk-HLL6GLZO.js +109 -0
  110. package/dist/chunk-HPQG3PEA.js +67 -0
  111. package/dist/chunk-I5LLMPI2.js +108 -0
  112. package/dist/chunk-I6GNV6QA.js +175 -0
  113. package/dist/chunk-IGTRIAUC.js +84 -0
  114. package/dist/chunk-INNFZYX2.js +183 -0
  115. package/dist/chunk-IQPN4PZJ.js +749 -0
  116. package/dist/chunk-IUB4C2WJ.js +420 -0
  117. package/dist/chunk-J54BZXZX.js +83 -0
  118. package/dist/chunk-J5SOBS7K.js +298 -0
  119. package/dist/chunk-JAJMMPOF.js +1260 -0
  120. package/dist/chunk-JHIMVLB2.js +42 -0
  121. package/dist/chunk-JI7HMGMO.js +79 -0
  122. package/dist/chunk-JJ4XUGHZ.js +312 -0
  123. package/dist/chunk-JOX3ZSRT.js +50 -0
  124. package/dist/chunk-JQV7CXEC.js +37 -0
  125. package/dist/chunk-JRTZWK77.js +1764 -0
  126. package/dist/chunk-K6RZE3F7.js +39 -0
  127. package/dist/chunk-KAZ5BYTQ.js +132 -0
  128. package/dist/chunk-KBYZLKI4.js +1093 -0
  129. package/dist/chunk-KHXRL3BH.js +85 -0
  130. package/dist/chunk-KWW4RDRS.js +199 -0
  131. package/dist/chunk-L74EVHCU.js +176 -0
  132. package/dist/chunk-L7DIEO5B.js +33 -0
  133. package/dist/chunk-LAVHRER2.js +17 -0
  134. package/dist/chunk-LFKTHNWI.js +83 -0
  135. package/dist/chunk-LGVVX4I6.js +422 -0
  136. package/dist/chunk-LQAAVRET.js +88 -0
  137. package/dist/chunk-LTBX54CI.js +11 -0
  138. package/dist/chunk-LXSBG6LK.js +18 -0
  139. package/dist/chunk-LXZXXOJ3.js +64 -0
  140. package/dist/chunk-LZO7MWH7.js +102 -0
  141. package/dist/chunk-MAEP2UCK.js +110 -0
  142. package/dist/chunk-MG4GKUJW.js +31 -0
  143. package/dist/chunk-MMDRMNPE.js +424 -0
  144. package/dist/chunk-MO7TNIVQ.js +23 -0
  145. package/dist/chunk-MZCJZRR6.js +381 -0
  146. package/dist/chunk-N2TQXB44.js +1280 -0
  147. package/dist/chunk-N3WRPCPT.js +94 -0
  148. package/dist/chunk-N5IUYCUZ.js +31 -0
  149. package/dist/chunk-N5XVXV47.js +530 -0
  150. package/dist/chunk-NBMM2TZK.js +33 -0
  151. package/dist/chunk-NCMUZ6BQ.js +0 -0
  152. package/dist/chunk-NCYTM57J.js +160 -0
  153. package/dist/chunk-NHGR2OFE.js +292 -0
  154. package/dist/chunk-NOWUEJ74.js +44 -0
  155. package/dist/chunk-NQ2RDSI3.js +43 -0
  156. package/dist/chunk-NXDFDEKP.js +0 -0
  157. package/dist/chunk-NYWESQ6J.js +86705 -0
  158. package/dist/chunk-NZN7PFPB.js +169 -0
  159. package/dist/chunk-O4LSCHTC.js +245 -0
  160. package/dist/chunk-O5VKW5FL.js +41 -0
  161. package/dist/chunk-O5ZOACVV.js +593 -0
  162. package/dist/chunk-OEDISQ2O.js +98 -0
  163. package/dist/chunk-OJI3SRZ3.js +373 -0
  164. package/dist/chunk-OSI3M4M2.js +473 -0
  165. package/dist/chunk-OT5X3VOQ.js +42 -0
  166. package/dist/chunk-OZMCKYJL.js +204 -0
  167. package/dist/chunk-P52JGPUG.js +135 -0
  168. package/dist/chunk-PHOCVOZ5.js +9 -0
  169. package/dist/chunk-PJTR2MBS.js +459 -0
  170. package/dist/chunk-PUQSQBZW.js +49 -0
  171. package/dist/chunk-PVZBDWLK.js +41 -0
  172. package/dist/chunk-PWMB7ITO.js +344 -0
  173. package/dist/chunk-PXYDR7WQ.js +48 -0
  174. package/dist/chunk-PYF5EER5.js +32 -0
  175. package/dist/chunk-Q6GUA5VE.js +92 -0
  176. package/dist/chunk-QDIPFZLV.js +113 -0
  177. package/dist/chunk-QDPLZDMX.js +17 -0
  178. package/dist/chunk-QG6PLWNH.js +106 -0
  179. package/dist/chunk-QLTN2DIY.js +119 -0
  180. package/dist/chunk-QSGR43JM.js +30 -0
  181. package/dist/chunk-QUNCQMFH.js +219 -0
  182. package/dist/chunk-QUTZUW55.js +163 -0
  183. package/dist/chunk-QVLL4MKH.js +245 -0
  184. package/dist/chunk-R325CPYC.js +88 -0
  185. package/dist/chunk-R4O667NT.js +80 -0
  186. package/dist/chunk-R55Q5LAH.js +47 -0
  187. package/dist/chunk-RF7BE47J.js +685 -0
  188. package/dist/chunk-RHKRREUU.js +15 -0
  189. package/dist/chunk-RHYS2TFP.js +266 -0
  190. package/dist/chunk-RK5N3XIX.js +56 -0
  191. package/dist/chunk-RQQ53CQJ.js +87 -0
  192. package/dist/chunk-RSBZREKG.js +144 -0
  193. package/dist/chunk-RXM4B6HR.js +8 -0
  194. package/dist/chunk-S2WEYEQR.js +14 -0
  195. package/dist/chunk-S3L6CIN2.js +459 -0
  196. package/dist/chunk-S4SVK5DE.js +39 -0
  197. package/dist/chunk-SBH4E5NY.js +129 -0
  198. package/dist/chunk-SDNGZDNK.js +170 -0
  199. package/dist/chunk-SJQ4QAFK.js +471 -0
  200. package/dist/chunk-SMQT3ZNO.js +8 -0
  201. package/dist/chunk-STSW4GDV.js +325 -0
  202. package/dist/chunk-SWL7ZCP3.js +11 -0
  203. package/dist/chunk-THHRRYRS.js +16 -0
  204. package/dist/chunk-THYWJQI4.js +635 -0
  205. package/dist/chunk-TK3XKN2P.js +357 -0
  206. package/dist/chunk-TKEAOWBZ.js +178 -0
  207. package/dist/chunk-TKFMOTJK.js +297 -0
  208. package/dist/chunk-TKGWSUEI.js +0 -0
  209. package/dist/chunk-TKSKCH3S.js +199 -0
  210. package/dist/chunk-TLE6YHGH.js +26 -0
  211. package/dist/chunk-TN4TIT7O.js +116 -0
  212. package/dist/chunk-TOUMBTYI.js +41 -0
  213. package/dist/chunk-TP7M43SI.js +189 -0
  214. package/dist/chunk-TUJIAA5O.js +101 -0
  215. package/dist/chunk-TZSOL34K.js +106 -0
  216. package/dist/chunk-U2EI2ZLM.js +32 -0
  217. package/dist/chunk-U2L77ZDR.js +17 -0
  218. package/dist/chunk-U2ZFCAPX.js +34 -0
  219. package/dist/chunk-U3OWJE7V.js +4113 -0
  220. package/dist/chunk-U5MJIHLY.js +87 -0
  221. package/dist/chunk-U5QDMLTR.js +294 -0
  222. package/dist/chunk-UI2BJVP5.js +170 -0
  223. package/dist/chunk-ULJ3OMWU.js +467 -0
  224. package/dist/chunk-UM7ZR3VU.js +14 -0
  225. package/dist/chunk-UQITHKTH.js +342 -0
  226. package/dist/chunk-UXD3VNBO.js +53 -0
  227. package/dist/chunk-UZWFZMOX.js +40 -0
  228. package/dist/chunk-V5J73NPW.js +117 -0
  229. package/dist/chunk-V6LO4BXB.js +460 -0
  230. package/dist/chunk-V74Y5NIV.js +49 -0
  231. package/dist/chunk-V7Y7WBGF.js +112 -0
  232. package/dist/chunk-VEW7PQ3X.js +209 -0
  233. package/dist/chunk-VHCDSNXF.js +89 -0
  234. package/dist/chunk-VKOE5J66.js +31 -0
  235. package/dist/chunk-VOHEQ7B5.js +31 -0
  236. package/dist/chunk-VRGXUUPH.js +772 -0
  237. package/dist/chunk-VVWB3GIK.js +70 -0
  238. package/dist/chunk-VW56KWO2.js +9 -0
  239. package/dist/chunk-VXW3BCN2.js +171 -0
  240. package/dist/chunk-VZEMURY7.js +35 -0
  241. package/dist/chunk-W6Y3PPU5.js +73 -0
  242. package/dist/chunk-WBNGBRBK.js +482 -0
  243. package/dist/chunk-WCEMRNW4.js +6 -0
  244. package/dist/chunk-WEVK4TBV.js +257 -0
  245. package/dist/chunk-WIYFXWRI.js +30 -0
  246. package/dist/chunk-WMA3WTCM.js +117 -0
  247. package/dist/chunk-WW7VLWKJ.js +360 -0
  248. package/dist/chunk-X6HEEFUW.js +1104 -0
  249. package/dist/chunk-XBFWFGZH.js +249 -0
  250. package/dist/chunk-XFKRBJLK.js +104 -0
  251. package/dist/chunk-XFR5JLNF.js +44 -0
  252. package/dist/chunk-XIZLPYEE.js +261 -0
  253. package/dist/chunk-XQNVC4Q7.js +212 -0
  254. package/dist/chunk-XR2UEF6U.js +433 -0
  255. package/dist/chunk-XSEF6KRY.js +335 -0
  256. package/dist/chunk-XSX255FK.js +12 -0
  257. package/dist/chunk-Y2M536WR.js +67 -0
  258. package/dist/chunk-Y456KVIN.js +116 -0
  259. package/dist/chunk-Y7QKP6QU.js +35 -0
  260. package/dist/chunk-YAMNPEPW.js +345 -0
  261. package/dist/chunk-YBZWO4ZV.js +57 -0
  262. package/dist/chunk-YDAJI7WF.js +389 -0
  263. package/dist/chunk-YMKZS2HK.js +82 -0
  264. package/dist/chunk-YQYGAFCS.js +119 -0
  265. package/dist/chunk-YVCBMOJG.js +50 -0
  266. package/dist/chunk-YWWUOGJA.js +62 -0
  267. package/dist/chunk-YXFG3M2D.js +792 -0
  268. package/dist/chunk-ZA2KFUFR.js +19 -0
  269. package/dist/chunk-ZGEMSYN7.js +61 -0
  270. package/dist/chunk-ZJO4DDOP.js +454 -0
  271. package/dist/chunk-ZNA2XOGX.js +675 -0
  272. package/dist/chunk-ZQZHFMD7.js +19 -0
  273. package/dist/collection-add-products-4TTEF6QV.js +288 -0
  274. package/dist/collection-create-SD4GKHFC.js +134 -0
  275. package/dist/collection-detail-64YVMLBU.js +97 -0
  276. package/dist/collection-edit-Z474HXCJ.js +122 -0
  277. package/dist/collection-list-OTSGOEBC.js +79 -0
  278. package/dist/collection-metadata-FFHA6CQ3.js +84 -0
  279. package/dist/commission-rate-create-7BBUGS2I.js +779 -0
  280. package/dist/commission-rate-detail-FORKXXJY.js +83 -0
  281. package/dist/commission-rate-edit-SAX2DAND.js +762 -0
  282. package/dist/commission-rate-list-EESTCCRP.js +28 -0
  283. package/dist/constants-CAwtRicB.d.ts +42 -0
  284. package/dist/customer-create-WA4GYGVD.js +184 -0
  285. package/dist/customer-create-address-YBI4KWWH.js +300 -0
  286. package/dist/customer-detail-SDE4TDZD.js +107 -0
  287. package/dist/customer-edit-TFR6PVJJ.js +193 -0
  288. package/dist/customer-group-add-customers-77BVWLTN.js +247 -0
  289. package/dist/customer-group-create-32UIUO46.js +114 -0
  290. package/dist/customer-group-detail-QRY6BHGI.js +106 -0
  291. package/dist/customer-group-edit-HFL7LZZZ.js +109 -0
  292. package/dist/customer-group-list-Q3T72VH2.js +57 -0
  293. package/dist/customer-group-metadata-FXI3J6DB.js +85 -0
  294. package/dist/customer-list-CXTUBLCK.js +33 -0
  295. package/dist/customer-metadata-BV4CHHWI.js +85 -0
  296. package/dist/customers-add-customer-group-SUE2KKJR.js +312 -0
  297. package/dist/edit-inventory-item-DDRUGVSK.js +156 -0
  298. package/dist/edit-inventory-item-attributes-MDL7FSLR.js +327 -0
  299. package/dist/edit-reservation-JWABBNJ6.js +247 -0
  300. package/dist/edit-rules-ECNFIPUC.js +320 -0
  301. package/dist/home-I3OILW5Z.js +16 -0
  302. package/dist/index.css +6 -0
  303. package/dist/index.d.ts +255 -0
  304. package/dist/index.js +4989 -0
  305. package/dist/inventory-create-S6CB4JYN.js +56 -0
  306. package/dist/inventory-detail-OIKNOS5A.js +107 -0
  307. package/dist/inventory-list-XSHWCPO4.js +30 -0
  308. package/dist/inventory-metadata-MHGDNLXT.js +87 -0
  309. package/dist/inventory-stock-JG5CZWZA.js +292 -0
  310. package/dist/invite-25CGHT4W.js +373 -0
  311. package/dist/location-create-G3MNWQWB.js +239 -0
  312. package/dist/location-detail-5CGAZMBR.js +100 -0
  313. package/dist/location-edit-UI6AWCZS.js +254 -0
  314. package/dist/location-fulfillment-providers-BA2VMZHX.js +293 -0
  315. package/dist/location-list-656DEW7L.js +53 -0
  316. package/dist/location-sales-channels-WXBK4EJO.js +216 -0
  317. package/dist/location-service-zone-create-647O67PU.js +174 -0
  318. package/dist/location-service-zone-edit-BUY6HNZM.js +135 -0
  319. package/dist/location-service-zone-manage-areas-X2ZGRHHA.js +155 -0
  320. package/dist/location-service-zone-shipping-option-create-IASFWJ2Z.js +57 -0
  321. package/dist/location-service-zone-shipping-option-edit-IJDU5PTW.js +363 -0
  322. package/dist/location-service-zone-shipping-option-pricing-3T7HLKJC.js +363 -0
  323. package/dist/login-WU5VB5LW.js +264 -0
  324. package/dist/manage-locations-IJIPCYAY.js +250 -0
  325. package/dist/marketplace-add-currencies-RXLEQ6MZ.js +305 -0
  326. package/dist/marketplace-detail-23KSAJVI.js +75 -0
  327. package/dist/marketplace-edit-XPIEDQYD.js +247 -0
  328. package/dist/marketplace-metadata-5GEWGH2M.js +89 -0
  329. package/dist/no-match-JLVLPCRH.js +33 -0
  330. package/dist/order-allocate-items-GYGER65Z.js +559 -0
  331. package/dist/order-create-claim-RNUFU2MP.js +2207 -0
  332. package/dist/order-create-edit-DLH76B2Q.js +936 -0
  333. package/dist/order-create-exchange-FA27FZU7.js +2194 -0
  334. package/dist/order-create-fulfillment-4F5JAUOX.js +625 -0
  335. package/dist/order-create-refund-3LCTQXFD.js +407 -0
  336. package/dist/order-create-return-EO2C5RAA.js +1293 -0
  337. package/dist/order-create-shipment-PIQ43ZSG.js +212 -0
  338. package/dist/order-detail-2U26JNU2.js +123 -0
  339. package/dist/order-edit-billing-address-PRXCLUNR.js +404 -0
  340. package/dist/order-edit-email-GVKVQESG.js +175 -0
  341. package/dist/order-edit-shipping-address-UDNHXO2V.js +401 -0
  342. package/dist/order-list-U2HL7VBX.js +49 -0
  343. package/dist/order-metadata-HPXIR6KI.js +86 -0
  344. package/dist/order-receive-return-FMM74XYM.js +553 -0
  345. package/dist/order-request-transfer-SI5PSOKA.js +575 -0
  346. package/dist/pages/index.d.ts +3165 -0
  347. package/dist/pages/index.js +447 -0
  348. package/dist/payout-detail-L4VYAP53.js +52 -0
  349. package/dist/payout-list-4S6MAU4R.js +30 -0
  350. package/dist/price-list-configuration-F2BZC6QX.js +357 -0
  351. package/dist/price-list-create-ZJTDGJSS.js +76 -0
  352. package/dist/price-list-detail-IUJXNM6Y.js +103 -0
  353. package/dist/price-list-edit-CERYYMC5.js +228 -0
  354. package/dist/price-list-list-RBD2MEZ5.js +36 -0
  355. package/dist/price-list-prices-add-AJJ76VMY.js +71 -0
  356. package/dist/price-list-prices-edit-2NYN6WVJ.js +332 -0
  357. package/dist/product-attributes-EUDG25XA.js +362 -0
  358. package/dist/product-create-XA7UOISW.js +68 -0
  359. package/dist/product-create-option-BG2ZKSFN.js +148 -0
  360. package/dist/product-create-variant-4Z6HSHRE.js +54 -0
  361. package/dist/product-detail-F67SLUIA.js +103 -0
  362. package/dist/product-edit-HFWSBQQI.js +401 -0
  363. package/dist/product-edit-option-Y46SNVHN.js +156 -0
  364. package/dist/product-export-ABNA6ZTY.js +132 -0
  365. package/dist/product-import-SQSXBPK5.js +265 -0
  366. package/dist/product-list-NWHRQHVJ.js +86 -0
  367. package/dist/product-media-YIQCVDCC.js +883 -0
  368. package/dist/product-metadata-2Z5DIXJH.js +87 -0
  369. package/dist/product-organization-L666C2EQ.js +316 -0
  370. package/dist/product-prices-DPGO4KHT.js +267 -0
  371. package/dist/product-sales-channels-6IS6T3EC.js +161 -0
  372. package/dist/product-shipping-profile-LMLRMJ36.js +150 -0
  373. package/dist/product-stock-AQKD6EQO.js +542 -0
  374. package/dist/product-tag-create-5CF7JLN5.js +126 -0
  375. package/dist/product-tag-detail-2RJNUUT7.js +136 -0
  376. package/dist/product-tag-edit-KGT54WP5.js +138 -0
  377. package/dist/product-tag-list-PJG7ICZE.js +130 -0
  378. package/dist/product-tag-metadata-WU7DVJUM.js +84 -0
  379. package/dist/product-type-create-WHYGTCYX.js +102 -0
  380. package/dist/product-type-detail-MZ3MAV2B.js +98 -0
  381. package/dist/product-type-edit-A4IE6BSF.js +114 -0
  382. package/dist/product-type-list-ND2IIR6O.js +35 -0
  383. package/dist/product-type-metadata-KX4ETP3Y.js +84 -0
  384. package/dist/product-variant-detail-USZXPSVX.js +112 -0
  385. package/dist/product-variant-edit-5L2GWAHB.js +545 -0
  386. package/dist/product-variant-manage-inventory-items-54V2HTA6.js +341 -0
  387. package/dist/product-variant-metadata-SBYZTEIH.js +90 -0
  388. package/dist/profile-detail-OAQD5VJC.js +18 -0
  389. package/dist/profile-edit-DSZCGRY7.js +177 -0
  390. package/dist/promotion-add-campaign-JC4B53LS.js +44 -0
  391. package/dist/promotion-create-A6FMNECA.js +54 -0
  392. package/dist/promotion-detail-XOQTYXTV.js +88 -0
  393. package/dist/promotion-edit-details-KFZ2VVVQ.js +513 -0
  394. package/dist/promotion-list-EH7CW4JZ.js +58 -0
  395. package/dist/refund-reason-create-EMGCAW5S.js +196 -0
  396. package/dist/refund-reason-edit-3D25LGKM.js +196 -0
  397. package/dist/refund-reason-list-V7HDVFS2.js +102 -0
  398. package/dist/region-add-countries-ZAQBBXIL.js +227 -0
  399. package/dist/region-create-IMSMEASB.js +508 -0
  400. package/dist/region-detail-RASFBR5O.js +74 -0
  401. package/dist/region-edit-HGSLB3RU.js +381 -0
  402. package/dist/region-list-WEILXVMS.js +35 -0
  403. package/dist/region-metadata-4COKDRZH.js +87 -0
  404. package/dist/reservation-create-CIYW3ZKU.js +310 -0
  405. package/dist/reservation-detail-2ARWTBE6.js +83 -0
  406. package/dist/reservation-list-W6IOXQZK.js +31 -0
  407. package/dist/reservation-metadata-3ZJ2C5BM.js +87 -0
  408. package/dist/reset-password-YQ6HMFFZ.js +458 -0
  409. package/dist/return-reason-create-HHZ3EMCC.js +166 -0
  410. package/dist/return-reason-edit-5P43JRYC.js +169 -0
  411. package/dist/return-reason-list-32MCIQMK.js +81 -0
  412. package/dist/sales-channel-add-products-U2UTBUKE.js +278 -0
  413. package/dist/sales-channel-create-TMRTMLIX.js +155 -0
  414. package/dist/sales-channel-detail-FRBKGP4X.js +98 -0
  415. package/dist/sales-channel-edit-4LE2N6EV.js +164 -0
  416. package/dist/sales-channel-list-36UHU63C.js +50 -0
  417. package/dist/sales-channel-metadata-OKKVLC7G.js +92 -0
  418. package/dist/seller-address-edit-VH4X5OIO.js +223 -0
  419. package/dist/seller-details-52PG56BK.js +104 -0
  420. package/dist/seller-edit-TU72D5QS.js +331 -0
  421. package/dist/seller-list-CYNCPXYT.js +80 -0
  422. package/dist/settings-AVE3VCCM.js +19 -0
  423. package/dist/shipping-option-type-create-ZHRADP5E.js +199 -0
  424. package/dist/shipping-option-type-detail-ZDEEU3P5.js +82 -0
  425. package/dist/shipping-option-type-edit-2FCNVHNE.js +195 -0
  426. package/dist/shipping-option-type-list-OCCZ4DNS.js +60 -0
  427. package/dist/shipping-profile-create-WLHDFQ4Q.js +124 -0
  428. package/dist/shipping-profile-detail-AUWRGYYL.js +57 -0
  429. package/dist/shipping-profile-metadata-W7CND3IQ.js +88 -0
  430. package/dist/shipping-profiles-list-RZT6HIZV.js +27 -0
  431. package/dist/tax-region-create-U5JWJUX4.js +304 -0
  432. package/dist/tax-region-detail-UNGDO64V.js +68 -0
  433. package/dist/tax-region-edit-5DOYTPEF.js +166 -0
  434. package/dist/tax-region-list-MRQ63BL3.js +27 -0
  435. package/dist/tax-region-metadata-WN3XSWGA.js +87 -0
  436. package/dist/tax-region-province-create-3GZUYVBY.js +316 -0
  437. package/dist/tax-region-province-detail-QTBP47GV.js +99 -0
  438. package/dist/tax-region-tax-override-create-PRZ3DEZE.js +688 -0
  439. package/dist/tax-region-tax-override-edit-YAA6TB6A.js +797 -0
  440. package/dist/tax-region-tax-rate-create-KHNADBCN.js +194 -0
  441. package/dist/tax-region-tax-rate-edit-JR5262VW.js +193 -0
  442. package/dist/user-detail-I66RREWP.js +55 -0
  443. package/dist/user-edit-LBJOZ4LG.js +116 -0
  444. package/dist/user-invite-EUNVBT5W.js +398 -0
  445. package/dist/user-list-BDJJI33F.js +28 -0
  446. package/dist/user-metadata-4RXAMVDT.js +87 -0
  447. package/package.json +87 -0
@@ -0,0 +1,2194 @@
1
+ import {
2
+ ItemPlaceholder
3
+ } from "./chunk-U2L77ZDR.js";
4
+ import {
5
+ OutboundShippingPlaceholder,
6
+ ReturnShippingPlaceholder
7
+ } from "./chunk-S4SVK5DE.js";
8
+ import {
9
+ useAddExchangeInboundItems,
10
+ useAddExchangeInboundShipping,
11
+ useAddExchangeOutboundItems,
12
+ useAddExchangeOutboundShipping,
13
+ useCancelExchangeRequest,
14
+ useCreateExchange,
15
+ useDeleteExchangeInboundShipping,
16
+ useDeleteExchangeOutboundShipping,
17
+ useExchange,
18
+ useExchangeConfirmRequest,
19
+ useRemoveExchangeInboundItem,
20
+ useRemoveExchangeOutboundItem,
21
+ useUpdateExchangeInboundItem,
22
+ useUpdateExchangeInboundShipping,
23
+ useUpdateExchangeOutboundItems,
24
+ useUpdateExchangeOutboundShipping
25
+ } from "./chunk-PWMB7ITO.js";
26
+ import {
27
+ getFormattedShippingOptionLocationName
28
+ } from "./chunk-HC25LNX7.js";
29
+ import {
30
+ useReturnReasons
31
+ } from "./chunk-RQQ53CQJ.js";
32
+ import {
33
+ getReturnableQuantity
34
+ } from "./chunk-UM7ZR3VU.js";
35
+ import {
36
+ MoneyAmountCell
37
+ } from "./chunk-2Y3WMGN6.js";
38
+ import {
39
+ DEFAULT_FIELDS
40
+ } from "./chunk-Y2M536WR.js";
41
+ import {
42
+ useReturn,
43
+ useUpdateReturn
44
+ } from "./chunk-PJTR2MBS.js";
45
+ import {
46
+ getStylizedAmount
47
+ } from "./chunk-PXYDR7WQ.js";
48
+ import {
49
+ ProductCell,
50
+ ProductHeader
51
+ } from "./chunk-FWPGOIFA.js";
52
+ import "./chunk-PHOCVOZ5.js";
53
+ import {
54
+ Thumbnail
55
+ } from "./chunk-WIYFXWRI.js";
56
+ import "./chunk-FQERBIVS.js";
57
+ import {
58
+ _DataTable,
59
+ useDataTable
60
+ } from "./chunk-ULJ3OMWU.js";
61
+ import "./chunk-YBZWO4ZV.js";
62
+ import "./chunk-KAZ5BYTQ.js";
63
+ import "./chunk-3EF54XFY.js";
64
+ import {
65
+ currencies
66
+ } from "./chunk-IQPN4PZJ.js";
67
+ import {
68
+ Combobox
69
+ } from "./chunk-AW77UWCZ.js";
70
+ import {
71
+ KeyboundForm
72
+ } from "./chunk-U2ZFCAPX.js";
73
+ import "./chunk-INNFZYX2.js";
74
+ import {
75
+ ActionMenu
76
+ } from "./chunk-BDGZ4EQO.js";
77
+ import "./chunk-LAVHRER2.js";
78
+ import "./chunk-Y7QKP6QU.js";
79
+ import "./chunk-KBYZLKI4.js";
80
+ import "./chunk-YWWUOGJA.js";
81
+ import {
82
+ useQueryParams
83
+ } from "./chunk-THHRRYRS.js";
84
+ import "./chunk-UZWFZMOX.js";
85
+ import "./chunk-XQNVC4Q7.js";
86
+ import {
87
+ RouteFocusModal,
88
+ StackedFocusModal,
89
+ useRouteModal,
90
+ useStackedModal
91
+ } from "./chunk-V6LO4BXB.js";
92
+ import {
93
+ Form
94
+ } from "./chunk-3QSRE5LS.js";
95
+ import {
96
+ useVariants
97
+ } from "./chunk-YAMNPEPW.js";
98
+ import "./chunk-R325CPYC.js";
99
+ import "./chunk-J54BZXZX.js";
100
+ import "./chunk-JI7HMGMO.js";
101
+ import "./chunk-EWFOFSF7.js";
102
+ import "./chunk-YQYGAFCS.js";
103
+ import "./chunk-HLL6GLZO.js";
104
+ import "./chunk-CARSKIPW.js";
105
+ import "./chunk-25DQRKFS.js";
106
+ import "./chunk-R4O667NT.js";
107
+ import "./chunk-MO7TNIVQ.js";
108
+ import "./chunk-A2F5MDPU.js";
109
+ import "./chunk-L7DIEO5B.js";
110
+ import "./chunk-EEOEIXDA.js";
111
+ import "./chunk-OEDISQ2O.js";
112
+ import "./chunk-GCEOEV6P.js";
113
+ import "./chunk-PYF5EER5.js";
114
+ import "./chunk-HPQG3PEA.js";
115
+ import "./chunk-FIVW6L2I.js";
116
+ import {
117
+ useShippingOptions
118
+ } from "./chunk-Q6GUA5VE.js";
119
+ import {
120
+ useOrder,
121
+ useOrderPreview,
122
+ useOrderShippingOptions
123
+ } from "./chunk-QVLL4MKH.js";
124
+ import "./chunk-I5LLMPI2.js";
125
+ import {
126
+ useStockLocations
127
+ } from "./chunk-VXW3BCN2.js";
128
+ import "./chunk-VHCDSNXF.js";
129
+ import "./chunk-EJY35WBK.js";
130
+ import "./chunk-GYRTURN7.js";
131
+ import "./chunk-QUTZUW55.js";
132
+ import "./chunk-XFKRBJLK.js";
133
+ import "./chunk-WBNGBRBK.js";
134
+ import "./chunk-RHKRREUU.js";
135
+ import "./chunk-ZA2KFUFR.js";
136
+ import {
137
+ sdk
138
+ } from "./chunk-LXZXXOJ3.js";
139
+ import "./chunk-NBMM2TZK.js";
140
+
141
+ // src/pages/orders/order-create-exchange/exchange-create.tsx
142
+ import { toast as toast4 } from "@medusajs/ui";
143
+ import { useEffect as useEffect4, useState as useState6 } from "react";
144
+ import { useTranslation as useTranslation12 } from "react-i18next";
145
+ import { useNavigate, useParams } from "react-router-dom";
146
+
147
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx
148
+ import { zodResolver } from "@hookform/resolvers/zod";
149
+ import { PencilSquare } from "@medusajs/icons";
150
+ import {
151
+ Button as Button3,
152
+ CurrencyInput,
153
+ Heading as Heading3,
154
+ IconButton as IconButton2,
155
+ Switch,
156
+ toast as toast3,
157
+ usePrompt
158
+ } from "@medusajs/ui";
159
+ import { useEffect as useEffect3, useMemo as useMemo6, useState as useState5 } from "react";
160
+ import { useForm } from "react-hook-form";
161
+ import { useTranslation as useTranslation11 } from "react-i18next";
162
+
163
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/schema.ts
164
+ import { z } from "zod";
165
+ var ExchangeCreateSchema = z.object({
166
+ inbound_items: z.array(
167
+ z.object({
168
+ item_id: z.string(),
169
+ quantity: z.number(),
170
+ reason_id: z.string().nullish(),
171
+ note: z.string().nullish()
172
+ })
173
+ ),
174
+ outbound_items: z.array(
175
+ z.object({
176
+ item_id: z.string(),
177
+ quantity: z.number()
178
+ })
179
+ ),
180
+ location_id: z.string().optional(),
181
+ inbound_option_id: z.string().nullish(),
182
+ outbound_option_id: z.string().nullish(),
183
+ send_notification: z.boolean().optional()
184
+ });
185
+
186
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx
187
+ import { Alert, Button, Heading, Text as Text2, toast } from "@medusajs/ui";
188
+ import { useEffect, useMemo as useMemo3, useState as useState2 } from "react";
189
+ import { useFieldArray } from "react-hook-form";
190
+ import { useTranslation as useTranslation5 } from "react-i18next";
191
+
192
+ // src/pages/orders/order-create-exchange/components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
193
+ import { useMemo as useMemo2, useState } from "react";
194
+ import { useTranslation as useTranslation3 } from "react-i18next";
195
+
196
+ // src/pages/orders/order-create-exchange/components/add-exchange-inbound-items-table/use-exchange-item-table-columns.tsx
197
+ import { Checkbox } from "@medusajs/ui";
198
+ import { createColumnHelper } from "@tanstack/react-table";
199
+ import { useMemo } from "react";
200
+ import { useTranslation } from "react-i18next";
201
+ import { jsx } from "react/jsx-runtime";
202
+ var columnHelper = createColumnHelper();
203
+ var useExchangeItemTableColumns = (currencyCode) => {
204
+ const { t } = useTranslation();
205
+ return useMemo(
206
+ () => [
207
+ columnHelper.display({
208
+ id: "select",
209
+ header: ({ table }) => {
210
+ return /* @__PURE__ */ jsx(
211
+ Checkbox,
212
+ {
213
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
214
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
215
+ }
216
+ );
217
+ },
218
+ cell: ({ row }) => {
219
+ const isSelectable = row.getCanSelect();
220
+ return /* @__PURE__ */ jsx(
221
+ Checkbox,
222
+ {
223
+ disabled: !isSelectable,
224
+ checked: row.getIsSelected(),
225
+ onCheckedChange: (value) => row.toggleSelected(!!value),
226
+ onClick: (e) => {
227
+ e.stopPropagation();
228
+ }
229
+ }
230
+ );
231
+ }
232
+ }),
233
+ columnHelper.display({
234
+ id: "product",
235
+ header: () => /* @__PURE__ */ jsx(ProductHeader, {}),
236
+ cell: ({ row }) => /* @__PURE__ */ jsx(
237
+ ProductCell,
238
+ {
239
+ product: {
240
+ thumbnail: row.original.thumbnail,
241
+ title: row.original.product_title
242
+ }
243
+ }
244
+ )
245
+ }),
246
+ columnHelper.accessor("variant.sku", {
247
+ header: t("fields.sku"),
248
+ cell: ({ getValue }) => {
249
+ return getValue() || "-";
250
+ }
251
+ }),
252
+ columnHelper.accessor("variant.title", {
253
+ header: t("fields.variant")
254
+ }),
255
+ columnHelper.accessor("quantity", {
256
+ header: () => /* @__PURE__ */ jsx("div", { className: "flex size-full items-center overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: t("fields.quantity") }) }),
257
+ cell: ({ row }) => {
258
+ return getReturnableQuantity(row.original);
259
+ }
260
+ }),
261
+ columnHelper.accessor("refundable_total", {
262
+ 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") }) }),
263
+ cell: ({ getValue }) => {
264
+ const amount = getValue() || 0;
265
+ const stylized = getStylizedAmount(amount, currencyCode);
266
+ return /* @__PURE__ */ jsx("div", { className: "flex size-full items-center justify-end overflow-hidden text-right", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: stylized }) });
267
+ }
268
+ })
269
+ ],
270
+ [t, currencyCode]
271
+ );
272
+ };
273
+
274
+ // src/pages/orders/order-create-exchange/components/add-exchange-inbound-items-table/use-exchange-item-table-filters.tsx
275
+ import { useTranslation as useTranslation2 } from "react-i18next";
276
+ var useExchangeItemTableFilters = () => {
277
+ const { t } = useTranslation2();
278
+ const filters = [
279
+ {
280
+ key: "created_at",
281
+ label: t("fields.createdAt"),
282
+ type: "date"
283
+ },
284
+ {
285
+ key: "updated_at",
286
+ label: t("fields.updatedAt"),
287
+ type: "date"
288
+ }
289
+ ];
290
+ return filters;
291
+ };
292
+
293
+ // src/pages/orders/order-create-exchange/components/add-exchange-inbound-items-table/use-exchange-item-table-query.tsx
294
+ var useExchangeItemTableQuery = ({
295
+ pageSize = 50,
296
+ prefix
297
+ }) => {
298
+ const raw = useQueryParams(
299
+ ["q", "offset", "order", "created_at", "updated_at"],
300
+ prefix
301
+ );
302
+ const { offset, created_at, updated_at, ...rest } = raw;
303
+ const searchParams = {
304
+ ...rest,
305
+ limit: pageSize,
306
+ offset: offset ? Number(offset) : 0,
307
+ created_at: created_at ? JSON.parse(created_at) : void 0,
308
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
309
+ };
310
+ return { searchParams, raw };
311
+ };
312
+
313
+ // src/pages/orders/order-create-exchange/components/add-exchange-inbound-items-table/add-exchange-inbound-items-table.tsx
314
+ import { jsx as jsx2 } from "react/jsx-runtime";
315
+ var PAGE_SIZE = 50;
316
+ var PREFIX = "rit";
317
+ var AddExchangeInboundItemsTable = ({
318
+ onSelectionChange,
319
+ selectedItems,
320
+ items,
321
+ currencyCode
322
+ }) => {
323
+ const { t } = useTranslation3();
324
+ const [rowSelection, setRowSelection] = useState(
325
+ selectedItems.reduce((acc, id) => {
326
+ acc[id] = true;
327
+ return acc;
328
+ }, {})
329
+ );
330
+ const updater = (fn) => {
331
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
332
+ setRowSelection(newState);
333
+ onSelectionChange(Object.keys(newState));
334
+ };
335
+ const { searchParams, raw } = useExchangeItemTableQuery({
336
+ pageSize: PAGE_SIZE,
337
+ prefix: PREFIX
338
+ });
339
+ const queriedItems = useMemo2(() => {
340
+ const { order, offset, limit, q, created_at, updated_at } = searchParams;
341
+ let results = items;
342
+ if (q) {
343
+ results = results.filter((i) => {
344
+ return i.product_title?.toLowerCase().includes(q.toLowerCase()) || i.variant_title?.toLowerCase().includes(q.toLowerCase()) || i.variant_sku?.toLowerCase().includes(q.toLowerCase());
345
+ });
346
+ }
347
+ if (order) {
348
+ const direction = order[0] === "-" ? "desc" : "asc";
349
+ const field = order.replace("-", "");
350
+ results = sortItems(results, field, direction);
351
+ }
352
+ if (created_at) {
353
+ results = filterByDate(results, created_at, "created_at");
354
+ }
355
+ if (updated_at) {
356
+ results = filterByDate(results, updated_at, "updated_at");
357
+ }
358
+ return results.slice(offset, offset + limit);
359
+ }, [items, currencyCode, searchParams]);
360
+ const columns = useExchangeItemTableColumns(currencyCode);
361
+ const filters = useExchangeItemTableFilters();
362
+ const { table } = useDataTable({
363
+ data: queriedItems,
364
+ columns,
365
+ count: queriedItems.length,
366
+ enablePagination: true,
367
+ getRowId: (row) => row.id,
368
+ pageSize: PAGE_SIZE,
369
+ enableRowSelection: (row) => {
370
+ return getReturnableQuantity(row.original) > 0;
371
+ },
372
+ rowSelection: {
373
+ state: rowSelection,
374
+ updater
375
+ }
376
+ });
377
+ return /* @__PURE__ */ jsx2("div", { className: "flex size-full flex-col overflow-hidden", children: /* @__PURE__ */ jsx2(
378
+ _DataTable,
379
+ {
380
+ table,
381
+ columns,
382
+ pageSize: PAGE_SIZE,
383
+ count: queriedItems.length,
384
+ filters,
385
+ pagination: true,
386
+ layout: "fill",
387
+ search: true,
388
+ orderBy: [
389
+ { key: "product_title", label: t("fields.product") },
390
+ { key: "variant_title", label: t("fields.variant") },
391
+ { key: "sku", label: t("fields.sku") }
392
+ ],
393
+ prefix: PREFIX,
394
+ queryObject: raw
395
+ }
396
+ ) });
397
+ };
398
+ var sortItems = (items, field, direction) => {
399
+ return items.sort((a, b) => {
400
+ let aValue;
401
+ let bValue;
402
+ if (field === "product_title") {
403
+ aValue = a.product_title;
404
+ bValue = b.product_title;
405
+ } else if (field === "variant_title") {
406
+ aValue = a.variant_title;
407
+ bValue = b.variant_title;
408
+ } else if (field === "sku") {
409
+ aValue = a.variant_sku;
410
+ bValue = b.variant_sku;
411
+ }
412
+ if (aValue < bValue) {
413
+ return direction === "asc" ? -1 : 1;
414
+ }
415
+ if (aValue > bValue) {
416
+ return direction === "asc" ? 1 : -1;
417
+ }
418
+ return 0;
419
+ });
420
+ };
421
+ var filterByDate = (items, date, field) => {
422
+ const { gt, gte, lt, lte } = date;
423
+ return items.filter((i) => {
424
+ const itemDate = new Date(i[field]);
425
+ let isValid = true;
426
+ if (gt) {
427
+ isValid = isValid && itemDate > new Date(gt);
428
+ }
429
+ if (gte) {
430
+ isValid = isValid && itemDate >= new Date(gte);
431
+ }
432
+ if (lt) {
433
+ isValid = isValid && itemDate < new Date(lt);
434
+ }
435
+ if (lte) {
436
+ isValid = isValid && itemDate <= new Date(lte);
437
+ }
438
+ return isValid;
439
+ });
440
+ };
441
+
442
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-item.tsx
443
+ import { ChatBubble, DocumentText, XCircle, XMark } from "@medusajs/icons";
444
+ import { IconButton, Input, Text } from "@medusajs/ui";
445
+ import { useTranslation as useTranslation4 } from "react-i18next";
446
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
447
+ function ExchangeInboundItem({
448
+ item,
449
+ previewItem,
450
+ currencyCode,
451
+ form,
452
+ onRemove,
453
+ onUpdate,
454
+ index
455
+ }) {
456
+ const { t } = useTranslation4();
457
+ const { return_reasons = [] } = useReturnReasons({ fields: "+label" });
458
+ const formItem = form.watch(`inbound_items.${index}`);
459
+ const showReturnReason = typeof formItem.reason_id === "string";
460
+ const showNote = typeof formItem.note === "string";
461
+ return /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl ", children: [
462
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-x-2 gap-y-2 p-3 text-sm md:flex-row", children: [
463
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-x-3", children: [
464
+ /* @__PURE__ */ jsx3(Thumbnail, { src: item.thumbnail }),
465
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
466
+ /* @__PURE__ */ jsxs("div", { children: [
467
+ /* @__PURE__ */ jsxs(Text, { className: "txt-small", as: "span", weight: "plus", children: [
468
+ item.title,
469
+ " "
470
+ ] }),
471
+ item.variant_sku && /* @__PURE__ */ jsxs("span", { children: [
472
+ "(",
473
+ item.variant_sku,
474
+ ")"
475
+ ] })
476
+ ] }),
477
+ /* @__PURE__ */ jsx3(Text, { as: "div", className: "text-ui-fg-subtle txt-small", children: item.product_title })
478
+ ] })
479
+ ] }),
480
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 justify-between", children: [
481
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-grow items-center gap-2", children: [
482
+ /* @__PURE__ */ jsx3(
483
+ Form.Field,
484
+ {
485
+ control: form.control,
486
+ name: `inbound_items.${index}.quantity`,
487
+ render: ({ field }) => {
488
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
489
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
490
+ Input,
491
+ {
492
+ ...field,
493
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
494
+ min: 1,
495
+ max: item.quantity,
496
+ type: "number",
497
+ onBlur: (e) => {
498
+ const val = e.target.value;
499
+ const payload = val === "" ? null : Number(val);
500
+ field.onChange(payload);
501
+ if (payload) {
502
+ onUpdate({ quantity: payload });
503
+ }
504
+ }
505
+ }
506
+ ) }),
507
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
508
+ ] });
509
+ }
510
+ }
511
+ ),
512
+ /* @__PURE__ */ jsx3(Text, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
513
+ ] }),
514
+ /* @__PURE__ */ jsx3("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx3(
515
+ MoneyAmountCell,
516
+ {
517
+ currencyCode,
518
+ amount: previewItem.return_requested_total
519
+ }
520
+ ) }),
521
+ /* @__PURE__ */ jsx3(
522
+ ActionMenu,
523
+ {
524
+ groups: [
525
+ {
526
+ actions: [
527
+ !showReturnReason && {
528
+ label: t("actions.addReason"),
529
+ onClick: () => form.setValue(`inbound_items.${index}.reason_id`, ""),
530
+ icon: /* @__PURE__ */ jsx3(ChatBubble, {})
531
+ },
532
+ !showNote && {
533
+ label: t("actions.addNote"),
534
+ onClick: () => form.setValue(`inbound_items.${index}.note`, ""),
535
+ icon: /* @__PURE__ */ jsx3(DocumentText, {})
536
+ },
537
+ {
538
+ label: t("actions.remove"),
539
+ onClick: onRemove,
540
+ icon: /* @__PURE__ */ jsx3(XCircle, {})
541
+ }
542
+ ].filter(Boolean)
543
+ }
544
+ ]
545
+ }
546
+ )
547
+ ] })
548
+ ] }),
549
+ /* @__PURE__ */ jsxs(Fragment, { children: [
550
+ showReturnReason && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
551
+ /* @__PURE__ */ jsxs("div", { children: [
552
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.reason") }),
553
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.reasonHint") })
554
+ ] }),
555
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
556
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
557
+ Form.Field,
558
+ {
559
+ control: form.control,
560
+ name: `inbound_items.${index}.reason_id`,
561
+ render: ({ field: { ref, value, onChange, ...field } }) => {
562
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
563
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
564
+ Combobox,
565
+ {
566
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover",
567
+ value,
568
+ onChange: (v) => {
569
+ onUpdate({ reason_id: v });
570
+ onChange(v);
571
+ },
572
+ ...field,
573
+ options: return_reasons.map((reason) => ({
574
+ label: reason.label,
575
+ value: reason.id
576
+ }))
577
+ }
578
+ ) }),
579
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
580
+ ] });
581
+ }
582
+ }
583
+ ) }),
584
+ /* @__PURE__ */ jsx3(
585
+ IconButton,
586
+ {
587
+ type: "button",
588
+ className: "flex-shrink",
589
+ variant: "transparent",
590
+ onClick: () => {
591
+ form.setValue(`inbound_items.${index}.reason_id`, null);
592
+ onUpdate({ reason_id: null });
593
+ },
594
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
595
+ }
596
+ )
597
+ ] })
598
+ ] }),
599
+ showNote && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 p-3 md:grid-cols-2", children: [
600
+ /* @__PURE__ */ jsxs("div", { children: [
601
+ /* @__PURE__ */ jsx3(Form.Label, { children: t("orders.returns.note") }),
602
+ /* @__PURE__ */ jsx3(Form.Hint, { className: "!mt-1", children: t("orders.returns.noteHint") })
603
+ ] }),
604
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
605
+ /* @__PURE__ */ jsx3("div", { className: "flex-grow", children: /* @__PURE__ */ jsx3(
606
+ Form.Field,
607
+ {
608
+ control: form.control,
609
+ name: `inbound_items.${index}.note`,
610
+ render: ({ field: { ref, ...field } }) => {
611
+ return /* @__PURE__ */ jsxs(Form.Item, { children: [
612
+ /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(
613
+ Input,
614
+ {
615
+ ...field,
616
+ onBlur: () => {
617
+ field.onChange(field.value);
618
+ onUpdate({ internal_note: field.value });
619
+ },
620
+ className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover"
621
+ }
622
+ ) }),
623
+ /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
624
+ ] });
625
+ }
626
+ }
627
+ ) }),
628
+ /* @__PURE__ */ jsx3(
629
+ IconButton,
630
+ {
631
+ type: "button",
632
+ className: "flex-shrink",
633
+ variant: "transparent",
634
+ onClick: () => {
635
+ form.setValue(`inbound_items.${index}.note`, null);
636
+ onUpdate({ internal_note: null });
637
+ },
638
+ children: /* @__PURE__ */ jsx3(XMark, { className: "text-ui-fg-muted" })
639
+ }
640
+ )
641
+ ] })
642
+ ] })
643
+ ] })
644
+ ] });
645
+ }
646
+
647
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-inbound-section.tsx
648
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
649
+ var itemsToAdd = [];
650
+ var itemsToRemove = [];
651
+ var ExchangeInboundSection = ({
652
+ order,
653
+ preview,
654
+ exchange,
655
+ form,
656
+ orderReturn
657
+ }) => {
658
+ const { t } = useTranslation5();
659
+ const { setIsOpen } = useStackedModal();
660
+ const [inventoryMap, setInventoryMap] = useState2({});
661
+ const { mutateAsync: updateReturn } = useUpdateReturn(
662
+ preview?.order_change?.return_id,
663
+ order.id
664
+ );
665
+ const { mutateAsync: addInboundShipping } = useAddExchangeInboundShipping(
666
+ exchange.id,
667
+ order.id
668
+ );
669
+ const { mutateAsync: deleteInboundShipping } = useDeleteExchangeInboundShipping(exchange.id, order.id);
670
+ const { mutateAsync: addInboundItem } = useAddExchangeInboundItems(
671
+ exchange.id,
672
+ order.id
673
+ );
674
+ const { mutateAsync: updateInboundItem } = useUpdateExchangeInboundItem(
675
+ exchange.id,
676
+ order.id
677
+ );
678
+ const { mutateAsync: removeInboundItem } = useRemoveExchangeInboundItem(
679
+ exchange.id,
680
+ order.id
681
+ );
682
+ const previewInboundItems = useMemo3(
683
+ () => preview?.items?.filter(
684
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchange.id)
685
+ ),
686
+ [preview.items]
687
+ );
688
+ const inboundPreviewItems = previewInboundItems.filter(
689
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
690
+ );
691
+ const itemsMap = useMemo3(
692
+ () => new Map(order?.items?.map((i) => [i.id, i])),
693
+ [order.items]
694
+ );
695
+ const locationId = form.watch("location_id");
696
+ const { stock_locations = [] } = useStockLocations({ limit: 999 });
697
+ const { shipping_options = [] } = useShippingOptions(
698
+ {
699
+ limit: 999,
700
+ fields: "*prices,+service_zone.fulfillment_set.location.id",
701
+ stock_location_id: locationId
702
+ },
703
+ {
704
+ enabled: !!locationId
705
+ }
706
+ );
707
+ const inboundShippingOptions = shipping_options.filter(
708
+ (shippingOption) => !!shippingOption.rules.find(
709
+ (r) => r.attribute === "is_return" && r.value === "true"
710
+ )
711
+ );
712
+ const {
713
+ fields: inboundItems,
714
+ append,
715
+ remove,
716
+ update
717
+ } = useFieldArray({
718
+ name: "inbound_items",
719
+ control: form.control
720
+ });
721
+ const inboundItemsMap = useMemo3(
722
+ () => new Map(previewInboundItems.map((i) => [i.id, i])),
723
+ [previewInboundItems, inboundItems]
724
+ );
725
+ useEffect(() => {
726
+ const existingItemsMap = {};
727
+ inboundPreviewItems.forEach((i) => {
728
+ const ind = inboundItems.findIndex((field) => field.item_id === i.id);
729
+ existingItemsMap[i.id] = true;
730
+ if (ind > -1) {
731
+ if (inboundItems[ind].quantity !== i.detail.return_requested_quantity) {
732
+ const returnItemAction = i.actions?.find(
733
+ (a) => a.action === "RETURN_ITEM"
734
+ );
735
+ update(ind, {
736
+ ...inboundItems[ind],
737
+ quantity: i.detail.return_requested_quantity,
738
+ note: returnItemAction?.internal_note,
739
+ reason_id: returnItemAction?.details?.reason_id
740
+ });
741
+ }
742
+ } else {
743
+ append(
744
+ { item_id: i.id, quantity: i.detail.return_requested_quantity },
745
+ { shouldFocus: false }
746
+ );
747
+ }
748
+ });
749
+ inboundItems.forEach((i, ind) => {
750
+ if (!(i.item_id in existingItemsMap)) {
751
+ remove(ind);
752
+ }
753
+ });
754
+ }, [previewInboundItems]);
755
+ useEffect(() => {
756
+ const inboundShippingMethod = preview.shipping_methods.find(
757
+ (s) => s.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
758
+ );
759
+ if (inboundShippingMethod) {
760
+ form.setValue(
761
+ "inbound_option_id",
762
+ inboundShippingMethod.shipping_option_id
763
+ );
764
+ } else {
765
+ form.setValue("inbound_option_id", "");
766
+ }
767
+ }, [preview.shipping_methods]);
768
+ useEffect(() => {
769
+ form.setValue("location_id", orderReturn?.location_id);
770
+ }, [orderReturn]);
771
+ const showInboundItemsPlaceholder = !inboundItems.length;
772
+ const onItemsSelected = async () => {
773
+ itemsToAdd.length && await addInboundItem(
774
+ {
775
+ items: itemsToAdd.map((id) => ({
776
+ id,
777
+ quantity: 1
778
+ }))
779
+ },
780
+ {
781
+ onError: (error) => {
782
+ toast.error(error.message);
783
+ }
784
+ }
785
+ );
786
+ for (const itemToRemove of itemsToRemove) {
787
+ const actionId = previewInboundItems.find((i) => i.id === itemToRemove)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
788
+ if (actionId) {
789
+ await removeInboundItem(actionId, {
790
+ onError: (error) => {
791
+ toast.error(error.message);
792
+ }
793
+ });
794
+ }
795
+ }
796
+ setIsOpen("inbound-items", false);
797
+ };
798
+ const onLocationChange = async (selectedLocationId) => {
799
+ await updateReturn({ location_id: selectedLocationId });
800
+ };
801
+ const onShippingOptionChange = async (selectedOptionId) => {
802
+ const inboundShippingMethods = preview.shipping_methods.filter(
803
+ (s) => s.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
804
+ );
805
+ const promises = inboundShippingMethods.filter(Boolean).map((inboundShippingMethod) => {
806
+ const action = inboundShippingMethod.actions?.find(
807
+ (a) => a.action === "SHIPPING_ADD" && !!a.return_id
808
+ );
809
+ if (action) {
810
+ return deleteInboundShipping(action.id);
811
+ }
812
+ });
813
+ await Promise.all(promises);
814
+ if (selectedOptionId) {
815
+ await addInboundShipping(
816
+ { shipping_option_id: selectedOptionId },
817
+ {
818
+ onError: (error) => {
819
+ toast.error(error.message);
820
+ }
821
+ }
822
+ );
823
+ }
824
+ };
825
+ const showLevelsWarning = useMemo3(() => {
826
+ if (!locationId) {
827
+ return false;
828
+ }
829
+ const allItemsHaveLocation = inboundItems.map((_i) => {
830
+ const item = itemsMap.get(_i.item_id);
831
+ if (!item?.variant_id || !item?.variant) {
832
+ return true;
833
+ }
834
+ if (!item.variant?.manage_inventory) {
835
+ return true;
836
+ }
837
+ return inventoryMap[item.variant_id]?.find(
838
+ (l) => l.location_id === locationId
839
+ );
840
+ }).every(Boolean);
841
+ return !allItemsHaveLocation;
842
+ }, [inboundItems, inventoryMap, locationId]);
843
+ useEffect(() => {
844
+ const getInventoryMap = async () => {
845
+ const ret = {};
846
+ if (!inboundItems.length) {
847
+ return ret;
848
+ }
849
+ const variantIds = inboundItems.map((item) => item?.variant_id).filter(Boolean);
850
+ const variants = (await sdk.admin.productVariants.query({
851
+ id: variantIds,
852
+ fields: "*inventory.location_levels"
853
+ })).variants;
854
+ variants.forEach((variant) => {
855
+ ret[variant.id] = variant.inventory?.[0]?.location_levels || [];
856
+ });
857
+ return ret;
858
+ };
859
+ getInventoryMap().then((map) => {
860
+ setInventoryMap(map);
861
+ });
862
+ }, [inboundItems]);
863
+ return /* @__PURE__ */ jsxs2("div", { children: [
864
+ /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex items-center justify-between", children: [
865
+ /* @__PURE__ */ jsx4(Heading, { level: "h2", children: t("orders.returns.inbound") }),
866
+ /* @__PURE__ */ jsxs2(StackedFocusModal, { id: "inbound-items", children: [
867
+ /* @__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") }) }),
868
+ /* @__PURE__ */ jsxs2(StackedFocusModal.Content, { children: [
869
+ /* @__PURE__ */ jsx4(StackedFocusModal.Header, {}),
870
+ /* @__PURE__ */ jsx4(
871
+ AddExchangeInboundItemsTable,
872
+ {
873
+ items: order.items,
874
+ selectedItems: inboundItems.map((i) => i.item_id),
875
+ currencyCode: order.currency_code,
876
+ onSelectionChange: (finalSelection) => {
877
+ const alreadySelected = inboundItems.map((i) => i.item_id);
878
+ itemsToAdd = finalSelection.filter(
879
+ (selection) => !alreadySelected.includes(selection)
880
+ );
881
+ itemsToRemove = alreadySelected.filter(
882
+ (selection) => !finalSelection.includes(selection)
883
+ );
884
+ }
885
+ }
886
+ ),
887
+ /* @__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: [
888
+ /* @__PURE__ */ jsx4(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx4(Button, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
889
+ /* @__PURE__ */ jsx4(
890
+ Button,
891
+ {
892
+ type: "submit",
893
+ variant: "primary",
894
+ size: "small",
895
+ role: "button",
896
+ onClick: async () => await onItemsSelected(),
897
+ children: t("actions.save")
898
+ },
899
+ "submit-button"
900
+ )
901
+ ] }) }) })
902
+ ] })
903
+ ] })
904
+ ] }),
905
+ showInboundItemsPlaceholder && /* @__PURE__ */ jsx4(ItemPlaceholder, {}),
906
+ inboundItems.map(
907
+ (item, index) => inboundItemsMap.get(item.item_id) && itemsMap.get(item.item_id) && /* @__PURE__ */ jsx4(
908
+ ExchangeInboundItem,
909
+ {
910
+ item: itemsMap.get(item.item_id),
911
+ previewItem: inboundItemsMap.get(item.item_id),
912
+ currencyCode: order.currency_code,
913
+ form,
914
+ onRemove: () => {
915
+ const actionId = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM")?.id;
916
+ if (actionId) {
917
+ removeInboundItem(actionId, {
918
+ onError: (error) => {
919
+ toast.error(error.message);
920
+ }
921
+ });
922
+ }
923
+ },
924
+ onUpdate: (payload) => {
925
+ const action = previewInboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "RETURN_ITEM");
926
+ if (action) {
927
+ updateInboundItem(
928
+ { ...payload, actionId: action.id },
929
+ {
930
+ onError: (error) => {
931
+ if (action.details?.quantity && payload.quantity) {
932
+ form.setValue(
933
+ `inbound_items.${index}.quantity`,
934
+ action.details?.quantity
935
+ );
936
+ }
937
+ toast.error(error.message);
938
+ }
939
+ }
940
+ );
941
+ }
942
+ },
943
+ index
944
+ },
945
+ item.id
946
+ )
947
+ ),
948
+ !showInboundItemsPlaceholder && /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex flex-col gap-y-4", children: [
949
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
950
+ /* @__PURE__ */ jsxs2("div", { children: [
951
+ /* @__PURE__ */ jsx4(Form.Label, { children: t("orders.returns.location") }),
952
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.locationHint") })
953
+ ] }),
954
+ /* @__PURE__ */ jsx4(
955
+ Form.Field,
956
+ {
957
+ control: form.control,
958
+ name: "location_id",
959
+ render: ({ field: { value, onChange, ...field } }) => {
960
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
961
+ Combobox,
962
+ {
963
+ ...field,
964
+ value: value ?? void 0,
965
+ onChange: (v) => {
966
+ onChange(v);
967
+ onLocationChange(v);
968
+ },
969
+ options: (stock_locations ?? []).map(
970
+ (stockLocation) => ({
971
+ label: stockLocation.name,
972
+ value: stockLocation.id
973
+ })
974
+ )
975
+ }
976
+ ) }) });
977
+ }
978
+ }
979
+ )
980
+ ] }),
981
+ /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
982
+ /* @__PURE__ */ jsxs2("div", { children: [
983
+ /* @__PURE__ */ jsxs2(Form.Label, { children: [
984
+ t("orders.returns.inboundShipping"),
985
+ /* @__PURE__ */ jsxs2(
986
+ Text2,
987
+ {
988
+ size: "small",
989
+ leading: "compact",
990
+ className: "text-ui-fg-muted ml-1 inline",
991
+ children: [
992
+ "(",
993
+ t("fields.optional"),
994
+ ")"
995
+ ]
996
+ }
997
+ )
998
+ ] }),
999
+ /* @__PURE__ */ jsx4(Form.Hint, { className: "!mt-1", children: t("orders.returns.inboundShippingHint") })
1000
+ ] }),
1001
+ /* @__PURE__ */ jsx4(
1002
+ Form.Field,
1003
+ {
1004
+ control: form.control,
1005
+ name: "inbound_option_id",
1006
+ render: ({ field: { value, onChange, ...field } }) => {
1007
+ return /* @__PURE__ */ jsx4(Form.Item, { children: /* @__PURE__ */ jsx4(Form.Control, { children: /* @__PURE__ */ jsx4(
1008
+ Combobox,
1009
+ {
1010
+ allowClear: true,
1011
+ value: value ?? void 0,
1012
+ onChange: (val) => {
1013
+ onChange(val);
1014
+ onShippingOptionChange(val);
1015
+ },
1016
+ ...field,
1017
+ options: inboundShippingOptions.map((so) => ({
1018
+ label: so.name,
1019
+ value: so.id
1020
+ })),
1021
+ disabled: !locationId,
1022
+ noResultsPlaceholder: /* @__PURE__ */ jsx4(ReturnShippingPlaceholder, {})
1023
+ }
1024
+ ) }) });
1025
+ }
1026
+ }
1027
+ )
1028
+ ] })
1029
+ ] }),
1030
+ showLevelsWarning && /* @__PURE__ */ jsxs2(Alert, { variant: "warning", dismissible: true, className: "mt-4 p-5", children: [
1031
+ /* @__PURE__ */ jsx4("div", { className: "text-ui-fg-subtle txt-small pb-2 font-medium leading-[20px]", children: t("orders.returns.noInventoryLevel") }),
1032
+ /* @__PURE__ */ jsx4(Text2, { className: "text-ui-fg-subtle txt-small leading-normal", children: t("orders.returns.noInventoryLevelDesc") })
1033
+ ] })
1034
+ ] });
1035
+ };
1036
+
1037
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx
1038
+ import { Alert as Alert2, Button as Button2, Heading as Heading2, Text as Text4, toast as toast2 } from "@medusajs/ui";
1039
+ import { useEffect as useEffect2, useMemo as useMemo5, useState as useState4 } from "react";
1040
+ import { useFieldArray as useFieldArray2 } from "react-hook-form";
1041
+ import { useTranslation as useTranslation10 } from "react-i18next";
1042
+
1043
+ // src/pages/orders/order-create-exchange/components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
1044
+ import { useState as useState3 } from "react";
1045
+ import { useTranslation as useTranslation8 } from "react-i18next";
1046
+
1047
+ // src/pages/orders/order-create-exchange/components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-columns.tsx
1048
+ import { Checkbox as Checkbox2 } from "@medusajs/ui";
1049
+ import { createColumnHelper as createColumnHelper2 } from "@tanstack/react-table";
1050
+ import { useMemo as useMemo4 } from "react";
1051
+ import { useTranslation as useTranslation6 } from "react-i18next";
1052
+ import { jsx as jsx5 } from "react/jsx-runtime";
1053
+ var columnHelper2 = createColumnHelper2();
1054
+ var useExchangeOutboundItemTableColumns = (currencyCode) => {
1055
+ const { t } = useTranslation6();
1056
+ return useMemo4(
1057
+ () => [
1058
+ columnHelper2.display({
1059
+ id: "select",
1060
+ header: ({ table }) => {
1061
+ return /* @__PURE__ */ jsx5(
1062
+ Checkbox2,
1063
+ {
1064
+ checked: table.getIsSomePageRowsSelected() ? "indeterminate" : table.getIsAllPageRowsSelected(),
1065
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value)
1066
+ }
1067
+ );
1068
+ },
1069
+ cell: ({ row }) => {
1070
+ const isSelectable = row.getCanSelect();
1071
+ return /* @__PURE__ */ jsx5(
1072
+ Checkbox2,
1073
+ {
1074
+ disabled: !isSelectable,
1075
+ checked: row.getIsSelected(),
1076
+ onCheckedChange: (value) => row.toggleSelected(!!value),
1077
+ onClick: (e) => {
1078
+ e.stopPropagation();
1079
+ }
1080
+ }
1081
+ );
1082
+ }
1083
+ }),
1084
+ columnHelper2.display({
1085
+ id: "product",
1086
+ header: () => /* @__PURE__ */ jsx5(ProductHeader, {}),
1087
+ cell: ({ row }) => {
1088
+ return /* @__PURE__ */ jsx5(ProductCell, { product: row.original.product });
1089
+ }
1090
+ }),
1091
+ columnHelper2.accessor("sku", {
1092
+ header: t("fields.sku"),
1093
+ cell: ({ getValue }) => {
1094
+ return getValue() || "-";
1095
+ }
1096
+ }),
1097
+ columnHelper2.accessor("title", {
1098
+ header: t("fields.title")
1099
+ })
1100
+ ],
1101
+ [t, currencyCode]
1102
+ );
1103
+ };
1104
+
1105
+ // src/pages/orders/order-create-exchange/components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-filters.tsx
1106
+ import { useTranslation as useTranslation7 } from "react-i18next";
1107
+ var useExchangeOutboundItemTableFilters = () => {
1108
+ const { t } = useTranslation7();
1109
+ const filters = [
1110
+ {
1111
+ key: "created_at",
1112
+ label: t("fields.createdAt"),
1113
+ type: "date"
1114
+ },
1115
+ {
1116
+ key: "updated_at",
1117
+ label: t("fields.updatedAt"),
1118
+ type: "date"
1119
+ }
1120
+ ];
1121
+ return filters;
1122
+ };
1123
+
1124
+ // src/pages/orders/order-create-exchange/components/add-exchange-outbound-items-table/use-exchange-outbound-item-table-query.tsx
1125
+ var useExchangeOutboundItemTableQuery = ({
1126
+ pageSize = 50,
1127
+ prefix
1128
+ }) => {
1129
+ const raw = useQueryParams(
1130
+ ["q", "offset", "order", "created_at", "updated_at"],
1131
+ prefix
1132
+ );
1133
+ const { offset, created_at, updated_at, ...rest } = raw;
1134
+ const searchParams = {
1135
+ ...rest,
1136
+ limit: pageSize,
1137
+ offset: offset ? Number(offset) : 0,
1138
+ created_at: created_at ? JSON.parse(created_at) : void 0,
1139
+ updated_at: updated_at ? JSON.parse(updated_at) : void 0
1140
+ };
1141
+ return { searchParams, raw };
1142
+ };
1143
+
1144
+ // src/pages/orders/order-create-exchange/components/add-exchange-outbound-items-table/add-exchange-outbound-items-table.tsx
1145
+ import { jsx as jsx6 } from "react/jsx-runtime";
1146
+ var PAGE_SIZE2 = 50;
1147
+ var PREFIX2 = "rit";
1148
+ var AddExchangeOutboundItemsTable = ({
1149
+ onSelectionChange,
1150
+ selectedItems,
1151
+ currencyCode
1152
+ }) => {
1153
+ const { t } = useTranslation8();
1154
+ const [rowSelection, setRowSelection] = useState3(
1155
+ selectedItems.reduce((acc, id) => {
1156
+ acc[id] = true;
1157
+ return acc;
1158
+ }, {})
1159
+ );
1160
+ const updater = (fn) => {
1161
+ const newState = typeof fn === "function" ? fn(rowSelection) : fn;
1162
+ setRowSelection(newState);
1163
+ onSelectionChange(Object.keys(newState));
1164
+ };
1165
+ const { searchParams, raw } = useExchangeOutboundItemTableQuery({
1166
+ pageSize: PAGE_SIZE2,
1167
+ prefix: PREFIX2
1168
+ });
1169
+ const { variants = [], count } = useVariants({
1170
+ ...searchParams,
1171
+ fields: "*inventory_items.inventory.location_levels,+inventory_quantity"
1172
+ });
1173
+ const columns = useExchangeOutboundItemTableColumns(currencyCode);
1174
+ const filters = useExchangeOutboundItemTableFilters();
1175
+ const { table } = useDataTable({
1176
+ data: variants,
1177
+ columns,
1178
+ count,
1179
+ enablePagination: true,
1180
+ getRowId: (row) => row.id,
1181
+ pageSize: PAGE_SIZE2,
1182
+ enableRowSelection: (_row) => {
1183
+ return true;
1184
+ },
1185
+ rowSelection: {
1186
+ state: rowSelection,
1187
+ updater
1188
+ }
1189
+ });
1190
+ return /* @__PURE__ */ jsx6("div", { className: "flex size-full flex-col overflow-hidden", children: /* @__PURE__ */ jsx6(
1191
+ _DataTable,
1192
+ {
1193
+ table,
1194
+ columns,
1195
+ pageSize: PAGE_SIZE2,
1196
+ count,
1197
+ filters,
1198
+ pagination: true,
1199
+ layout: "fill",
1200
+ search: true,
1201
+ orderBy: [
1202
+ { key: "product_id", label: t("fields.product") },
1203
+ { key: "title", label: t("fields.title") },
1204
+ { key: "sku", label: t("fields.sku") }
1205
+ ],
1206
+ prefix: PREFIX2,
1207
+ queryObject: raw
1208
+ }
1209
+ ) });
1210
+ };
1211
+
1212
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-item.tsx
1213
+ import { XCircle as XCircle2 } from "@medusajs/icons";
1214
+ import { Input as Input2, Text as Text3 } from "@medusajs/ui";
1215
+ import { useTranslation as useTranslation9 } from "react-i18next";
1216
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
1217
+ function ExchangeOutboundItem({
1218
+ previewItem,
1219
+ currencyCode,
1220
+ form,
1221
+ onRemove,
1222
+ onUpdate,
1223
+ index
1224
+ }) {
1225
+ const { t } = useTranslation9();
1226
+ return /* @__PURE__ */ jsx7("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest my-2 rounded-xl ", children: /* @__PURE__ */ jsxs3("div", { className: "flex flex-col items-center gap-x-2 gap-y-2 p-3 text-sm md:flex-row", children: [
1227
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-1 items-center gap-x-3", children: [
1228
+ /* @__PURE__ */ jsx7(Thumbnail, { src: previewItem.thumbnail }),
1229
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-col", children: [
1230
+ /* @__PURE__ */ jsxs3("div", { children: [
1231
+ /* @__PURE__ */ jsxs3(Text3, { className: "txt-small", as: "span", weight: "plus", children: [
1232
+ previewItem.title,
1233
+ " "
1234
+ ] }),
1235
+ previewItem.variant_sku && /* @__PURE__ */ jsxs3("span", { children: [
1236
+ "(",
1237
+ previewItem.variant_sku,
1238
+ ")"
1239
+ ] })
1240
+ ] }),
1241
+ /* @__PURE__ */ jsx7(Text3, { as: "div", className: "text-ui-fg-subtle txt-small", children: previewItem.subtitle })
1242
+ ] })
1243
+ ] }),
1244
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-1 justify-between", children: [
1245
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-grow items-center gap-2", children: [
1246
+ /* @__PURE__ */ jsx7(
1247
+ Form.Field,
1248
+ {
1249
+ control: form.control,
1250
+ name: `outbound_items.${index}.quantity`,
1251
+ render: ({ field }) => {
1252
+ return /* @__PURE__ */ jsxs3(Form.Item, { children: [
1253
+ /* @__PURE__ */ jsx7(Form.Control, { children: /* @__PURE__ */ jsx7(
1254
+ Input2,
1255
+ {
1256
+ ...field,
1257
+ className: "bg-ui-bg-base txt-small w-[67px] rounded-lg",
1258
+ min: 1,
1259
+ type: "number",
1260
+ onBlur: (e) => {
1261
+ const val = e.target.value;
1262
+ const payload = val === "" ? null : Number(val);
1263
+ field.onChange(payload);
1264
+ if (payload) {
1265
+ onUpdate({ quantity: payload });
1266
+ }
1267
+ }
1268
+ }
1269
+ ) }),
1270
+ /* @__PURE__ */ jsx7(Form.ErrorMessage, {})
1271
+ ] });
1272
+ }
1273
+ }
1274
+ ),
1275
+ /* @__PURE__ */ jsx7(Text3, { className: "txt-small text-ui-fg-subtle", children: t("fields.qty") })
1276
+ ] }),
1277
+ /* @__PURE__ */ jsx7("div", { className: "text-ui-fg-subtle txt-small mr-2 flex flex-shrink-0", children: /* @__PURE__ */ jsx7(
1278
+ MoneyAmountCell,
1279
+ {
1280
+ currencyCode,
1281
+ amount: previewItem.total
1282
+ }
1283
+ ) }),
1284
+ /* @__PURE__ */ jsx7(
1285
+ ActionMenu,
1286
+ {
1287
+ groups: [
1288
+ {
1289
+ actions: [
1290
+ {
1291
+ label: t("actions.remove"),
1292
+ onClick: onRemove,
1293
+ icon: /* @__PURE__ */ jsx7(XCircle2, {})
1294
+ }
1295
+ ].filter(Boolean)
1296
+ }
1297
+ ]
1298
+ }
1299
+ )
1300
+ ] })
1301
+ ] }) });
1302
+ }
1303
+
1304
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx
1305
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
1306
+ var itemsToAdd2 = [];
1307
+ var itemsToRemove2 = [];
1308
+ var ExchangeOutboundSection = ({
1309
+ order,
1310
+ preview,
1311
+ exchange,
1312
+ form
1313
+ }) => {
1314
+ const { t } = useTranslation10();
1315
+ const { setIsOpen } = useStackedModal();
1316
+ const [inventoryMap, setInventoryMap] = useState4({});
1317
+ const { shipping_options = [] } = useOrderShippingOptions(order.id);
1318
+ const outboundShippingOptions = shipping_options.filter(
1319
+ (so) => !so.rules?.find((r) => r.attribute === "is_return" && r.value === "true")
1320
+ );
1321
+ const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping(
1322
+ exchange.id,
1323
+ order.id
1324
+ );
1325
+ const { mutateAsync: deleteOutboundShipping } = useDeleteExchangeOutboundShipping(exchange.id, order.id);
1326
+ const { mutateAsync: addOutboundItem } = useAddExchangeOutboundItems(
1327
+ exchange.id,
1328
+ order.id
1329
+ );
1330
+ const { mutateAsync: updateOutboundItem } = useUpdateExchangeOutboundItems(
1331
+ exchange.id,
1332
+ order.id
1333
+ );
1334
+ const { mutateAsync: removeOutboundItem } = useRemoveExchangeOutboundItem(
1335
+ exchange.id,
1336
+ order.id
1337
+ );
1338
+ const previewOutboundItems = useMemo5(
1339
+ () => preview?.items?.filter(
1340
+ (i) => !!i.actions?.find(
1341
+ (a) => a.exchange_id === exchange.id && a.action === "ITEM_ADD"
1342
+ )
1343
+ ),
1344
+ [preview.items]
1345
+ );
1346
+ const variantItemMap = useMemo5(
1347
+ () => new Map(order?.items?.map((i) => [i.variant_id, i])),
1348
+ [order.items]
1349
+ );
1350
+ const {
1351
+ fields: outboundItems,
1352
+ append,
1353
+ remove,
1354
+ update
1355
+ } = useFieldArray2({
1356
+ name: "outbound_items",
1357
+ control: form.control
1358
+ });
1359
+ const variantOutboundMap = useMemo5(
1360
+ () => new Map(previewOutboundItems.map((i) => [i.variant_id, i])),
1361
+ [previewOutboundItems, outboundItems]
1362
+ );
1363
+ useEffect2(() => {
1364
+ const existingItemsMap = {};
1365
+ previewOutboundItems.forEach((i) => {
1366
+ const ind = outboundItems.findIndex((field) => field.item_id === i.id);
1367
+ existingItemsMap[i.id] = true;
1368
+ if (ind > -1) {
1369
+ if (outboundItems[ind].quantity !== i.detail.quantity) {
1370
+ update(ind, {
1371
+ ...outboundItems[ind],
1372
+ quantity: i.detail.quantity
1373
+ });
1374
+ }
1375
+ } else {
1376
+ append(
1377
+ {
1378
+ item_id: i.id,
1379
+ quantity: i.detail.quantity,
1380
+ variant_id: i.variant_id
1381
+ },
1382
+ { shouldFocus: false }
1383
+ );
1384
+ }
1385
+ });
1386
+ outboundItems.forEach((i, ind) => {
1387
+ if (!(i.item_id in existingItemsMap)) {
1388
+ remove(ind);
1389
+ }
1390
+ });
1391
+ }, [previewOutboundItems]);
1392
+ const locationId = form.watch("location_id");
1393
+ const showOutboundItemsPlaceholder = !outboundItems.length;
1394
+ const onItemsSelected = async () => {
1395
+ itemsToAdd2.length && await addOutboundItem(
1396
+ {
1397
+ items: itemsToAdd2.map((variantId) => ({
1398
+ variant_id: variantId,
1399
+ quantity: 1
1400
+ }))
1401
+ },
1402
+ {
1403
+ onError: (error) => {
1404
+ toast2.error(error.message);
1405
+ }
1406
+ }
1407
+ );
1408
+ for (const itemToRemove of itemsToRemove2) {
1409
+ const action = previewOutboundItems.find((i) => i.variant_id === itemToRemove)?.actions?.find((a) => a.action === "ITEM_ADD");
1410
+ if (action?.id) {
1411
+ await removeOutboundItem(action?.id, {
1412
+ onError: (error) => {
1413
+ toast2.error(error.message);
1414
+ }
1415
+ });
1416
+ }
1417
+ }
1418
+ setIsOpen("outbound-items", false);
1419
+ };
1420
+ useEffect2(() => {
1421
+ const outboundShipping = preview.shipping_methods.find(
1422
+ (s) => !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1423
+ );
1424
+ if (outboundShipping) {
1425
+ form.setValue("outbound_option_id", outboundShipping.shipping_option_id);
1426
+ } else {
1427
+ form.setValue("outbound_option_id", "");
1428
+ }
1429
+ }, [preview.shipping_methods]);
1430
+ const onShippingOptionChange = async (selectedOptionId) => {
1431
+ const outboundShippingMethods = preview.shipping_methods.filter(
1432
+ (s) => !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1433
+ );
1434
+ const promises = outboundShippingMethods.filter(Boolean).map((outboundShippingMethod) => {
1435
+ const action = outboundShippingMethod.actions?.find(
1436
+ (a) => a.action === "SHIPPING_ADD" && !a.return_id
1437
+ );
1438
+ if (action) {
1439
+ return deleteOutboundShipping(action.id);
1440
+ }
1441
+ });
1442
+ await Promise.all(promises);
1443
+ if (selectedOptionId) {
1444
+ await addOutboundShipping(
1445
+ { shipping_option_id: selectedOptionId },
1446
+ {
1447
+ onError: (error) => {
1448
+ toast2.error(error.message);
1449
+ }
1450
+ }
1451
+ );
1452
+ }
1453
+ };
1454
+ const showLevelsWarning = useMemo5(() => {
1455
+ if (!locationId) {
1456
+ return false;
1457
+ }
1458
+ const allItemsHaveLocation = outboundItems.map((i) => {
1459
+ const item = variantItemMap.get(i.variant_id);
1460
+ if (!item?.variant_id || !item?.variant) {
1461
+ return true;
1462
+ }
1463
+ if (!item.variant?.manage_inventory) {
1464
+ return true;
1465
+ }
1466
+ return inventoryMap[item.variant_id]?.find(
1467
+ (l) => l.location_id === locationId
1468
+ );
1469
+ }).every(Boolean);
1470
+ return !allItemsHaveLocation;
1471
+ }, [outboundItems, inventoryMap, locationId]);
1472
+ useEffect2(() => {
1473
+ const getInventoryMap = async () => {
1474
+ const ret = {};
1475
+ if (!outboundItems.length) {
1476
+ return ret;
1477
+ }
1478
+ const variantIds = outboundItems.map((item) => item?.variant_id).filter(Boolean);
1479
+ const variants = (await sdk.admin.productVariants.query({
1480
+ id: variantIds,
1481
+ fields: "*inventory.location_levels"
1482
+ })).variants;
1483
+ variants.forEach((variant) => {
1484
+ ret[variant.id] = variant.inventory?.[0]?.location_levels || [];
1485
+ });
1486
+ return ret;
1487
+ };
1488
+ getInventoryMap().then((map) => {
1489
+ setInventoryMap(map);
1490
+ });
1491
+ }, [outboundItems]);
1492
+ return /* @__PURE__ */ jsxs4("div", { children: [
1493
+ /* @__PURE__ */ jsxs4("div", { className: "mt-8 flex items-center justify-between", children: [
1494
+ /* @__PURE__ */ jsx8(Heading2, { level: "h2", children: t("orders.returns.outbound") }),
1495
+ /* @__PURE__ */ jsxs4(StackedFocusModal, { id: "outbound-items", children: [
1496
+ /* @__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") }) }),
1497
+ /* @__PURE__ */ jsxs4(StackedFocusModal.Content, { children: [
1498
+ /* @__PURE__ */ jsx8(StackedFocusModal.Header, {}),
1499
+ /* @__PURE__ */ jsx8(
1500
+ AddExchangeOutboundItemsTable,
1501
+ {
1502
+ selectedItems: outboundItems.map((i) => i.variant_id),
1503
+ currencyCode: order.currency_code,
1504
+ onSelectionChange: (finalSelection) => {
1505
+ const alreadySelected = outboundItems.map((i) => i.variant_id);
1506
+ itemsToAdd2 = finalSelection.filter(
1507
+ (selection) => !alreadySelected.includes(selection)
1508
+ );
1509
+ itemsToRemove2 = alreadySelected.filter(
1510
+ (selection) => !finalSelection.includes(selection)
1511
+ );
1512
+ }
1513
+ }
1514
+ ),
1515
+ /* @__PURE__ */ jsx8(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsx8("div", { className: "flex w-full items-center justify-end gap-x-4", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-end gap-x-2", children: [
1516
+ /* @__PURE__ */ jsx8(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx8(Button2, { type: "button", variant: "secondary", size: "small", children: t("actions.cancel") }) }),
1517
+ /* @__PURE__ */ jsx8(
1518
+ Button2,
1519
+ {
1520
+ type: "submit",
1521
+ variant: "primary",
1522
+ size: "small",
1523
+ role: "button",
1524
+ onClick: async () => await onItemsSelected(),
1525
+ children: t("actions.save")
1526
+ },
1527
+ "submit-button"
1528
+ )
1529
+ ] }) }) })
1530
+ ] })
1531
+ ] })
1532
+ ] }),
1533
+ showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8(ItemPlaceholder, {}),
1534
+ outboundItems.map(
1535
+ (item, index) => variantOutboundMap.get(item.variant_id) && /* @__PURE__ */ jsx8(
1536
+ ExchangeOutboundItem,
1537
+ {
1538
+ previewItem: variantOutboundMap.get(item.variant_id),
1539
+ currencyCode: order.currency_code,
1540
+ form,
1541
+ onRemove: () => {
1542
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1543
+ if (actionId) {
1544
+ removeOutboundItem(actionId, {
1545
+ onError: (error) => {
1546
+ toast2.error(error.message);
1547
+ }
1548
+ });
1549
+ }
1550
+ },
1551
+ onUpdate: (payload) => {
1552
+ const actionId = previewOutboundItems.find((i) => i.id === item.item_id)?.actions?.find((a) => a.action === "ITEM_ADD")?.id;
1553
+ if (actionId) {
1554
+ updateOutboundItem(
1555
+ { ...payload, actionId },
1556
+ {
1557
+ onError: (error) => {
1558
+ toast2.error(error.message);
1559
+ }
1560
+ }
1561
+ );
1562
+ }
1563
+ },
1564
+ index
1565
+ },
1566
+ item.id
1567
+ )
1568
+ ),
1569
+ !showOutboundItemsPlaceholder && /* @__PURE__ */ jsx8("div", { className: "mt-8 flex flex-col gap-y-4", children: /* @__PURE__ */ jsxs4("div", { className: "grid grid-cols-1 gap-2 md:grid-cols-2", children: [
1570
+ /* @__PURE__ */ jsxs4("div", { children: [
1571
+ /* @__PURE__ */ jsx8(Form.Label, { children: t("orders.exchanges.outboundShipping") }),
1572
+ /* @__PURE__ */ jsx8(Form.Hint, { className: "!mt-1", children: t("orders.exchanges.outboundShippingHint") })
1573
+ ] }),
1574
+ /* @__PURE__ */ jsx8(
1575
+ Form.Field,
1576
+ {
1577
+ control: form.control,
1578
+ name: "outbound_option_id",
1579
+ render: ({ field: { value, onChange, ...field } }) => {
1580
+ return /* @__PURE__ */ jsx8(Form.Item, { children: /* @__PURE__ */ jsx8(Form.Control, { children: /* @__PURE__ */ jsx8(
1581
+ Combobox,
1582
+ {
1583
+ allowClear: true,
1584
+ noResultsPlaceholder: /* @__PURE__ */ jsx8(OutboundShippingPlaceholder, {}),
1585
+ value: value ?? void 0,
1586
+ onChange: (val) => {
1587
+ onChange(val);
1588
+ onShippingOptionChange(val);
1589
+ },
1590
+ ...field,
1591
+ options: outboundShippingOptions.map((so) => ({
1592
+ label: `${so.name} (${getFormattedShippingOptionLocationName(so)})`,
1593
+ value: so.id
1594
+ })),
1595
+ disabled: !outboundShippingOptions.length
1596
+ }
1597
+ ) }) });
1598
+ }
1599
+ }
1600
+ )
1601
+ ] }) }),
1602
+ showLevelsWarning && /* @__PURE__ */ jsxs4(Alert2, { variant: "warning", dismissible: true, className: "mt-4 p-5", children: [
1603
+ /* @__PURE__ */ jsx8("div", { className: "text-ui-fg-subtle txt-small pb-2 font-medium leading-[20px]", children: t("orders.returns.noInventoryLevel") }),
1604
+ /* @__PURE__ */ jsx8(Text4, { className: "text-ui-fg-subtle txt-small leading-normal", children: t("orders.returns.noInventoryLevelDesc") })
1605
+ ] })
1606
+ ] });
1607
+ };
1608
+
1609
+ // src/pages/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx
1610
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
1611
+ var IS_CANCELING = false;
1612
+ var ExchangeCreateForm = ({
1613
+ order,
1614
+ preview,
1615
+ exchange,
1616
+ orderReturn
1617
+ }) => {
1618
+ const { t } = useTranslation11();
1619
+ const { handleSuccess } = useRouteModal();
1620
+ const [isInboundShippingPriceEdit, setIsInboundShippingPriceEdit] = useState5(false);
1621
+ const [isOutboundShippingPriceEdit, setIsOutboundShippingPriceEdit] = useState5(false);
1622
+ const [customInboundShippingAmount, setCustomInboundShippingAmount] = useState5({
1623
+ value: "0",
1624
+ float: 0
1625
+ });
1626
+ const [customOutboundShippingAmount, setCustomOutboundShippingAmount] = useState5({
1627
+ value: "0",
1628
+ float: 0
1629
+ });
1630
+ const { mutateAsync: confirmExchangeRequest, isPending: isConfirming } = useExchangeConfirmRequest(exchange.id, order.id);
1631
+ const { mutateAsync: cancelExchangeRequest, isPending: isCanceling } = useCancelExchangeRequest(exchange.id, order.id);
1632
+ const {
1633
+ mutateAsync: updateInboundShipping,
1634
+ isPending: isUpdatingOutboundShipping
1635
+ } = useUpdateExchangeInboundShipping(exchange.id, order.id);
1636
+ const {
1637
+ mutateAsync: updateOutboundShipping,
1638
+ isPending: isUpdatingInboundShipping
1639
+ } = useUpdateExchangeOutboundShipping(exchange.id, order.id);
1640
+ const isRequestLoading = isConfirming || isCanceling || isUpdatingInboundShipping || isUpdatingOutboundShipping;
1641
+ const previewItems = useMemo6(
1642
+ () => preview?.items?.filter(
1643
+ (i) => !!i.actions?.find((a) => a.exchange_id === exchange.id)
1644
+ ),
1645
+ [preview.items]
1646
+ );
1647
+ const inboundPreviewItems = previewItems.filter(
1648
+ (item) => !!item.actions?.find((a) => a.action === "RETURN_ITEM")
1649
+ );
1650
+ const outboundPreviewItems = previewItems.filter(
1651
+ (item) => !!item.actions?.find((a) => a.action === "ITEM_ADD")
1652
+ );
1653
+ const form = useForm({
1654
+ defaultValues: () => {
1655
+ const inboundShippingMethod = preview.shipping_methods.find((s) => {
1656
+ return !!s.actions?.find(
1657
+ (a) => a.action === "SHIPPING_ADD" && !!a.return_id
1658
+ );
1659
+ });
1660
+ const outboundShippingMethod = preview.shipping_methods.find((s) => {
1661
+ return !!s.actions?.find(
1662
+ (a) => a.action === "SHIPPING_ADD" && !a.return_id
1663
+ );
1664
+ });
1665
+ return Promise.resolve({
1666
+ inbound_items: inboundPreviewItems.map((i) => {
1667
+ const inboundAction = i.actions?.find(
1668
+ (a) => a.action === "RETURN_ITEM"
1669
+ );
1670
+ return {
1671
+ item_id: i.id,
1672
+ variant_id: i.variant_id,
1673
+ quantity: i.detail.return_requested_quantity,
1674
+ note: inboundAction?.internal_note,
1675
+ reason_id: inboundAction?.details?.reason_id
1676
+ };
1677
+ }),
1678
+ outbound_items: outboundPreviewItems.map((i) => ({
1679
+ item_id: i.id,
1680
+ variant_id: i.variant_id,
1681
+ quantity: i.detail.quantity
1682
+ })),
1683
+ inbound_option_id: inboundShippingMethod ? inboundShippingMethod.shipping_option_id : "",
1684
+ outbound_option_id: outboundShippingMethod ? outboundShippingMethod.shipping_option_id : "",
1685
+ location_id: orderReturn?.location_id,
1686
+ send_notification: false
1687
+ });
1688
+ },
1689
+ resolver: zodResolver(ExchangeCreateSchema)
1690
+ });
1691
+ const inboundShipping = preview.shipping_methods.find((s) => {
1692
+ return !!s.actions?.find(
1693
+ (a) => a.action === "SHIPPING_ADD" && !!a.return_id
1694
+ );
1695
+ });
1696
+ const outboundShipping = preview.shipping_methods.find((s) => {
1697
+ return !!s.actions?.find(
1698
+ (a) => a.action === "SHIPPING_ADD" && !a.return_id
1699
+ );
1700
+ });
1701
+ useEffect3(() => {
1702
+ if (inboundShipping) {
1703
+ setCustomInboundShippingAmount(inboundShipping.total);
1704
+ }
1705
+ }, [inboundShipping]);
1706
+ useEffect3(() => {
1707
+ if (outboundShipping) {
1708
+ setCustomOutboundShippingAmount(outboundShipping.total);
1709
+ }
1710
+ }, [outboundShipping]);
1711
+ const inboundShippingOptionId = form.watch("inbound_option_id");
1712
+ const outboundShippingOptionId = form.watch("outbound_option_id");
1713
+ const prompt = usePrompt();
1714
+ const handleSubmit = form.handleSubmit(async (data) => {
1715
+ try {
1716
+ const res = await prompt({
1717
+ title: t("general.areYouSure"),
1718
+ description: t("orders.exchanges.confirmText"),
1719
+ confirmText: t("actions.continue"),
1720
+ cancelText: t("actions.cancel"),
1721
+ variant: "confirmation"
1722
+ });
1723
+ if (!res) {
1724
+ return;
1725
+ }
1726
+ await confirmExchangeRequest({
1727
+ no_notification: !data.send_notification
1728
+ });
1729
+ handleSuccess();
1730
+ } catch (e) {
1731
+ toast3.error(t("general.error"), {
1732
+ description: e.message
1733
+ });
1734
+ }
1735
+ });
1736
+ useEffect3(() => {
1737
+ if (isInboundShippingPriceEdit) {
1738
+ document.getElementById("js-inbound-shipping-input")?.focus();
1739
+ }
1740
+ }, [isInboundShippingPriceEdit]);
1741
+ useEffect3(() => {
1742
+ if (isOutboundShippingPriceEdit) {
1743
+ document.getElementById("js-outbound-shipping-input")?.focus();
1744
+ }
1745
+ }, [isOutboundShippingPriceEdit]);
1746
+ useEffect3(() => {
1747
+ return () => {
1748
+ if (IS_CANCELING) {
1749
+ cancelExchangeRequest(void 0, {
1750
+ onSuccess: () => {
1751
+ toast3.success(
1752
+ t("orders.exchanges.actions.cancelExchange.successToast")
1753
+ );
1754
+ },
1755
+ onError: (error) => {
1756
+ toast3.error(error.message);
1757
+ }
1758
+ });
1759
+ IS_CANCELING = false;
1760
+ }
1761
+ };
1762
+ }, []);
1763
+ const inboundShippingTotal = useMemo6(() => {
1764
+ const method = preview.shipping_methods.find(
1765
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id)
1766
+ );
1767
+ return method?.total || 0;
1768
+ }, [preview.shipping_methods]);
1769
+ const outboundShippingTotal = useMemo6(() => {
1770
+ const method = preview.shipping_methods.find(
1771
+ (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
1772
+ );
1773
+ return method?.total || 0;
1774
+ }, [preview.shipping_methods]);
1775
+ return /* @__PURE__ */ jsx9(RouteFocusModal.Form, { form, "data-testid": "order-create-exchange-form", children: /* @__PURE__ */ jsxs5(
1776
+ KeyboundForm,
1777
+ {
1778
+ onSubmit: handleSubmit,
1779
+ className: "flex h-full flex-col",
1780
+ "data-testid": "order-create-exchange-form",
1781
+ children: [
1782
+ /* @__PURE__ */ jsx9(RouteFocusModal.Header, { "data-testid": "order-create-exchange-header" }),
1783
+ /* @__PURE__ */ jsx9(
1784
+ RouteFocusModal.Body,
1785
+ {
1786
+ className: "flex size-full justify-center overflow-y-auto",
1787
+ "data-testid": "order-create-exchange-body",
1788
+ children: /* @__PURE__ */ jsxs5(
1789
+ "div",
1790
+ {
1791
+ className: "mt-16 w-[720px] max-w-[100%] px-4 md:p-0",
1792
+ "data-testid": "order-create-exchange-form-content",
1793
+ children: [
1794
+ /* @__PURE__ */ jsx9(Heading3, { level: "h1", "data-testid": "order-create-exchange-heading", children: t("orders.exchanges.create") }),
1795
+ /* @__PURE__ */ jsx9(
1796
+ ExchangeInboundSection,
1797
+ {
1798
+ form,
1799
+ preview,
1800
+ order,
1801
+ exchange,
1802
+ orderReturn
1803
+ }
1804
+ ),
1805
+ /* @__PURE__ */ jsx9(
1806
+ ExchangeOutboundSection,
1807
+ {
1808
+ form,
1809
+ preview,
1810
+ order,
1811
+ exchange
1812
+ }
1813
+ ),
1814
+ /* @__PURE__ */ jsxs5(
1815
+ "div",
1816
+ {
1817
+ className: "mt-8 border-y border-dotted py-4",
1818
+ "data-testid": "order-create-exchange-totals",
1819
+ children: [
1820
+ /* @__PURE__ */ jsxs5(
1821
+ "div",
1822
+ {
1823
+ className: "mb-2 flex items-center justify-between",
1824
+ "data-testid": "order-create-exchange-inbound-total",
1825
+ children: [
1826
+ /* @__PURE__ */ jsx9(
1827
+ "span",
1828
+ {
1829
+ className: "txt-small text-ui-fg-subtle",
1830
+ "data-testid": "order-create-exchange-form-inbound-total-label",
1831
+ children: t("orders.returns.inboundTotal")
1832
+ }
1833
+ ),
1834
+ /* @__PURE__ */ jsx9(
1835
+ "span",
1836
+ {
1837
+ className: "txt-small text-ui-fg-subtle",
1838
+ "data-testid": "order-create-exchange-form-inbound-total-value",
1839
+ children: getStylizedAmount(
1840
+ inboundPreviewItems.reduce((acc, item) => {
1841
+ const action = item.actions?.find(
1842
+ (act) => act.action === "RETURN_ITEM"
1843
+ );
1844
+ acc = acc + (action?.amount || 0);
1845
+ return acc;
1846
+ }, 0) * -1,
1847
+ order.currency_code
1848
+ )
1849
+ }
1850
+ )
1851
+ ]
1852
+ }
1853
+ ),
1854
+ /* @__PURE__ */ jsxs5(
1855
+ "div",
1856
+ {
1857
+ className: "mb-2 flex items-center justify-between",
1858
+ "data-testid": "order-create-exchange-outbound-total",
1859
+ children: [
1860
+ /* @__PURE__ */ jsx9(
1861
+ "span",
1862
+ {
1863
+ className: "txt-small text-ui-fg-subtle",
1864
+ "data-testid": "order-create-exchange-form-outbound-total-label",
1865
+ children: t("orders.exchanges.outboundTotal")
1866
+ }
1867
+ ),
1868
+ /* @__PURE__ */ jsx9(
1869
+ "span",
1870
+ {
1871
+ className: "txt-small text-ui-fg-subtle",
1872
+ "data-testid": "order-create-exchange-form-outbound-total-value",
1873
+ children: getStylizedAmount(
1874
+ outboundPreviewItems.reduce((acc, item) => {
1875
+ const action = item.actions?.find(
1876
+ (act) => act.action === "ITEM_ADD"
1877
+ );
1878
+ acc = acc + (action?.amount || 0);
1879
+ return acc;
1880
+ }, 0),
1881
+ order.currency_code
1882
+ )
1883
+ }
1884
+ )
1885
+ ]
1886
+ }
1887
+ ),
1888
+ /* @__PURE__ */ jsxs5("div", { className: "mb-2 flex items-center justify-between", children: [
1889
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.returns.inboundShipping") }),
1890
+ /* @__PURE__ */ jsxs5("span", { className: "txt-small text-ui-fg-subtle flex items-center", children: [
1891
+ !isInboundShippingPriceEdit && /* @__PURE__ */ jsx9(
1892
+ IconButton2,
1893
+ {
1894
+ onClick: () => setIsInboundShippingPriceEdit(true),
1895
+ variant: "transparent",
1896
+ className: "text-ui-fg-muted",
1897
+ disabled: !inboundPreviewItems?.length || !inboundShippingOptionId,
1898
+ children: /* @__PURE__ */ jsx9(PencilSquare, {})
1899
+ }
1900
+ ),
1901
+ isInboundShippingPriceEdit ? /* @__PURE__ */ jsx9(
1902
+ CurrencyInput,
1903
+ {
1904
+ id: "js-inbound-shipping-input",
1905
+ onBlur: () => {
1906
+ let actionId;
1907
+ preview.shipping_methods.forEach((s) => {
1908
+ if (s.actions) {
1909
+ for (const a of s.actions) {
1910
+ if (a.action === "SHIPPING_ADD" && !!a.return_id) {
1911
+ actionId = a.id;
1912
+ }
1913
+ }
1914
+ }
1915
+ });
1916
+ const customPrice = customInboundShippingAmount.float;
1917
+ if (actionId) {
1918
+ updateInboundShipping(
1919
+ {
1920
+ actionId,
1921
+ custom_amount: customPrice
1922
+ },
1923
+ {
1924
+ onError: (error) => {
1925
+ toast3.error(error.message);
1926
+ }
1927
+ }
1928
+ );
1929
+ }
1930
+ setIsInboundShippingPriceEdit(false);
1931
+ },
1932
+ symbol: currencies[order.currency_code.toUpperCase()].symbol_native,
1933
+ code: order.currency_code,
1934
+ onValueChange: (_value, _name, values) => setCustomInboundShippingAmount({
1935
+ value: values?.value ?? "",
1936
+ float: values?.float ?? null
1937
+ }),
1938
+ value: customInboundShippingAmount.value,
1939
+ disabled: !inboundPreviewItems?.length
1940
+ }
1941
+ ) : getStylizedAmount(inboundShippingTotal, order.currency_code)
1942
+ ] })
1943
+ ] }),
1944
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between", children: [
1945
+ /* @__PURE__ */ jsx9("span", { className: "txt-small text-ui-fg-subtle", children: t("orders.exchanges.outboundShipping") }),
1946
+ /* @__PURE__ */ jsxs5("span", { className: "txt-small text-ui-fg-subtle flex items-center", children: [
1947
+ !isOutboundShippingPriceEdit && /* @__PURE__ */ jsx9(
1948
+ IconButton2,
1949
+ {
1950
+ onClick: () => setIsOutboundShippingPriceEdit(true),
1951
+ variant: "transparent",
1952
+ className: "text-ui-fg-muted",
1953
+ disabled: !outboundPreviewItems?.length || !outboundShippingOptionId,
1954
+ children: /* @__PURE__ */ jsx9(PencilSquare, {})
1955
+ }
1956
+ ),
1957
+ isOutboundShippingPriceEdit ? /* @__PURE__ */ jsx9(
1958
+ CurrencyInput,
1959
+ {
1960
+ id: "js-outbound-shipping-input",
1961
+ onBlur: () => {
1962
+ let actionId;
1963
+ preview.shipping_methods.forEach((s) => {
1964
+ if (s.actions) {
1965
+ for (const a of s.actions) {
1966
+ if (a.action === "SHIPPING_ADD" && !a.return_id) {
1967
+ actionId = a.id;
1968
+ }
1969
+ }
1970
+ }
1971
+ });
1972
+ const customPrice = customOutboundShippingAmount.float;
1973
+ if (actionId) {
1974
+ updateOutboundShipping(
1975
+ {
1976
+ actionId,
1977
+ custom_amount: customPrice
1978
+ },
1979
+ {
1980
+ onError: (error) => {
1981
+ toast3.error(error.message);
1982
+ }
1983
+ }
1984
+ );
1985
+ }
1986
+ setIsOutboundShippingPriceEdit(false);
1987
+ },
1988
+ symbol: currencies[order.currency_code.toUpperCase()].symbol_native,
1989
+ code: order.currency_code,
1990
+ onValueChange: (_value, _name, values) => setCustomOutboundShippingAmount({
1991
+ value: values?.value ?? "",
1992
+ float: values?.float ?? null
1993
+ }),
1994
+ value: customOutboundShippingAmount.value,
1995
+ disabled: !outboundPreviewItems?.length
1996
+ }
1997
+ ) : getStylizedAmount(
1998
+ outboundShippingTotal,
1999
+ order.currency_code
2000
+ )
2001
+ ] })
2002
+ ] }),
2003
+ /* @__PURE__ */ jsxs5(
2004
+ "div",
2005
+ {
2006
+ className: "mt-4 flex items-center justify-between border-t border-dotted pt-4",
2007
+ "data-testid": "order-create-exchange-refund-amount",
2008
+ children: [
2009
+ /* @__PURE__ */ jsx9(
2010
+ "span",
2011
+ {
2012
+ className: "txt-small font-medium",
2013
+ "data-testid": "order-create-exchange-form-refund-amount-label",
2014
+ children: t("orders.exchanges.refundAmount")
2015
+ }
2016
+ ),
2017
+ /* @__PURE__ */ jsx9(
2018
+ "span",
2019
+ {
2020
+ className: "txt-small font-medium",
2021
+ "data-testid": "order-create-exchange-form-refund-amount-value",
2022
+ children: getStylizedAmount(
2023
+ preview.summary.pending_difference,
2024
+ order.currency_code
2025
+ )
2026
+ }
2027
+ )
2028
+ ]
2029
+ }
2030
+ )
2031
+ ]
2032
+ }
2033
+ ),
2034
+ /* @__PURE__ */ jsx9(
2035
+ "div",
2036
+ {
2037
+ className: "bg-ui-bg-field mt-8 rounded-lg border py-2 pl-2 pr-4",
2038
+ "data-testid": "order-create-exchange-notification",
2039
+ children: /* @__PURE__ */ jsx9(
2040
+ Form.Field,
2041
+ {
2042
+ control: form.control,
2043
+ name: "send_notification",
2044
+ render: ({ field: { onChange, value, ...field } }) => {
2045
+ return /* @__PURE__ */ jsxs5(Form.Item, { "data-testid": "order-create-exchange-notification-item", children: [
2046
+ /* @__PURE__ */ jsxs5(
2047
+ "div",
2048
+ {
2049
+ className: "flex items-center",
2050
+ "data-testid": "order-create-exchange-form-notification-control",
2051
+ children: [
2052
+ /* @__PURE__ */ jsx9(
2053
+ Form.Control,
2054
+ {
2055
+ className: "mr-4 self-start",
2056
+ "data-testid": "order-create-exchange-notification-control",
2057
+ children: /* @__PURE__ */ jsx9(
2058
+ Switch,
2059
+ {
2060
+ dir: "ltr",
2061
+ className: "mt-[2px] rtl:rotate-180",
2062
+ checked: !!value,
2063
+ onCheckedChange: onChange,
2064
+ ...field,
2065
+ "data-testid": "order-create-exchange-notification-switch"
2066
+ }
2067
+ )
2068
+ }
2069
+ ),
2070
+ /* @__PURE__ */ jsxs5("div", { className: "block", children: [
2071
+ /* @__PURE__ */ jsx9(Form.Label, { "data-testid": "order-create-exchange-notification-label", children: t("orders.returns.sendNotification") }),
2072
+ /* @__PURE__ */ jsx9(
2073
+ Form.Hint,
2074
+ {
2075
+ className: "!mt-1",
2076
+ "data-testid": "order-create-exchange-notification-hint",
2077
+ children: t("orders.returns.sendNotificationHint")
2078
+ }
2079
+ )
2080
+ ] })
2081
+ ]
2082
+ }
2083
+ ),
2084
+ /* @__PURE__ */ jsx9(Form.ErrorMessage, { "data-testid": "order-create-exchange-notification-error" })
2085
+ ] });
2086
+ }
2087
+ }
2088
+ )
2089
+ }
2090
+ ),
2091
+ /* @__PURE__ */ jsx9("div", { className: "p-8" })
2092
+ ]
2093
+ }
2094
+ )
2095
+ }
2096
+ ),
2097
+ /* @__PURE__ */ jsx9(RouteFocusModal.Footer, { "data-testid": "order-create-exchange-footer", children: /* @__PURE__ */ jsx9(
2098
+ "div",
2099
+ {
2100
+ className: "flex w-full items-center justify-end gap-x-4",
2101
+ "data-testid": "order-create-exchange-form-footer-actions",
2102
+ children: /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-end gap-x-2", children: [
2103
+ /* @__PURE__ */ jsx9(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx9(
2104
+ Button3,
2105
+ {
2106
+ type: "button",
2107
+ onClick: () => IS_CANCELING = true,
2108
+ variant: "secondary",
2109
+ size: "small",
2110
+ "data-testid": "order-create-exchange-cancel-button",
2111
+ children: t("orders.exchanges.cancel.title")
2112
+ }
2113
+ ) }),
2114
+ /* @__PURE__ */ jsx9(
2115
+ Button3,
2116
+ {
2117
+ type: "submit",
2118
+ variant: "primary",
2119
+ size: "small",
2120
+ isLoading: isRequestLoading,
2121
+ "data-testid": "order-create-exchange-confirm-button",
2122
+ children: t("orders.exchanges.confirm")
2123
+ },
2124
+ "submit-button"
2125
+ )
2126
+ ] })
2127
+ }
2128
+ ) })
2129
+ ]
2130
+ }
2131
+ ) });
2132
+ };
2133
+
2134
+ // src/pages/orders/order-create-exchange/exchange-create.tsx
2135
+ import { jsx as jsx10 } from "react/jsx-runtime";
2136
+ var IS_REQUEST_RUNNING = false;
2137
+ var ExchangeCreate = () => {
2138
+ const { id } = useParams();
2139
+ const navigate = useNavigate();
2140
+ const { t } = useTranslation12();
2141
+ const { order } = useOrder(id, {
2142
+ fields: DEFAULT_FIELDS
2143
+ });
2144
+ const { order: preview } = useOrderPreview(id);
2145
+ const [activeExchangeId, setActiveExchangeId] = useState6();
2146
+ const { mutateAsync: createExchange } = useCreateExchange(order.id);
2147
+ const { exchange } = useExchange(activeExchangeId, void 0, {
2148
+ enabled: !!activeExchangeId
2149
+ });
2150
+ const { return: orderReturn } = useReturn(exchange?.return_id, void 0, {
2151
+ enabled: !!exchange?.return_id
2152
+ });
2153
+ useEffect4(() => {
2154
+ async function run() {
2155
+ if (IS_REQUEST_RUNNING || !preview) {
2156
+ return;
2157
+ }
2158
+ if (preview.order_change) {
2159
+ if (preview.order_change.change_type === "exchange") {
2160
+ setActiveExchangeId(preview.order_change.exchange_id);
2161
+ } else {
2162
+ navigate(`/orders/${preview.id}`, { replace: true });
2163
+ toast4.error(t("orders.exchanges.activeChangeError"));
2164
+ }
2165
+ return;
2166
+ }
2167
+ IS_REQUEST_RUNNING = true;
2168
+ try {
2169
+ const { exchange: createdExchange } = await createExchange({
2170
+ order_id: preview.id
2171
+ });
2172
+ setActiveExchangeId(createdExchange.id);
2173
+ } catch (e) {
2174
+ toast4.error(e.message);
2175
+ navigate(`/orders/${preview.id}`, { replace: true });
2176
+ } finally {
2177
+ IS_REQUEST_RUNNING = false;
2178
+ }
2179
+ }
2180
+ run();
2181
+ }, [preview]);
2182
+ return /* @__PURE__ */ jsx10(RouteFocusModal, { "data-testid": "order-create-exchange-modal", children: exchange && preview && order && /* @__PURE__ */ jsx10(
2183
+ ExchangeCreateForm,
2184
+ {
2185
+ order,
2186
+ exchange,
2187
+ preview,
2188
+ orderReturn
2189
+ }
2190
+ ) });
2191
+ };
2192
+ export {
2193
+ ExchangeCreate as Component
2194
+ };