@open-mercato/core 0.10.1-develop.7708.1.5a5c248637 → 0.10.1-develop.7714.1.9dbb8200d8

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 (287) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/asn/index.js +19 -0
  3. package/dist/generated/entities/asn/index.js.map +7 -0
  4. package/dist/generated/entities/putaway_task/index.js +25 -0
  5. package/dist/generated/entities/putaway_task/index.js.map +7 -0
  6. package/dist/generated/entities/receiving_line/index.js +21 -0
  7. package/dist/generated/entities/receiving_line/index.js.map +7 -0
  8. package/dist/generated/entities.ids.generated.js +4 -1
  9. package/dist/generated/entities.ids.generated.js.map +2 -2
  10. package/dist/generated/entity-fields-registry.js +34 -0
  11. package/dist/generated/entity-fields-registry.js.map +2 -2
  12. package/dist/modules/communication_channels/lib/sanitize-channel-html.js +22 -3
  13. package/dist/modules/communication_channels/lib/sanitize-channel-html.js.map +2 -2
  14. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js +40 -11
  15. package/dist/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.js.map +2 -2
  16. package/dist/modules/customers/components/calendar/CalendarEventEditor.js +13 -2
  17. package/dist/modules/customers/components/calendar/CalendarEventEditor.js.map +2 -2
  18. package/dist/modules/wms/acl.js +2 -0
  19. package/dist/modules/wms/acl.js.map +2 -2
  20. package/dist/modules/wms/api/asns/[id]/complete/route.js +61 -0
  21. package/dist/modules/wms/api/asns/[id]/complete/route.js.map +7 -0
  22. package/dist/modules/wms/api/asns/[id]/receive/route.js +68 -0
  23. package/dist/modules/wms/api/asns/[id]/receive/route.js.map +7 -0
  24. package/dist/modules/wms/api/asns/route.js +197 -0
  25. package/dist/modules/wms/api/asns/route.js.map +7 -0
  26. package/dist/modules/wms/api/inventory/helpers.js +42 -34
  27. package/dist/modules/wms/api/inventory/helpers.js.map +2 -2
  28. package/dist/modules/wms/api/inventory/receive/route.js +1 -1
  29. package/dist/modules/wms/api/inventory/receive/route.js.map +2 -2
  30. package/dist/modules/wms/api/listEnrichers.js +23 -0
  31. package/dist/modules/wms/api/listEnrichers.js.map +2 -2
  32. package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js +56 -0
  33. package/dist/modules/wms/api/putaway-tasks/[id]/assign/route.js.map +7 -0
  34. package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js +56 -0
  35. package/dist/modules/wms/api/putaway-tasks/[id]/cancel/route.js.map +7 -0
  36. package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js +65 -0
  37. package/dist/modules/wms/api/putaway-tasks/[id]/complete/route.js.map +7 -0
  38. package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js +56 -0
  39. package/dist/modules/wms/api/putaway-tasks/[id]/start/route.js.map +7 -0
  40. package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js +51 -0
  41. package/dist/modules/wms/api/putaway-tasks/create-from-balance/route.js.map +7 -0
  42. package/dist/modules/wms/api/putaway-tasks/route.js +192 -0
  43. package/dist/modules/wms/api/putaway-tasks/route.js.map +7 -0
  44. package/dist/modules/wms/api/receiving-lines/route.js +180 -0
  45. package/dist/modules/wms/api/receiving-lines/route.js.map +7 -0
  46. package/dist/modules/wms/api/scan/putaway/route.js +104 -0
  47. package/dist/modules/wms/api/scan/putaway/route.js.map +7 -0
  48. package/dist/modules/wms/api/scan/receive/route.js +109 -0
  49. package/dist/modules/wms/api/scan/receive/route.js.map +7 -0
  50. package/dist/modules/wms/api/scan/resolve-location/route.js +89 -0
  51. package/dist/modules/wms/api/scan/resolve-location/route.js.map +7 -0
  52. package/dist/modules/wms/api/scan/resolve-lot/route.js +89 -0
  53. package/dist/modules/wms/api/scan/resolve-lot/route.js.map +7 -0
  54. package/dist/modules/wms/backend/wms/asns/[id]/page.js +9 -0
  55. package/dist/modules/wms/backend/wms/asns/[id]/page.js.map +7 -0
  56. package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js +18 -0
  57. package/dist/modules/wms/backend/wms/asns/[id]/page.meta.js.map +7 -0
  58. package/dist/modules/wms/backend/wms/asns/page.js +9 -0
  59. package/dist/modules/wms/backend/wms/asns/page.js.map +7 -0
  60. package/dist/modules/wms/backend/wms/asns/page.meta.js +18 -0
  61. package/dist/modules/wms/backend/wms/asns/page.meta.js.map +7 -0
  62. package/dist/modules/wms/backend/wms/putaway/page.js +9 -0
  63. package/dist/modules/wms/backend/wms/putaway/page.js.map +7 -0
  64. package/dist/modules/wms/backend/wms/putaway/page.meta.js +18 -0
  65. package/dist/modules/wms/backend/wms/putaway/page.meta.js.map +7 -0
  66. package/dist/modules/wms/backend/wms/receiving/page.js +8 -0
  67. package/dist/modules/wms/backend/wms/receiving/page.js.map +7 -0
  68. package/dist/modules/wms/backend/wms/receiving/page.meta.js +18 -0
  69. package/dist/modules/wms/backend/wms/receiving/page.meta.js.map +7 -0
  70. package/dist/modules/wms/ce.js +27 -0
  71. package/dist/modules/wms/ce.js.map +2 -2
  72. package/dist/modules/wms/commands/asn.js +1746 -0
  73. package/dist/modules/wms/commands/asn.js.map +7 -0
  74. package/dist/modules/wms/commands/index.js +2 -0
  75. package/dist/modules/wms/commands/index.js.map +2 -2
  76. package/dist/modules/wms/commands/inventory-actions.js +347 -243
  77. package/dist/modules/wms/commands/inventory-actions.js.map +2 -2
  78. package/dist/modules/wms/commands/putaway.js +945 -0
  79. package/dist/modules/wms/commands/putaway.js.map +7 -0
  80. package/dist/modules/wms/commands/shared.js +51 -0
  81. package/dist/modules/wms/commands/shared.js.map +2 -2
  82. package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js +278 -0
  83. package/dist/modules/wms/components/backend/AssignPutawayTaskDialog.js.map +7 -0
  84. package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js +327 -0
  85. package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js.map +7 -0
  86. package/dist/modules/wms/components/backend/CreateAsnDialog.js +404 -0
  87. package/dist/modules/wms/components/backend/CreateAsnDialog.js.map +7 -0
  88. package/dist/modules/wms/components/backend/InventoryOperationsSection.js +16 -3
  89. package/dist/modules/wms/components/backend/InventoryOperationsSection.js.map +2 -2
  90. package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js +476 -0
  91. package/dist/modules/wms/components/backend/ReceiveAsnLineDialog.js.map +7 -0
  92. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js +2 -2
  93. package/dist/modules/wms/components/backend/ReceiveInventoryDialog.js.map +2 -2
  94. package/dist/modules/wms/components/backend/WmsAsnDetailPage.js +524 -0
  95. package/dist/modules/wms/components/backend/WmsAsnDetailPage.js.map +7 -0
  96. package/dist/modules/wms/components/backend/WmsAsnsListPage.js +339 -0
  97. package/dist/modules/wms/components/backend/WmsAsnsListPage.js.map +7 -0
  98. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +5 -6
  99. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
  100. package/dist/modules/wms/components/backend/WmsLotDetailPage.js +5 -6
  101. package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
  102. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +14 -10
  103. package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +2 -2
  104. package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js +598 -0
  105. package/dist/modules/wms/components/backend/WmsPutawayQueuePage.js.map +7 -0
  106. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +5 -6
  107. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
  108. package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js +32 -0
  109. package/dist/modules/wms/components/backend/asnCompleteOptimisticLock.js.map +7 -0
  110. package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js +36 -0
  111. package/dist/modules/wms/components/backend/asnReceivingLinesLoader.js.map +7 -0
  112. package/dist/modules/wms/components/backend/inboundStatusUi.js +106 -0
  113. package/dist/modules/wms/components/backend/inboundStatusUi.js.map +7 -0
  114. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +17 -0
  115. package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +2 -2
  116. package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js +14 -0
  117. package/dist/modules/wms/components/backend/putawayQueueOptimisticLock.js.map +7 -0
  118. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js +4 -0
  119. package/dist/modules/wms/components/backend/useWmsInventoryMutationAccess.js.map +2 -2
  120. package/dist/modules/wms/data/enrichers.js +117 -12
  121. package/dist/modules/wms/data/enrichers.js.map +2 -2
  122. package/dist/modules/wms/data/entities.js +150 -1
  123. package/dist/modules/wms/data/entities.js.map +2 -2
  124. package/dist/modules/wms/data/validators.js +214 -0
  125. package/dist/modules/wms/data/validators.js.map +2 -2
  126. package/dist/modules/wms/events.js +12 -1
  127. package/dist/modules/wms/events.js.map +2 -2
  128. package/dist/modules/wms/extension-points.js +3 -1
  129. package/dist/modules/wms/extension-points.js.map +2 -2
  130. package/dist/modules/wms/lib/asnReceiving.js +124 -0
  131. package/dist/modules/wms/lib/asnReceiving.js.map +7 -0
  132. package/dist/modules/wms/lib/asnVendor.js +52 -0
  133. package/dist/modules/wms/lib/asnVendor.js.map +7 -0
  134. package/dist/modules/wms/lib/flashMutationError.js +4 -0
  135. package/dist/modules/wms/lib/flashMutationError.js.map +2 -2
  136. package/dist/modules/wms/lib/inventoryDisplayUi.js +24 -0
  137. package/dist/modules/wms/lib/inventoryDisplayUi.js.map +2 -2
  138. package/dist/modules/wms/lib/inventoryPolicy.js +17 -0
  139. package/dist/modules/wms/lib/inventoryPolicy.js.map +2 -2
  140. package/dist/modules/wms/lib/loadOperationalDashboard.js +67 -1
  141. package/dist/modules/wms/lib/loadOperationalDashboard.js.map +2 -2
  142. package/dist/modules/wms/lib/putaway.js +141 -0
  143. package/dist/modules/wms/lib/putaway.js.map +7 -0
  144. package/dist/modules/wms/lib/roleFeatures.js +3 -1
  145. package/dist/modules/wms/lib/roleFeatures.js.map +2 -2
  146. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js +99 -1
  147. package/dist/modules/wms/lib/salesOrderInventoryAutomation.js.map +2 -2
  148. package/dist/modules/wms/lib/scanResolve.js +147 -0
  149. package/dist/modules/wms/lib/scanResolve.js.map +7 -0
  150. package/dist/modules/wms/lib/wmsIntegrationToggles.js +1 -1
  151. package/dist/modules/wms/lib/wmsIntegrationToggles.js.map +2 -2
  152. package/dist/modules/wms/migrations/Migration20260812120000.js +43 -0
  153. package/dist/modules/wms/migrations/Migration20260812120000.js.map +7 -0
  154. package/dist/modules/wms/migrations/Migration20260812130000.js +30 -0
  155. package/dist/modules/wms/migrations/Migration20260812130000.js.map +7 -0
  156. package/dist/modules/wms/migrations/Migration20260822120000.js +17 -0
  157. package/dist/modules/wms/migrations/Migration20260822120000.js.map +7 -0
  158. package/dist/modules/wms/migrations/Migration20260822130000.js +17 -0
  159. package/dist/modules/wms/migrations/Migration20260822130000.js.map +7 -0
  160. package/dist/modules/wms/migrations/Migration20261029120000.js +13 -0
  161. package/dist/modules/wms/migrations/Migration20261029120000.js.map +7 -0
  162. package/dist/modules/wms/search.js +85 -0
  163. package/dist/modules/wms/search.js.map +2 -2
  164. package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js +14 -0
  165. package/dist/modules/wms/subscribers/asn-line-received-reevaluate-reservations.js.map +7 -0
  166. package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js +12 -0
  167. package/dist/modules/wms/subscribers/invalidate-enricher-cache-asn.js.map +7 -0
  168. package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js +163 -0
  169. package/dist/modules/wms/subscribers/procurement-goods-receipt-created.js.map +7 -0
  170. package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js +14 -0
  171. package/dist/modules/wms/subscribers/putaway-completed-reevaluate-reservations.js.map +7 -0
  172. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js +37 -8
  173. package/dist/modules/wms/widgets/injection/sales-order-stock-context/widget.client.js.map +2 -2
  174. package/dist/modules/workflows/lib/activity-executor.js +78 -51
  175. package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
  176. package/dist/modules/workflows/lib/activity-registry.js.map +2 -2
  177. package/dist/modules/workflows/lib/activity-types.js +4 -1
  178. package/dist/modules/workflows/lib/activity-types.js.map +2 -2
  179. package/dist/modules/workflows/lib/activity-worker-handler.js +1 -1
  180. package/dist/modules/workflows/lib/activity-worker-handler.js.map +2 -2
  181. package/generated/entities/asn/index.ts +8 -0
  182. package/generated/entities/putaway_task/index.ts +11 -0
  183. package/generated/entities/receiving_line/index.ts +9 -0
  184. package/generated/entities.ids.generated.ts +4 -1
  185. package/generated/entity-fields-registry.ts +34 -0
  186. package/package.json +7 -7
  187. package/src/modules/auth/i18n/de.json +2 -0
  188. package/src/modules/auth/i18n/en.json +2 -0
  189. package/src/modules/auth/i18n/es.json +2 -0
  190. package/src/modules/auth/i18n/ko.json +2 -0
  191. package/src/modules/auth/i18n/pl.json +2 -0
  192. package/src/modules/communication_channels/i18n/de.json +2 -0
  193. package/src/modules/communication_channels/i18n/en.json +2 -0
  194. package/src/modules/communication_channels/i18n/es.json +2 -0
  195. package/src/modules/communication_channels/i18n/ko.json +2 -0
  196. package/src/modules/communication_channels/i18n/pl.json +2 -0
  197. package/src/modules/communication_channels/lib/sanitize-channel-html.ts +23 -3
  198. package/src/modules/communication_channels/widgets/injection/channel-payload-renderer/widget.client.tsx +44 -12
  199. package/src/modules/customers/components/calendar/CalendarEventEditor.tsx +16 -2
  200. package/src/modules/wms/acl.ts +2 -0
  201. package/src/modules/wms/api/asns/[id]/complete/route.ts +62 -0
  202. package/src/modules/wms/api/asns/[id]/receive/route.ts +74 -0
  203. package/src/modules/wms/api/asns/route.ts +200 -0
  204. package/src/modules/wms/api/inventory/helpers.ts +57 -34
  205. package/src/modules/wms/api/inventory/receive/route.ts +2 -1
  206. package/src/modules/wms/api/listEnrichers.ts +38 -0
  207. package/src/modules/wms/api/putaway-tasks/[id]/assign/route.ts +56 -0
  208. package/src/modules/wms/api/putaway-tasks/[id]/cancel/route.ts +56 -0
  209. package/src/modules/wms/api/putaway-tasks/[id]/complete/route.ts +66 -0
  210. package/src/modules/wms/api/putaway-tasks/[id]/start/route.ts +56 -0
  211. package/src/modules/wms/api/putaway-tasks/create-from-balance/route.ts +50 -0
  212. package/src/modules/wms/api/putaway-tasks/route.ts +199 -0
  213. package/src/modules/wms/api/receiving-lines/route.ts +180 -0
  214. package/src/modules/wms/api/scan/putaway/route.ts +108 -0
  215. package/src/modules/wms/api/scan/receive/route.ts +118 -0
  216. package/src/modules/wms/api/scan/resolve-location/route.ts +92 -0
  217. package/src/modules/wms/api/scan/resolve-lot/route.ts +92 -0
  218. package/src/modules/wms/backend/wms/asns/[id]/page.meta.ts +14 -0
  219. package/src/modules/wms/backend/wms/asns/[id]/page.tsx +5 -0
  220. package/src/modules/wms/backend/wms/asns/page.meta.ts +14 -0
  221. package/src/modules/wms/backend/wms/asns/page.tsx +5 -0
  222. package/src/modules/wms/backend/wms/putaway/page.meta.ts +14 -0
  223. package/src/modules/wms/backend/wms/putaway/page.tsx +5 -0
  224. package/src/modules/wms/backend/wms/receiving/page.meta.ts +14 -0
  225. package/src/modules/wms/backend/wms/receiving/page.tsx +5 -0
  226. package/src/modules/wms/ce.ts +27 -0
  227. package/src/modules/wms/commands/asn.ts +2122 -0
  228. package/src/modules/wms/commands/index.ts +2 -0
  229. package/src/modules/wms/commands/inventory-actions.ts +413 -243
  230. package/src/modules/wms/commands/putaway.ts +1169 -0
  231. package/src/modules/wms/commands/shared.ts +51 -0
  232. package/src/modules/wms/components/backend/AssignPutawayTaskDialog.tsx +328 -0
  233. package/src/modules/wms/components/backend/CompletePutawayTaskDialog.tsx +366 -0
  234. package/src/modules/wms/components/backend/CreateAsnDialog.tsx +427 -0
  235. package/src/modules/wms/components/backend/InventoryOperationsSection.tsx +20 -2
  236. package/src/modules/wms/components/backend/ReceiveAsnLineDialog.tsx +535 -0
  237. package/src/modules/wms/components/backend/ReceiveInventoryDialog.tsx +2 -2
  238. package/src/modules/wms/components/backend/WmsAsnDetailPage.tsx +647 -0
  239. package/src/modules/wms/components/backend/WmsAsnsListPage.tsx +407 -0
  240. package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +4 -5
  241. package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +4 -5
  242. package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +12 -8
  243. package/src/modules/wms/components/backend/WmsPutawayQueuePage.tsx +677 -0
  244. package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +4 -5
  245. package/src/modules/wms/components/backend/asnCompleteOptimisticLock.ts +52 -0
  246. package/src/modules/wms/components/backend/asnReceivingLinesLoader.ts +83 -0
  247. package/src/modules/wms/components/backend/inboundStatusUi.ts +154 -0
  248. package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +20 -0
  249. package/src/modules/wms/components/backend/putawayQueueOptimisticLock.ts +20 -0
  250. package/src/modules/wms/components/backend/useWmsInventoryMutationAccess.ts +4 -0
  251. package/src/modules/wms/data/enrichers.ts +175 -13
  252. package/src/modules/wms/data/entities.ts +155 -0
  253. package/src/modules/wms/data/validators.ts +256 -0
  254. package/src/modules/wms/events.ts +11 -0
  255. package/src/modules/wms/extension-points.ts +2 -0
  256. package/src/modules/wms/i18n/de.json +205 -3
  257. package/src/modules/wms/i18n/en.json +205 -3
  258. package/src/modules/wms/i18n/es.json +205 -3
  259. package/src/modules/wms/i18n/ko.json +205 -3
  260. package/src/modules/wms/i18n/pl.json +205 -3
  261. package/src/modules/wms/lib/asnReceiving.ts +226 -0
  262. package/src/modules/wms/lib/asnVendor.ts +80 -0
  263. package/src/modules/wms/lib/flashMutationError.ts +4 -0
  264. package/src/modules/wms/lib/inventoryDisplayUi.ts +46 -0
  265. package/src/modules/wms/lib/inventoryPolicy.ts +31 -1
  266. package/src/modules/wms/lib/loadOperationalDashboard.ts +89 -1
  267. package/src/modules/wms/lib/putaway.ts +210 -0
  268. package/src/modules/wms/lib/roleFeatures.ts +2 -0
  269. package/src/modules/wms/lib/salesOrderInventoryAutomation.ts +150 -1
  270. package/src/modules/wms/lib/scanResolve.ts +185 -0
  271. package/src/modules/wms/lib/wmsIntegrationToggles.ts +2 -1
  272. package/src/modules/wms/migrations/.snapshot-open-mercato.json +1000 -0
  273. package/src/modules/wms/migrations/Migration20260812120000.ts +43 -0
  274. package/src/modules/wms/migrations/Migration20260812130000.ts +28 -0
  275. package/src/modules/wms/migrations/Migration20260822120000.ts +17 -0
  276. package/src/modules/wms/migrations/Migration20260822130000.ts +15 -0
  277. package/src/modules/wms/migrations/Migration20261029120000.ts +11 -0
  278. package/src/modules/wms/search.ts +95 -0
  279. package/src/modules/wms/subscribers/asn-line-received-reevaluate-reservations.ts +21 -0
  280. package/src/modules/wms/subscribers/invalidate-enricher-cache-asn.ts +12 -0
  281. package/src/modules/wms/subscribers/procurement-goods-receipt-created.ts +238 -0
  282. package/src/modules/wms/subscribers/putaway-completed-reevaluate-reservations.ts +21 -0
  283. package/src/modules/wms/widgets/injection/sales-order-stock-context/widget.client.tsx +63 -13
  284. package/src/modules/workflows/lib/activity-executor.ts +89 -58
  285. package/src/modules/workflows/lib/activity-registry.ts +1 -0
  286. package/src/modules/workflows/lib/activity-types.ts +4 -1
  287. package/src/modules/workflows/lib/activity-worker-handler.ts +2 -2
@@ -0,0 +1,427 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { z } from 'zod'
5
+ import { useQueryClient } from '@tanstack/react-query'
6
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
7
+ import { flashMutationError } from '../../lib/flashMutationError'
8
+ import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
9
+ import { ComboboxInput } from '@open-mercato/ui/backend/inputs/ComboboxInput'
10
+ import { apiCall } from '@open-mercato/ui/backend/utils/apiCall'
11
+ import { raiseCrudError } from '@open-mercato/ui/backend/utils/serverErrors'
12
+ import { Button } from '@open-mercato/ui/primitives/button'
13
+ import {
14
+ Dialog,
15
+ DialogContent,
16
+ DialogDescription,
17
+ DialogFooter,
18
+ DialogHeader,
19
+ DialogTitle,
20
+ } from '@open-mercato/ui/primitives/dialog'
21
+ import { FormField } from '@open-mercato/ui/primitives/form-field'
22
+ import { Input } from '@open-mercato/ui/primitives/input'
23
+ import { KbdShortcut } from '@open-mercato/ui/primitives/kbd'
24
+ import { Textarea } from '@open-mercato/ui/primitives/textarea'
25
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
26
+ import {
27
+ loadCatalogVariantOptions,
28
+ loadStagingLocationOptions,
29
+ loadWarehouseOptions,
30
+ resolveCatalogVariantLabel,
31
+ resolveLocationLabel,
32
+ resolveWarehouseLabel,
33
+ } from './inventoryMutationLoaders'
34
+ import type { WmsInventoryMutationAccess } from './useWmsInventoryMutationAccess'
35
+
36
+ type CreateAsnDialogProps = {
37
+ open: boolean
38
+ onOpenChange: (open: boolean) => void
39
+ access: WmsInventoryMutationAccess
40
+ onCreated?: (asnId: string) => void
41
+ }
42
+
43
+ type LineDraft = {
44
+ catalogVariantId: string
45
+ expectedQty: number
46
+ targetStagingLocationId: string
47
+ }
48
+
49
+ const formSchema = z.object({
50
+ warehouseId: z.string().uuid(),
51
+ expectedAt: z.string().min(1),
52
+ referenceNumber: z.string().trim().max(120).optional(),
53
+ notes: z.string().trim().max(2000).optional(),
54
+ lines: z
55
+ .array(
56
+ z.object({
57
+ catalogVariantId: z.string().uuid(),
58
+ expectedQty: z.number().positive(),
59
+ targetStagingLocationId: z.string().uuid().optional(),
60
+ }),
61
+ )
62
+ .min(1),
63
+ })
64
+
65
+ const EMPTY_LINE: LineDraft = {
66
+ catalogVariantId: '',
67
+ expectedQty: 1,
68
+ targetStagingLocationId: '',
69
+ }
70
+
71
+ export function CreateAsnDialog({ open, onOpenChange, access, onCreated }: CreateAsnDialogProps) {
72
+ const t = useT()
73
+ const queryClient = useQueryClient()
74
+ const formRef = React.useRef<HTMLFormElement>(null)
75
+ const { runMutation, retryLastMutation } = useGuardedMutation<{
76
+ retryLastMutation: () => Promise<boolean>
77
+ }>({
78
+ contextId: 'wms-asn-create',
79
+ })
80
+ const mutationContext = React.useMemo(
81
+ () => ({ retryLastMutation }),
82
+ [retryLastMutation],
83
+ )
84
+
85
+ const [warehouseId, setWarehouseId] = React.useState('')
86
+ const [expectedAt, setExpectedAt] = React.useState('')
87
+ const [referenceNumber, setReferenceNumber] = React.useState('')
88
+ const [notes, setNotes] = React.useState('')
89
+ const [lines, setLines] = React.useState<LineDraft[]>([{ ...EMPTY_LINE }])
90
+ const [fieldErrors, setFieldErrors] = React.useState<Record<string, string>>({})
91
+ const [submitting, setSubmitting] = React.useState(false)
92
+ const [labelCache, setLabelCache] = React.useState<Record<string, string>>({})
93
+
94
+ const closeDialog = React.useCallback(() => {
95
+ if (submitting) return
96
+ onOpenChange(false)
97
+ }, [onOpenChange, submitting])
98
+
99
+ React.useEffect(() => {
100
+ if (!open) return
101
+ setWarehouseId('')
102
+ setExpectedAt(new Date().toISOString().slice(0, 10))
103
+ setReferenceNumber('')
104
+ setNotes('')
105
+ setLines([{ ...EMPTY_LINE }])
106
+ setFieldErrors({})
107
+ setSubmitting(false)
108
+ }, [open])
109
+
110
+ const resolveOptionLabel = React.useCallback(
111
+ async (value: string) => {
112
+ if (labelCache[value]) return labelCache[value]
113
+ const [warehouse, variant, location] = await Promise.all([
114
+ resolveWarehouseLabel(value),
115
+ resolveCatalogVariantLabel(value),
116
+ resolveLocationLabel(value),
117
+ ])
118
+ const label = warehouse || variant || location
119
+ if (label) setLabelCache((prev) => ({ ...prev, [value]: label }))
120
+ return label ?? value
121
+ },
122
+ [labelCache],
123
+ )
124
+
125
+ const handleSubmit = React.useCallback(
126
+ async (event?: React.FormEvent) => {
127
+ event?.preventDefault()
128
+ if (!access.scopeReady || !access.organizationId || !access.tenantId) {
129
+ flash(
130
+ t(
131
+ 'wms.backend.inventory.mutations.errors.scope',
132
+ 'Select an organization and sign in before posting inventory changes.',
133
+ ),
134
+ 'error',
135
+ )
136
+ return
137
+ }
138
+
139
+ const parsed = formSchema.safeParse({
140
+ warehouseId,
141
+ expectedAt,
142
+ referenceNumber: referenceNumber.trim() || undefined,
143
+ notes: notes.trim() || undefined,
144
+ lines: lines.map((line) => ({
145
+ catalogVariantId: line.catalogVariantId,
146
+ expectedQty: line.expectedQty,
147
+ targetStagingLocationId: line.targetStagingLocationId.trim() || undefined,
148
+ })),
149
+ })
150
+ if (!parsed.success) {
151
+ const nextErrors: Record<string, string> = {}
152
+ for (const issue of parsed.error.issues) {
153
+ const key = issue.path.join('.') || 'form'
154
+ if (!nextErrors[key]) {
155
+ nextErrors[key] = t(issue.message, issue.message)
156
+ }
157
+ }
158
+ setFieldErrors(nextErrors)
159
+ return
160
+ }
161
+
162
+ setSubmitting(true)
163
+ setFieldErrors({})
164
+ const payload = {
165
+ organizationId: access.organizationId,
166
+ tenantId: access.tenantId,
167
+ warehouseId: parsed.data.warehouseId,
168
+ expectedAt: parsed.data.expectedAt,
169
+ referenceNumber: parsed.data.referenceNumber ?? null,
170
+ notes: parsed.data.notes ?? null,
171
+ status: 'in_transit' as const,
172
+ lines: parsed.data.lines,
173
+ }
174
+
175
+ try {
176
+ const result = await runMutation({
177
+ operation: async () => {
178
+ const call = await apiCall<{ id?: string }>(
179
+ '/api/wms/asns',
180
+ {
181
+ method: 'POST',
182
+ headers: { 'content-type': 'application/json' },
183
+ body: JSON.stringify(payload),
184
+ },
185
+ )
186
+ if (!call.ok) {
187
+ await raiseCrudError(
188
+ call.response,
189
+ t('wms.backend.asns.create.errors.submit', 'Failed to create ASN.'),
190
+ )
191
+ }
192
+ return call.result ?? {}
193
+ },
194
+ context: mutationContext,
195
+ mutationPayload: payload,
196
+ })
197
+
198
+ const asnId = typeof result?.id === 'string' ? result.id : null
199
+ flash(t('wms.backend.asns.create.flash.success', 'ASN created'), 'success')
200
+ await queryClient.invalidateQueries({ queryKey: ['wms-asns-list'] })
201
+ closeDialog()
202
+ if (asnId) onCreated?.(asnId)
203
+ } catch (error) {
204
+ flashMutationError(error, t('wms.backend.asns.create.errors.submit', 'Failed to create ASN.'), t)
205
+ } finally {
206
+ setSubmitting(false)
207
+ }
208
+ },
209
+ [
210
+ access,
211
+ closeDialog,
212
+ expectedAt,
213
+ lines,
214
+ mutationContext,
215
+ notes,
216
+ onCreated,
217
+ queryClient,
218
+ referenceNumber,
219
+ runMutation,
220
+ t,
221
+ warehouseId,
222
+ ],
223
+ )
224
+
225
+ const handleKeyDown = React.useCallback(
226
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
227
+ if (event.key === 'Escape') {
228
+ event.preventDefault()
229
+ closeDialog()
230
+ return
231
+ }
232
+ if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
233
+ event.preventDefault()
234
+ if (!submitting) void handleSubmit()
235
+ }
236
+ },
237
+ [closeDialog, handleSubmit, submitting],
238
+ )
239
+
240
+ return (
241
+ <Dialog open={open} onOpenChange={(next) => (next ? onOpenChange(true) : closeDialog())}>
242
+ <DialogContent className="max-w-xl gap-0 overflow-hidden p-0" onKeyDown={handleKeyDown}>
243
+ <div className="border-b px-6 py-4 pr-12">
244
+ <DialogHeader className="space-y-1 text-left">
245
+ <DialogTitle>{t('wms.backend.asns.create.dialog.title', 'Create ASN')}</DialogTitle>
246
+ <DialogDescription>
247
+ {t(
248
+ 'wms.backend.asns.create.dialog.description',
249
+ 'Create an expected inbound shipment with receiving lines.',
250
+ )}
251
+ </DialogDescription>
252
+ </DialogHeader>
253
+ </div>
254
+
255
+ <form ref={formRef} onSubmit={handleSubmit} className="flex min-h-0 flex-1 flex-col">
256
+ <div className="flex flex-col gap-5 overflow-y-auto px-6 py-6">
257
+ <FormField
258
+ label={t('wms.backend.asns.create.form.warehouse', 'Warehouse')}
259
+ required
260
+ error={fieldErrors.warehouseId}
261
+ >
262
+ <ComboboxInput
263
+ value={warehouseId}
264
+ onChange={setWarehouseId}
265
+ loadSuggestions={async (query) => loadWarehouseOptions(query)}
266
+ resolveLabel={resolveOptionLabel}
267
+ placeholder={t('wms.backend.asns.create.form.warehousePlaceholder', 'Select warehouse')}
268
+ allowCustomValues={false}
269
+ disabled={submitting}
270
+ />
271
+ </FormField>
272
+
273
+ <div className="grid gap-5 sm:grid-cols-2">
274
+ <FormField
275
+ label={t('wms.backend.asns.create.form.expectedAt', 'Expected date')}
276
+ required
277
+ error={fieldErrors.expectedAt}
278
+ >
279
+ <Input
280
+ type="date"
281
+ value={expectedAt}
282
+ onChange={(event) => setExpectedAt(event.target.value)}
283
+ disabled={submitting}
284
+ />
285
+ </FormField>
286
+ <FormField
287
+ label={t('wms.backend.asns.create.form.referenceNumber', 'Reference')}
288
+ error={fieldErrors.referenceNumber}
289
+ >
290
+ <Input
291
+ value={referenceNumber}
292
+ onChange={(event) => setReferenceNumber(event.target.value)}
293
+ disabled={submitting}
294
+ placeholder={t('wms.backend.asns.create.form.referencePlaceholder', 'PO / ASN ref')}
295
+ />
296
+ </FormField>
297
+ </div>
298
+
299
+ <FormField label={t('wms.backend.asns.create.form.notes', 'Notes')} error={fieldErrors.notes}>
300
+ <Textarea
301
+ value={notes}
302
+ onChange={(event) => setNotes(event.target.value)}
303
+ disabled={submitting}
304
+ rows={2}
305
+ />
306
+ </FormField>
307
+
308
+ <div className="space-y-3">
309
+ <div className="flex items-center justify-between gap-2">
310
+ <h3 className="text-sm font-medium">
311
+ {t('wms.backend.asns.create.form.lines', 'Expected lines')}
312
+ </h3>
313
+ <Button
314
+ type="button"
315
+ variant="outline"
316
+ size="sm"
317
+ disabled={submitting}
318
+ onClick={() => setLines((current) => [...current, { ...EMPTY_LINE }])}
319
+ >
320
+ {t('wms.backend.asns.create.form.addLine', 'Add line')}
321
+ </Button>
322
+ </div>
323
+ {lines.map((line, index) => (
324
+ <div key={`line-${index}`} className="grid gap-3 rounded-md border p-3 sm:grid-cols-3">
325
+ <FormField
326
+ label={t('wms.backend.asns.create.form.variant', 'Variant')}
327
+ required
328
+ error={fieldErrors[`lines.${index}.catalogVariantId`]}
329
+ className="sm:col-span-2"
330
+ >
331
+ <ComboboxInput
332
+ value={line.catalogVariantId}
333
+ onChange={(next) => {
334
+ setLines((current) =>
335
+ current.map((item, itemIndex) =>
336
+ itemIndex === index ? { ...item, catalogVariantId: next.trim() } : item,
337
+ ),
338
+ )
339
+ }}
340
+ loadSuggestions={async (query) => loadCatalogVariantOptions(query)}
341
+ resolveLabel={resolveOptionLabel}
342
+ placeholder={t(
343
+ 'wms.backend.asns.create.form.variantPlaceholder',
344
+ 'Search variant or SKU',
345
+ )}
346
+ allowCustomValues={false}
347
+ disabled={submitting}
348
+ />
349
+ </FormField>
350
+ <FormField
351
+ label={t('wms.backend.asns.create.form.expectedQty', 'Expected qty')}
352
+ required
353
+ error={fieldErrors[`lines.${index}.expectedQty`]}
354
+ >
355
+ <Input
356
+ type="number"
357
+ min={0.0001}
358
+ step="any"
359
+ value={line.expectedQty}
360
+ onChange={(event) => {
361
+ const next = Number(event.target.value)
362
+ setLines((current) =>
363
+ current.map((item, itemIndex) =>
364
+ itemIndex === index
365
+ ? { ...item, expectedQty: Number.isFinite(next) ? next : 0 }
366
+ : item,
367
+ ),
368
+ )
369
+ }}
370
+ disabled={submitting}
371
+ />
372
+ </FormField>
373
+ <FormField
374
+ label={t('wms.backend.asns.create.form.staging', 'Staging location')}
375
+ error={fieldErrors[`lines.${index}.targetStagingLocationId`]}
376
+ className="sm:col-span-3"
377
+ >
378
+ <ComboboxInput
379
+ value={line.targetStagingLocationId}
380
+ onChange={(next) => {
381
+ setLines((current) =>
382
+ current.map((item, itemIndex) =>
383
+ itemIndex === index
384
+ ? { ...item, targetStagingLocationId: next.trim() }
385
+ : item,
386
+ ),
387
+ )
388
+ }}
389
+ loadSuggestions={async (query) =>
390
+ warehouseId ? loadStagingLocationOptions(warehouseId, query) : []
391
+ }
392
+ resolveLabel={resolveOptionLabel}
393
+ placeholder={t(
394
+ 'wms.backend.asns.create.form.stagingPlaceholder',
395
+ 'Optional staging/dock',
396
+ )}
397
+ allowCustomValues={false}
398
+ disabled={submitting || !warehouseId}
399
+ />
400
+ </FormField>
401
+ </div>
402
+ ))}
403
+ {fieldErrors.lines ? (
404
+ <p className="text-sm text-status-error-text">{fieldErrors.lines}</p>
405
+ ) : null}
406
+ </div>
407
+ </div>
408
+
409
+ <DialogFooter bordered={false} className="border-t px-6 py-4 sm:justify-between">
410
+ <span className="hidden text-xs text-muted-foreground sm:inline">
411
+ <KbdShortcut keys={['Ctrl/⌘', 'Enter']} />{' '}
412
+ {t('wms.backend.asns.create.dialog.shortcutHint', 'to save')}
413
+ </span>
414
+ <div className="flex gap-2">
415
+ <Button type="button" variant="outline" onClick={closeDialog} disabled={submitting}>
416
+ {t('wms.backend.asns.create.dialog.cancel', 'Cancel')}
417
+ </Button>
418
+ <Button type="submit" disabled={submitting} data-testid="create-asn-submit">
419
+ {t('wms.backend.asns.create.dialog.submit', 'Create ASN')}
420
+ </Button>
421
+ </div>
422
+ </DialogFooter>
423
+ </form>
424
+ </DialogContent>
425
+ </Dialog>
426
+ )
427
+ }
@@ -1,9 +1,18 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from 'react'
4
+ import Link from 'next/link'
4
5
  import { Button } from '@open-mercato/ui/primitives/button'
5
6
  import { useT } from '@open-mercato/shared/lib/i18n/context'
6
- import { ArrowDown, ArrowLeftRight, ClipboardList, ShieldCheck, SlidersHorizontal, Upload } from 'lucide-react'
7
+ import {
8
+ ArrowDown,
9
+ ArrowLeftRight,
10
+ ClipboardList,
11
+ PackageCheck,
12
+ ShieldCheck,
13
+ SlidersHorizontal,
14
+ Upload,
15
+ } from 'lucide-react'
7
16
  import { AdjustInventoryDialog } from './AdjustInventoryDialog'
8
17
  import { CycleCountWizardDialog } from './CycleCountWizardDialog'
9
18
  import { ImportInventoryDialog } from './ImportInventoryDialog'
@@ -67,6 +76,7 @@ export function InventoryOperationsSection({
67
76
  if (
68
77
  !access.canAdjust &&
69
78
  !access.canReceive &&
79
+ !access.canManageAsn &&
70
80
  !access.canReserve &&
71
81
  !access.canMove &&
72
82
  !access.canCycleCount &&
@@ -112,10 +122,18 @@ export function InventoryOperationsSection({
112
122
  {t('wms.backend.inventory.operations.reserve', 'Reserve')}
113
123
  </Button>
114
124
  ) : null}
125
+ {access.canManageAsn || access.canReceive ? (
126
+ <Button type="button" variant="outline" asChild>
127
+ <Link href="/backend/wms/asns">
128
+ <PackageCheck className="size-4" />
129
+ {t('wms.backend.inventory.operations.receiveAsn', 'Receive ASN')}
130
+ </Link>
131
+ </Button>
132
+ ) : null}
115
133
  {access.canReceive ? (
116
134
  <Button type="button" variant="default" onClick={() => setReceiveOpen(true)}>
117
135
  <ArrowDown className="size-4" />
118
- {t('wms.backend.inventory.operations.receive', 'Receive stock')}
136
+ {t('wms.backend.inventory.operations.receive', 'Receive stock (no ASN)')}
119
137
  </Button>
120
138
  ) : null}
121
139
  </SectionCard>