@qoretechnologies/reqraft 0.10.25 → 0.10.26

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 (310) hide show
  1. package/.claude/CLAUDE.md +52 -23
  2. package/design/COMPACT_ENGINE_REDESIGN.md +156 -0
  3. package/design/FORM_ENGINE_COMPACT_UX_PLAN.md +353 -0
  4. package/dist/components/FocusedEditing/index.d.ts +9 -1
  5. package/dist/components/FocusedEditing/index.d.ts.map +1 -1
  6. package/dist/components/FocusedEditing/index.js +2 -2
  7. package/dist/components/FocusedEditing/index.js.map +1 -1
  8. package/dist/components/composer/Composer.d.ts +108 -0
  9. package/dist/components/composer/Composer.d.ts.map +1 -0
  10. package/dist/components/composer/Composer.js +238 -0
  11. package/dist/components/composer/Composer.js.map +1 -0
  12. package/dist/components/composer/helpers.d.ts +21 -0
  13. package/dist/components/composer/helpers.d.ts.map +1 -0
  14. package/dist/components/composer/helpers.js +75 -0
  15. package/dist/components/composer/helpers.js.map +1 -0
  16. package/dist/components/composer/index.d.ts +3 -0
  17. package/dist/components/composer/index.d.ts.map +1 -0
  18. package/dist/components/composer/index.js +19 -0
  19. package/dist/components/composer/index.js.map +1 -0
  20. package/dist/components/form/engine/CompactRow.d.ts.map +1 -1
  21. package/dist/components/form/engine/CompactRow.js +307 -110
  22. package/dist/components/form/engine/CompactRow.js.map +1 -1
  23. package/dist/components/form/engine/CompactToolbar.d.ts.map +1 -1
  24. package/dist/components/form/engine/CompactToolbar.js +123 -106
  25. package/dist/components/form/engine/CompactToolbar.js.map +1 -1
  26. package/dist/components/form/engine/FormEngine.d.ts +107 -11
  27. package/dist/components/form/engine/FormEngine.d.ts.map +1 -1
  28. package/dist/components/form/engine/FormEngine.js +618 -179
  29. package/dist/components/form/engine/FormEngine.js.map +1 -1
  30. package/dist/components/form/engine/compactRowContext.d.ts +9 -0
  31. package/dist/components/form/engine/compactRowContext.d.ts.map +1 -1
  32. package/dist/components/form/engine/compactRowContext.js.map +1 -1
  33. package/dist/components/form/engine/compactRowStyles.d.ts +7 -3
  34. package/dist/components/form/engine/compactRowStyles.d.ts.map +1 -1
  35. package/dist/components/form/engine/compactRowStyles.js +88 -51
  36. package/dist/components/form/engine/compactRowStyles.js.map +1 -1
  37. package/dist/components/form/engine/compactToolbarContext.d.ts +1 -0
  38. package/dist/components/form/engine/compactToolbarContext.d.ts.map +1 -1
  39. package/dist/components/form/engine/compactToolbarContext.js.map +1 -1
  40. package/dist/components/form/engine/optionActions.d.ts +28 -0
  41. package/dist/components/form/engine/optionActions.d.ts.map +1 -0
  42. package/dist/components/form/engine/optionActions.js +18 -0
  43. package/dist/components/form/engine/optionActions.js.map +1 -0
  44. package/dist/components/form/engine/readFirst.d.ts +63 -2
  45. package/dist/components/form/engine/readFirst.d.ts.map +1 -1
  46. package/dist/components/form/engine/readFirst.js +121 -6
  47. package/dist/components/form/engine/readFirst.js.map +1 -1
  48. package/dist/components/form/engine/rendererTypes.d.ts +35 -0
  49. package/dist/components/form/engine/rendererTypes.d.ts.map +1 -0
  50. package/dist/components/form/engine/rendererTypes.js +63 -0
  51. package/dist/components/form/engine/rendererTypes.js.map +1 -0
  52. package/dist/components/form/engine/variants/VariantCalmTable.d.ts +6 -0
  53. package/dist/components/form/engine/variants/VariantCalmTable.d.ts.map +1 -0
  54. package/dist/components/form/engine/variants/VariantCalmTable.js +94 -0
  55. package/dist/components/form/engine/variants/VariantCalmTable.js.map +1 -0
  56. package/dist/components/form/engine/variants/VariantCards.d.ts +6 -0
  57. package/dist/components/form/engine/variants/VariantCards.d.ts.map +1 -0
  58. package/dist/components/form/engine/variants/VariantCards.js +80 -0
  59. package/dist/components/form/engine/variants/VariantCards.js.map +1 -0
  60. package/dist/components/form/engine/variants/VariantFocus.d.ts +7 -0
  61. package/dist/components/form/engine/variants/VariantFocus.d.ts.map +1 -0
  62. package/dist/components/form/engine/variants/VariantFocus.js +138 -0
  63. package/dist/components/form/engine/variants/VariantFocus.js.map +1 -0
  64. package/dist/components/form/engine/variants/VariantMinimal.d.ts +6 -0
  65. package/dist/components/form/engine/variants/VariantMinimal.d.ts.map +1 -0
  66. package/dist/components/form/engine/variants/VariantMinimal.js +73 -0
  67. package/dist/components/form/engine/variants/VariantMinimal.js.map +1 -0
  68. package/dist/components/form/engine/variants/focusDemo.d.ts +13 -0
  69. package/dist/components/form/engine/variants/focusDemo.d.ts.map +1 -0
  70. package/dist/components/form/engine/variants/focusDemo.js +139 -0
  71. package/dist/components/form/engine/variants/focusDemo.js.map +1 -0
  72. package/dist/components/form/engine/variants/variantModel.d.ts +70 -0
  73. package/dist/components/form/engine/variants/variantModel.d.ts.map +1 -0
  74. package/dist/components/form/engine/variants/variantModel.js +133 -0
  75. package/dist/components/form/engine/variants/variantModel.js.map +1 -0
  76. package/dist/components/form/engine/variants/variantParts.d.ts +79 -0
  77. package/dist/components/form/engine/variants/variantParts.d.ts.map +1 -0
  78. package/dist/components/form/engine/variants/variantParts.js +191 -0
  79. package/dist/components/form/engine/variants/variantParts.js.map +1 -0
  80. package/dist/components/form/expressions/builder/index.d.ts.map +1 -1
  81. package/dist/components/form/expressions/builder/index.js +13 -2
  82. package/dist/components/form/expressions/builder/index.js.map +1 -1
  83. package/dist/components/form/expressions/useExpressions.d.ts.map +1 -1
  84. package/dist/components/form/expressions/useExpressions.js +4 -1
  85. package/dist/components/form/expressions/useExpressions.js.map +1 -1
  86. package/dist/components/form/fields/Field.d.ts.map +1 -1
  87. package/dist/components/form/fields/Field.js +5 -3
  88. package/dist/components/form/fields/Field.js.map +1 -1
  89. package/dist/components/form/fields/allowed-values/AllowedValues.d.ts +2 -1
  90. package/dist/components/form/fields/allowed-values/AllowedValues.d.ts.map +1 -1
  91. package/dist/components/form/fields/allowed-values/AllowedValues.js +8 -26
  92. package/dist/components/form/fields/allowed-values/AllowedValues.js.map +1 -1
  93. package/dist/components/form/fields/auto/AutoFormField.d.ts +3 -0
  94. package/dist/components/form/fields/auto/AutoFormField.d.ts.map +1 -1
  95. package/dist/components/form/fields/auto/AutoFormField.js +42 -8
  96. package/dist/components/form/fields/auto/AutoFormField.js.map +1 -1
  97. package/dist/components/form/fields/binary/Binary.d.ts +15 -0
  98. package/dist/components/form/fields/binary/Binary.d.ts.map +1 -0
  99. package/dist/components/form/fields/binary/Binary.js +74 -0
  100. package/dist/components/form/fields/binary/Binary.js.map +1 -0
  101. package/dist/components/form/fields/boolean/Boolean.js +1 -1
  102. package/dist/components/form/fields/boolean/Boolean.js.map +1 -1
  103. package/dist/components/form/fields/multi-select/MultiSelectFormField.d.ts.map +1 -1
  104. package/dist/components/form/fields/multi-select/MultiSelectFormField.js +5 -4
  105. package/dist/components/form/fields/multi-select/MultiSelectFormField.js.map +1 -1
  106. package/dist/components/form/fields/select/Select.d.ts.map +1 -1
  107. package/dist/components/form/fields/select/Select.js +29 -12
  108. package/dist/components/form/fields/select/Select.js.map +1 -1
  109. package/dist/components/form/fields/select/SelectCollection.d.ts +8 -2
  110. package/dist/components/form/fields/select/SelectCollection.d.ts.map +1 -1
  111. package/dist/components/form/fields/select/SelectCollection.js +52 -16
  112. package/dist/components/form/fields/select/SelectCollection.js.map +1 -1
  113. package/dist/components/form/index.d.ts +2 -0
  114. package/dist/components/form/index.d.ts.map +1 -1
  115. package/dist/components/form/index.js +2 -0
  116. package/dist/components/form/index.js.map +1 -1
  117. package/dist/components/imageLightbox/ImageLightbox.d.ts +21 -0
  118. package/dist/components/imageLightbox/ImageLightbox.d.ts.map +1 -0
  119. package/dist/components/imageLightbox/ImageLightbox.js +169 -0
  120. package/dist/components/imageLightbox/ImageLightbox.js.map +1 -0
  121. package/dist/components/imageLightbox/index.d.ts +2 -0
  122. package/dist/components/imageLightbox/index.d.ts.map +1 -0
  123. package/dist/components/imageLightbox/index.js +18 -0
  124. package/dist/components/imageLightbox/index.js.map +1 -0
  125. package/dist/components/searchFilterBar/SearchFilterBar.d.ts +33 -0
  126. package/dist/components/searchFilterBar/SearchFilterBar.d.ts.map +1 -0
  127. package/dist/components/searchFilterBar/SearchFilterBar.js +76 -0
  128. package/dist/components/searchFilterBar/SearchFilterBar.js.map +1 -0
  129. package/dist/components/searchFilterBar/index.d.ts +2 -0
  130. package/dist/components/searchFilterBar/index.d.ts.map +1 -0
  131. package/dist/components/searchFilterBar/index.js +18 -0
  132. package/dist/components/searchFilterBar/index.js.map +1 -0
  133. package/dist/components/supportTicket/AttachmentChips.d.ts +10 -0
  134. package/dist/components/supportTicket/AttachmentChips.d.ts.map +1 -0
  135. package/dist/components/supportTicket/AttachmentChips.js +122 -0
  136. package/dist/components/supportTicket/AttachmentChips.js.map +1 -0
  137. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts +43 -0
  138. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts.map +1 -0
  139. package/dist/components/supportTicket/InterfaceReferenceTags.js +31 -0
  140. package/dist/components/supportTicket/InterfaceReferenceTags.js.map +1 -0
  141. package/dist/components/supportTicket/ReferencePicker.d.ts +87 -0
  142. package/dist/components/supportTicket/ReferencePicker.d.ts.map +1 -0
  143. package/dist/components/supportTicket/ReferencePicker.js +295 -0
  144. package/dist/components/supportTicket/ReferencePicker.js.map +1 -0
  145. package/dist/components/supportTicket/TicketHeader.d.ts +86 -0
  146. package/dist/components/supportTicket/TicketHeader.d.ts.map +1 -0
  147. package/dist/components/supportTicket/TicketHeader.js +149 -0
  148. package/dist/components/supportTicket/TicketHeader.js.map +1 -0
  149. package/dist/components/supportTicket/TicketMetaTags.d.ts +32 -0
  150. package/dist/components/supportTicket/TicketMetaTags.d.ts.map +1 -0
  151. package/dist/components/supportTicket/TicketMetaTags.js +21 -0
  152. package/dist/components/supportTicket/TicketMetaTags.js.map +1 -0
  153. package/dist/components/supportTicket/TicketReplyBox.d.ts +63 -0
  154. package/dist/components/supportTicket/TicketReplyBox.d.ts.map +1 -0
  155. package/dist/components/supportTicket/TicketReplyBox.js +115 -0
  156. package/dist/components/supportTicket/TicketReplyBox.js.map +1 -0
  157. package/dist/components/supportTicket/attachmentAccess.d.ts +37 -0
  158. package/dist/components/supportTicket/attachmentAccess.d.ts.map +1 -0
  159. package/dist/components/supportTicket/attachmentAccess.js +132 -0
  160. package/dist/components/supportTicket/attachmentAccess.js.map +1 -0
  161. package/dist/components/supportTicket/fileToAttachment.d.ts +9 -0
  162. package/dist/components/supportTicket/fileToAttachment.d.ts.map +1 -0
  163. package/dist/components/supportTicket/fileToAttachment.js +28 -0
  164. package/dist/components/supportTicket/fileToAttachment.js.map +1 -0
  165. package/dist/components/supportTicket/index.d.ts +11 -0
  166. package/dist/components/supportTicket/index.d.ts.map +1 -0
  167. package/dist/components/supportTicket/index.js +27 -0
  168. package/dist/components/supportTicket/index.js.map +1 -0
  169. package/dist/components/supportTicket/meta.d.ts +71 -0
  170. package/dist/components/supportTicket/meta.d.ts.map +1 -0
  171. package/dist/components/supportTicket/meta.js +115 -0
  172. package/dist/components/supportTicket/meta.js.map +1 -0
  173. package/dist/components/supportTicket/ticketModel.d.ts +102 -0
  174. package/dist/components/supportTicket/ticketModel.d.ts.map +1 -0
  175. package/dist/components/supportTicket/ticketModel.js +3 -0
  176. package/dist/components/supportTicket/ticketModel.js.map +1 -0
  177. package/dist/components/ticketReferences/TicketReferences.d.ts +52 -0
  178. package/dist/components/ticketReferences/TicketReferences.d.ts.map +1 -0
  179. package/dist/components/ticketReferences/TicketReferences.js +492 -0
  180. package/dist/components/ticketReferences/TicketReferences.js.map +1 -0
  181. package/dist/components/ticketReferences/index.d.ts +3 -0
  182. package/dist/components/ticketReferences/index.d.ts.map +1 -0
  183. package/dist/components/ticketReferences/index.js +6 -0
  184. package/dist/components/ticketReferences/index.js.map +1 -0
  185. package/dist/components/ticketThread/TicketThread.d.ts +57 -0
  186. package/dist/components/ticketThread/TicketThread.d.ts.map +1 -0
  187. package/dist/components/ticketThread/TicketThread.js +299 -0
  188. package/dist/components/ticketThread/TicketThread.js.map +1 -0
  189. package/dist/components/ticketThread/index.d.ts +3 -0
  190. package/dist/components/ticketThread/index.d.ts.map +1 -0
  191. package/dist/components/ticketThread/index.js +7 -0
  192. package/dist/components/ticketThread/index.js.map +1 -0
  193. package/dist/helpers/common.d.ts +5 -0
  194. package/dist/helpers/common.d.ts.map +1 -1
  195. package/dist/helpers/common.js +20 -1
  196. package/dist/helpers/common.js.map +1 -1
  197. package/dist/helpers/scrollbar.d.ts +2 -0
  198. package/dist/helpers/scrollbar.d.ts.map +1 -0
  199. package/dist/helpers/scrollbar.js +25 -0
  200. package/dist/helpers/scrollbar.js.map +1 -0
  201. package/dist/index.d.ts +8 -1
  202. package/dist/index.d.ts.map +1 -1
  203. package/dist/index.js +10 -1
  204. package/dist/index.js.map +1 -1
  205. package/dist/providers/StorageProvider.d.ts +13 -0
  206. package/dist/providers/StorageProvider.d.ts.map +1 -1
  207. package/dist/providers/StorageProvider.js +29 -5
  208. package/dist/providers/StorageProvider.js.map +1 -1
  209. package/package.json +6 -5
  210. package/src/components/FocusedEditing/index.tsx +17 -2
  211. package/src/components/composer/Composer.stories.tsx +238 -0
  212. package/src/components/composer/Composer.tsx +545 -0
  213. package/src/components/composer/helpers.ts +74 -0
  214. package/src/components/composer/index.ts +2 -0
  215. package/src/components/dpqlEditor/DpqlEditor.stories.tsx +74 -2
  216. package/src/components/form/engine/CompactRow.tsx +561 -283
  217. package/src/components/form/engine/CompactToolbar.tsx +216 -182
  218. package/src/components/form/engine/FormEngine.stories.tsx +1736 -162
  219. package/src/components/form/engine/FormEngine.tsx +886 -170
  220. package/src/components/form/engine/FormEngineRemote.stories.tsx +377 -0
  221. package/src/components/form/engine/_structuredData/StructuredDataView.stories.tsx +8 -0
  222. package/src/components/form/engine/compactRowContext.ts +14 -0
  223. package/src/components/form/engine/compactRowStyles.ts +273 -146
  224. package/src/components/form/engine/compactToolbarContext.ts +1 -0
  225. package/src/components/form/engine/optionActions.ts +40 -0
  226. package/src/components/form/engine/readFirst.ts +169 -10
  227. package/src/components/form/engine/rendererTypes.ts +55 -0
  228. package/src/components/form/engine/variants/FormEngineVariants.stories.tsx +159 -0
  229. package/src/components/form/engine/variants/VariantCalmTable.tsx +242 -0
  230. package/src/components/form/engine/variants/VariantCards.tsx +212 -0
  231. package/src/components/form/engine/variants/VariantFocus.tsx +382 -0
  232. package/src/components/form/engine/variants/VariantMinimal.tsx +170 -0
  233. package/src/components/form/engine/variants/focusDemo.ts +145 -0
  234. package/src/components/form/engine/variants/variantModel.ts +216 -0
  235. package/src/components/form/engine/variants/variantParts.tsx +313 -0
  236. package/src/components/form/expressions/ExpressionField.stories.tsx +84 -2
  237. package/src/components/form/expressions/builder/ExpressionBuilder.stories.tsx +213 -19
  238. package/src/components/form/expressions/builder/index.tsx +12 -1
  239. package/src/components/form/expressions/useExpressions.ts +4 -1
  240. package/src/components/form/fields/Field.stories.tsx +40 -0
  241. package/src/components/form/fields/Field.tsx +10 -1
  242. package/src/components/form/fields/allowed-values/AllowedValues.tsx +13 -36
  243. package/src/components/form/fields/array/ArrayAutoField.stories.tsx +64 -0
  244. package/src/components/form/fields/auto/AutoFormField.stories.tsx +146 -2
  245. package/src/components/form/fields/auto/AutoFormField.tsx +42 -1
  246. package/src/components/form/fields/binary/Binary.stories.tsx +122 -0
  247. package/src/components/form/fields/binary/Binary.tsx +81 -0
  248. package/src/components/form/fields/boolean/Boolean.stories.tsx +58 -0
  249. package/src/components/form/fields/boolean/Boolean.tsx +1 -1
  250. package/src/components/form/fields/byte-size/ByteSize.stories.tsx +24 -0
  251. package/src/components/form/fields/color/Color.stories.tsx +30 -0
  252. package/src/components/form/fields/cron/Cron.stories.tsx +8 -0
  253. package/src/components/form/fields/date/Date.stories.tsx +22 -0
  254. package/src/components/form/fields/file/File.stories.tsx +48 -0
  255. package/src/components/form/fields/long-string/LongString.stories.tsx +24 -0
  256. package/src/components/form/fields/markdown/Markdown.stories.tsx +8 -0
  257. package/src/components/form/fields/multi-select/MultiSelectFormField.tsx +14 -10
  258. package/src/components/form/fields/number/Number.stories.tsx +31 -0
  259. package/src/components/form/fields/object/Object.stories.tsx +88 -0
  260. package/src/components/form/fields/radio-group/RadioGroup.stories.tsx +24 -0
  261. package/src/components/form/fields/rich-text/RichText.stories.tsx +23 -0
  262. package/src/components/form/fields/schema-definition/SchemaDefinitionField.stories.tsx +72 -0
  263. package/src/components/form/fields/select/Select.stories.tsx +108 -0
  264. package/src/components/form/fields/select/Select.tsx +38 -12
  265. package/src/components/form/fields/select/SelectCollection.tsx +78 -17
  266. package/src/components/form/fields/string/String.stories.tsx +16 -0
  267. package/src/components/form/fields/template/TemplateField.stories.tsx +160 -0
  268. package/src/components/form/fields/url/Url.stories.tsx +24 -0
  269. package/src/components/form/index.tsx +2 -0
  270. package/src/components/imageLightbox/ImageLightbox.stories.tsx +238 -0
  271. package/src/components/imageLightbox/ImageLightbox.tsx +236 -0
  272. package/src/components/imageLightbox/index.ts +1 -0
  273. package/src/components/log/Log.stories.tsx +96 -0
  274. package/src/components/menu/Menu.stories.tsx +54 -0
  275. package/src/components/qonsoleSmartInput/QonsoleSmartInput.stories.tsx +83 -37
  276. package/src/components/searchFilterBar/SearchFilterBar.tsx +131 -0
  277. package/src/components/searchFilterBar/index.ts +1 -0
  278. package/src/components/smartEditor/SmartEditor.stories.tsx +32 -0
  279. package/src/components/supportTicket/AttachmentChips.stories.tsx +171 -0
  280. package/src/components/supportTicket/AttachmentChips.tsx +147 -0
  281. package/src/components/supportTicket/InterfaceReferenceTags.stories.tsx +171 -0
  282. package/src/components/supportTicket/InterfaceReferenceTags.tsx +96 -0
  283. package/src/components/supportTicket/ReferencePicker.stories.tsx +519 -0
  284. package/src/components/supportTicket/ReferencePicker.tsx +563 -0
  285. package/src/components/supportTicket/TicketConversation.stories.tsx +121 -0
  286. package/src/components/supportTicket/TicketHeader.stories.tsx +183 -0
  287. package/src/components/supportTicket/TicketHeader.tsx +247 -0
  288. package/src/components/supportTicket/TicketMetaTags.stories.tsx +103 -0
  289. package/src/components/supportTicket/TicketMetaTags.tsx +85 -0
  290. package/src/components/supportTicket/TicketReplyBox.stories.tsx +351 -0
  291. package/src/components/supportTicket/TicketReplyBox.tsx +146 -0
  292. package/src/components/supportTicket/attachmentAccess.ts +97 -0
  293. package/src/components/supportTicket/fileToAttachment.ts +24 -0
  294. package/src/components/supportTicket/index.ts +10 -0
  295. package/src/components/supportTicket/meta.ts +185 -0
  296. package/src/components/supportTicket/ticketModel.ts +131 -0
  297. package/src/components/ticketReferences/TicketReferences.stories.tsx +315 -0
  298. package/src/components/ticketReferences/TicketReferences.tsx +886 -0
  299. package/src/components/ticketReferences/index.ts +2 -0
  300. package/src/components/ticketThread/TicketThread.stories.tsx +828 -0
  301. package/src/components/ticketThread/TicketThread.tsx +704 -0
  302. package/src/components/ticketThread/index.ts +6 -0
  303. package/src/helpers/common.ts +19 -0
  304. package/src/helpers/scrollbar.ts +32 -0
  305. package/src/hooks/useFetch/useFetch.stories.tsx +30 -0
  306. package/src/hooks/useStorage/useStorage.stories.tsx +82 -0
  307. package/src/hooks/useWebSocket/useWebsocket.stories.tsx +127 -1
  308. package/src/index.tsx +8 -1
  309. package/src/providers/StorageProvider.tsx +30 -4
  310. package/src/stores/currentUser/currentUser.stories.tsx +49 -0
@@ -0,0 +1,351 @@
1
+ import { ReqoreButton, ReqoreUIProvider } from '@qoretechnologies/reqore';
2
+ import { StoryObj } from '@storybook/react-vite';
3
+ import { expect, fn, screen, userEvent, waitFor, within } from 'storybook/test';
4
+ import { StoryMeta } from '../../types';
5
+ import { InterfaceReferenceTags } from './InterfaceReferenceTags';
6
+ import { TicketReplyBox } from './TicketReplyBox';
7
+
8
+ const meta = {
9
+ component: TicketReplyBox,
10
+ title: 'Components/TicketReplyBox',
11
+ args: {
12
+ onSend: fn(),
13
+ },
14
+ } as StoryMeta<typeof TicketReplyBox>;
15
+
16
+ export default meta;
17
+ type Story = StoryObj<typeof meta>;
18
+
19
+ /**
20
+ * The customer composer, plain-editor variant (used here for a deterministic
21
+ * type→send test): an attach button (no extra menu → a plain button, not a
22
+ * dropdown) and Send. No internal-note toggle. Typing enables Send; clicking it
23
+ * calls `onSend` with the body and `internal: false`.
24
+ */
25
+ export const Default: Story = {
26
+ parameters: {
27
+ docs: {
28
+ description: {
29
+ story:
30
+ "Renders the customer composer's plain-editor variant — an attach button and Send, no internal-note toggle; typing a reply enables Send, which calls onSend with the body and internal: false.",
31
+ },
32
+ },
33
+ },
34
+ args: { editor: 'plain' },
35
+ async play({ canvasElement, args }) {
36
+ const canvas = within(canvasElement);
37
+ const textarea = canvasElement.querySelector('textarea');
38
+ await expect(textarea).not.toBeNull();
39
+ await expect(canvas.queryByText('Internal note')).not.toBeInTheDocument();
40
+
41
+ await userEvent.type(textarea!, 'Here is my reply');
42
+ await userEvent.click(canvas.getByText('Send reply'));
43
+ await waitFor(() =>
44
+ expect(args.onSend).toHaveBeenCalledWith(
45
+ 'Here is my reply',
46
+ expect.objectContaining({ internal: false })
47
+ )
48
+ );
49
+ },
50
+ };
51
+
52
+ /**
53
+ * The staff composer (`allowInternalNote`): no toggle — the send button splits, so
54
+ * the primary action posts a public reply and the caret opens "Add internal note",
55
+ * which sends with `internal: true`.
56
+ */
57
+ export const StaffWithInternalNote: Story = {
58
+ parameters: {
59
+ docs: {
60
+ description: {
61
+ story:
62
+ "Renders the staff composer with a split send button — the primary action posts a public reply, while the caret opens 'Add internal note', which sends with internal: true.",
63
+ },
64
+ },
65
+ },
66
+ args: { allowInternalNote: true, editor: 'plain' },
67
+ async play({ canvasElement, args }) {
68
+ const canvas = within(canvasElement);
69
+ // no toggle any more; the primary action is a plain "Send reply"
70
+ await expect(canvas.queryByText('Internal note')).not.toBeInTheDocument();
71
+ await expect(canvas.getByText('Send reply')).toBeInTheDocument();
72
+
73
+ const textarea = canvasElement.querySelector('textarea');
74
+ await userEvent.type(textarea!, 'internal context');
75
+
76
+ // "Add internal note" lives behind the split-send caret
77
+ const caret = canvasElement.querySelector('.ticket-send-more');
78
+ await expect(caret).not.toBeNull();
79
+ await userEvent.click(caret as Element);
80
+ await userEvent.click(await screen.findByText('Add internal note'));
81
+
82
+ await waitFor(() =>
83
+ expect(args.onSend).toHaveBeenCalledWith(
84
+ 'internal context',
85
+ expect.objectContaining({ internal: true })
86
+ )
87
+ );
88
+ },
89
+ };
90
+
91
+ /** A closed ticket replaces the editor with a muted notice. */
92
+ export const Closed: Story = {
93
+ parameters: {
94
+ docs: {
95
+ description: {
96
+ story:
97
+ "Renders a closed ticket, where the disabled composer replaces the editor with a muted 'ticket is closed' notice.",
98
+ },
99
+ },
100
+ },
101
+ args: { disabled: true },
102
+ async play({ canvasElement }) {
103
+ await expect(within(canvasElement).getByText(/ticket is closed/i)).toBeInTheDocument();
104
+ await expect(canvasElement.querySelector('textarea')).toBeNull();
105
+ },
106
+ };
107
+
108
+ /**
109
+ * The helpdesk composer as it now ships: the shared `<Composer>` with the rich,
110
+ * Qonsole-style editor (`ReqoreRichTextEditor`) instead of a plain textarea. Staff
111
+ * split-send, an attach dropdown (Upload + injected screenshot/capture), the
112
+ * reference-interfaces toggle, and a reference chip below — all through the same
113
+ * slots. Markdown still flows to `onSend` as a plain string. This is the input the
114
+ * helpdesk uses.
115
+ */
116
+ export const RichHelpdeskReply: Story = {
117
+ parameters: {
118
+ docs: {
119
+ description: {
120
+ story:
121
+ 'Renders the shipping helpdesk composer with the rich Qonsole-style editor — staff split-send, an attach dropdown, a reference-interfaces toggle, and an interface reference chip above the input.',
122
+ },
123
+ },
124
+ },
125
+ // Rendered under the Qorus theme (as in qorus-ide / admin-portal) so the
126
+ // `custom1` accent shows as the Qorus purple — a bare reqore theme greys it out.
127
+ decorators: [
128
+ (Story) => (
129
+ <ReqoreUIProvider theme={{ main: '#121212', intents: { custom1: '#762f7e' } }}>
130
+ <div style={{ padding: 20, background: '#121212' }}>
131
+ <Story />
132
+ </div>
133
+ </ReqoreUIProvider>
134
+ ),
135
+ ],
136
+ args: {
137
+ allowInternalNote: true,
138
+ defaultText:
139
+ "Thanks for the detailed report — we've reproduced the timeout and a fix is in review. In the meantime, can you confirm the datasource pool size configured for the sftp-partner connection?",
140
+ attachMenuItems: () => [
141
+ { label: 'Take screenshot', icon: 'CameraAiLine', onClick: fn() },
142
+ { label: 'Capture area', icon: 'CropLine', onClick: fn() },
143
+ ],
144
+ // the reference toggle, styled to the same custom1 accent as the send
145
+ footerActions: (
146
+ <ReqoreButton
147
+ icon='LinksLine'
148
+ minimal
149
+ flat
150
+ badge={1}
151
+ customTheme={{ main: 'custom1' }}
152
+ tooltip='Reference interfaces'
153
+ />
154
+ ),
155
+ // references on top of the editor (inside the bar), tinted to the accent — no
156
+ // "References" label, the chips read as the referenced interfaces on their own
157
+ aboveInput: (
158
+ <InterfaceReferenceTags
159
+ references={[{ interface_kind: 'connection', interface_name: 'sftp-partner' }]}
160
+ customTheme={{ main: 'custom1' }}
161
+ />
162
+ ),
163
+ },
164
+ async play({ canvasElement }) {
165
+ const canvas = within(canvasElement);
166
+ // rich editor renders a Slate contenteditable (not a <textarea>) …
167
+ await expect(canvasElement.querySelector('[contenteditable="true"]')).not.toBeNull();
168
+ await expect(canvasElement.querySelector('textarea')).toBeNull();
169
+ // … the staff split-send caret is present …
170
+ await expect(canvasElement.querySelector('.ticket-send-more')).not.toBeNull();
171
+ // … and the reference chip renders on top (no "References" label).
172
+ await expect(canvas.getByText('sftp-partner')).toBeInTheDocument();
173
+ await expect(canvas.queryByText('References')).not.toBeInTheDocument();
174
+ },
175
+ };
176
+
177
+ /**
178
+ * Every referenceable interface kind on one message, so the per-kind icons +
179
+ * accent chip styling can be reviewed together: workflow, service, job, fsm,
180
+ * connection, mapper, class, value-map, qog, ai-collection, ai-endpoint,
181
+ * ai-guardrail. (`qog` has no built-in icon → the generic fallback.)
182
+ */
183
+ export const AllReferenceTypes: Story = {
184
+ parameters: {
185
+ docs: {
186
+ description: {
187
+ story:
188
+ 'Renders a reply carrying every referenceable interface kind at once, so the per-kind icons and accent chip styling can be reviewed together (qog falls back to the generic glyph).',
189
+ },
190
+ },
191
+ },
192
+ decorators: [
193
+ (Story) => (
194
+ <ReqoreUIProvider theme={{ main: '#121212', intents: { custom1: '#762f7e' } }}>
195
+ <div style={{ padding: 20, background: '#121212' }}>
196
+ <Story />
197
+ </div>
198
+ </ReqoreUIProvider>
199
+ ),
200
+ ],
201
+ args: {
202
+ defaultText: 'This one references every interface kind.',
203
+ aboveInput: (
204
+ <InterfaceReferenceTags
205
+ customTheme={{ main: 'custom1' }}
206
+ references={[
207
+ { interface_kind: 'workflow', interface_name: 'order-sync:1.2' },
208
+ { interface_kind: 'service', interface_name: 'notifier' },
209
+ { interface_kind: 'job', interface_name: 'nightly-recon' },
210
+ { interface_kind: 'fsm', interface_name: 'onboarding' },
211
+ { interface_kind: 'connection', interface_name: 'sftp-partner' },
212
+ { interface_kind: 'mapper', interface_name: 'csv-to-order' },
213
+ { interface_kind: 'class', interface_name: 'OrderUtils' },
214
+ { interface_kind: 'value-map', interface_name: 'country-codes' },
215
+ { interface_kind: 'qog', interface_name: 'daily-report' },
216
+ { interface_kind: 'ai-collection', interface_name: 'kb-support' },
217
+ { interface_kind: 'ai-endpoint', interface_name: 'gpt-router' },
218
+ { interface_kind: 'ai-guardrail', interface_name: 'pii-filter' },
219
+ ]}
220
+ />
221
+ ),
222
+ },
223
+ async play({ canvasElement }) {
224
+ const canvas = within(canvasElement);
225
+ await expect(canvas.getByText('workflow')).toBeInTheDocument();
226
+ await expect(canvas.getByText('ai-guardrail')).toBeInTheDocument();
227
+ },
228
+ };
229
+
230
+ // Stand-in app logos (a coloured rounded square + initial) as data-URIs, so the
231
+ // story needs no network. Real logos come from the app catalogue (`app.logo`).
232
+ const appLogo = (hex: string, letter: string) =>
233
+ `data:image/svg+xml,${encodeURIComponent(
234
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect width="24" height="24" rx="6" fill="${hex}"/><text x="12" y="17" font-size="13" font-family="sans-serif" font-weight="bold" fill="#fff" text-anchor="middle">${letter}</text></svg>`
235
+ )}`;
236
+ const APP_LOGOS: Record<string, string> = {
237
+ Telegram: appLogo('#2AABEE', 'T'),
238
+ Stripe: appLogo('#635BFF', 'S'),
239
+ };
240
+
241
+ /**
242
+ * Faithful qog icons — a qog referenced by its trigger app shows that app's logo,
243
+ * exactly like the qogs list. The customer's IDE resolves it live from the
244
+ * reference's `trigger_app` via `resolveInterfaceImage` (it has the app catalogue);
245
+ * a stored `logo` travels to viewers that don't (staff triage, the Qonsole card).
246
+ * A qog with no trigger app falls back to the qog glyph.
247
+ */
248
+ export const QogTriggerAppLogo: Story = {
249
+ parameters: {
250
+ docs: {
251
+ description: {
252
+ story:
253
+ "Renders qogs referenced by their trigger apps, each showing that app's logo — resolved live via resolveInterfaceImage or from a stored logo — while a qog with no trigger app falls back to the qog glyph.",
254
+ },
255
+ },
256
+ },
257
+ decorators: [
258
+ (Story) => (
259
+ <ReqoreUIProvider theme={{ main: '#121212', intents: { custom1: '#762f7e' } }}>
260
+ <div style={{ padding: 20, background: '#121212' }}>
261
+ <Story />
262
+ </div>
263
+ </ReqoreUIProvider>
264
+ ),
265
+ ],
266
+ args: {
267
+ defaultText: 'These qogs are referenced by their trigger apps.',
268
+ aboveInput: (
269
+ <InterfaceReferenceTags
270
+ customTheme={{ main: 'custom1' }}
271
+ references={[
272
+ // resolved live from trigger_app (the customer/IDE path)
273
+ { interface_kind: 'qog', interface_name: 'telegram-intake', trigger_app: 'Telegram' },
274
+ { interface_kind: 'qog', interface_name: 'stripe-billing', trigger_app: 'Stripe' },
275
+ // stored logo travels to viewers without the app catalogue (staff / Qonsole)
276
+ { interface_kind: 'qog', interface_name: 'slack-alerts', logo: appLogo('#4A154B', 'S') },
277
+ // no trigger app → the qog glyph fallback
278
+ { interface_kind: 'qog', interface_name: 'manual-recon' },
279
+ ]}
280
+ resolveInterfaceImage={(ref) => (ref.trigger_app ? APP_LOGOS[ref.trigger_app] : undefined)}
281
+ />
282
+ ),
283
+ },
284
+ async play({ canvasElement }) {
285
+ const canvas = within(canvasElement);
286
+ await expect(canvas.getByText('telegram-intake')).toBeInTheDocument();
287
+ // the trigger-app / stored-logo qogs render their app logo image
288
+ await expect(canvasElement.innerHTML).toContain('data:image');
289
+ },
290
+ };
291
+
292
+ // A stand-in "screenshot" as an SVG File so the story needs no real capture — the
293
+ // composer's attachment strip renders any image File as a thumbnail (the real IDE
294
+ // stages a PNG from captureScreenshot / captureRegion the same way).
295
+ const screenshotFile = () => {
296
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="260" height="150" viewBox="0 0 260 150">
297
+ <rect width="260" height="150" rx="8" fill="#0f0b16"/>
298
+ <rect width="260" height="26" fill="#1c1428"/>
299
+ <circle cx="16" cy="13" r="4" fill="#ff5f57"/><circle cx="32" cy="13" r="4" fill="#febc2e"/><circle cx="48" cy="13" r="4" fill="#28c840"/>
300
+ <rect x="16" y="44" width="110" height="12" rx="3" fill="#8e39a0"/>
301
+ <rect x="16" y="68" width="228" height="9" rx="3" fill="#2c2440"/>
302
+ <rect x="16" y="86" width="200" height="9" rx="3" fill="#2c2440"/>
303
+ <rect x="16" y="104" width="170" height="9" rx="3" fill="#2c2440"/>
304
+ <rect x="16" y="122" width="92" height="9" rx="3" fill="#2c2440"/>
305
+ </svg>`;
306
+ return new File([svg], 'region-capture.svg', { type: 'image/svg+xml' });
307
+ };
308
+
309
+ /**
310
+ * A composed reply with both a staged screenshot (the attachment strip renders any
311
+ * image File as a thumbnail — the real IDE stages a PNG from Take-screenshot /
312
+ * Capture-area) and interface references on top.
313
+ */
314
+ export const WithScreenshotAndReferences: Story = {
315
+ parameters: {
316
+ docs: {
317
+ description: {
318
+ story:
319
+ 'Renders a composed reply carrying both a staged screenshot thumbnail in the attachment strip and interface references above the input.',
320
+ },
321
+ },
322
+ },
323
+ decorators: [
324
+ (Story) => (
325
+ <ReqoreUIProvider theme={{ main: '#121212', intents: { custom1: '#762f7e' } }}>
326
+ <div style={{ padding: 20, background: '#121212' }}>
327
+ <Story />
328
+ </div>
329
+ </ReqoreUIProvider>
330
+ ),
331
+ ],
332
+ args: {
333
+ defaultText: "Here's the timeout I'm seeing on the nightly run — screenshot attached.",
334
+ defaultFiles: [screenshotFile()],
335
+ aboveInput: (
336
+ <InterfaceReferenceTags
337
+ customTheme={{ main: 'custom1' }}
338
+ references={[
339
+ { interface_kind: 'connection', interface_name: 'sftp-partner' },
340
+ { interface_kind: 'qog', interface_name: 'telegram-intake', logo: appLogo('#2AABEE', 'T') },
341
+ ]}
342
+ />
343
+ ),
344
+ },
345
+ async play({ canvasElement }) {
346
+ const canvas = within(canvasElement);
347
+ // the staged screenshot thumbnail (an <img>) and the references both render
348
+ await expect(canvasElement.querySelector('img')).not.toBeNull();
349
+ await expect(canvas.getByText('sftp-partner')).toBeInTheDocument();
350
+ },
351
+ };
@@ -0,0 +1,146 @@
1
+ import { ReqoreDropdown } from '@qoretechnologies/reqore';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import { Composer, IComposerSendAction, TComposerEditor } from '../composer/Composer';
4
+ import { fileToAttachment as defaultFileToAttachment } from './fileToAttachment';
5
+ import { IAttachmentUpload } from './meta';
6
+
7
+ /** The exact `items` shape ReqoreDropdown accepts — no import-path guessing. */
8
+ type TAttachMenuItems = NonNullable<ComponentProps<typeof ReqoreDropdown>['items']>;
9
+
10
+ export interface ITicketReplyBoxProps {
11
+ /** Send the composed message. `internal` is only ever true when
12
+ * `allowInternalNote` is set (the staff surface). */
13
+ onSend: (
14
+ body: string,
15
+ options: { internal: boolean; attachments?: IAttachmentUpload[] }
16
+ ) => void | Promise<void>;
17
+ /** File → base64 upload conversion; defaults to the shared `fileToAttachment`. */
18
+ fileToAttachment?: (file: File) => Promise<IAttachmentUpload>;
19
+ /** the send round-trip is in flight */
20
+ sending?: boolean;
21
+ /** the ticket can't be replied to (e.g. closed) — renders a notice instead */
22
+ disabled?: boolean;
23
+ disabledReason?: string;
24
+ /** placeholder text. (A function is called with `false` — the mode is chosen at
25
+ * send time, so there is no live internal-note mode.) */
26
+ placeholder?: string | ((internal: boolean) => string);
27
+ /** send labels; a function is called with `false` for the primary "Send reply"
28
+ * and `true` for the "Add internal note" split-menu item. Defaults to
29
+ * "Send reply" / "Add internal note". */
30
+ sendLabel?: string | ((internal: boolean) => string);
31
+ /** Staff surface: split the send button so it also offers "Add internal note"
32
+ * (customer composers omit it and just send a reply). */
33
+ allowInternalNote?: boolean;
34
+ /** Extra attach-menu entries beyond "Upload files" — e.g. the IDE's screenshot /
35
+ * region capture. Receives the composer's `addFiles`. With any entry the attach
36
+ * control becomes a dropdown; otherwise it's a plain button. */
37
+ attachMenuItems?: (addFiles: (files: File[]) => void) => TAttachMenuItems;
38
+ /** Extra footer controls left of the send button — e.g. the IDE's
39
+ * reference-interfaces toggle. */
40
+ footerActions?: ReactNode;
41
+ /** Rendered on top of the editor, inside the bar — e.g. reference chips. */
42
+ aboveInput?: ReactNode;
43
+ /** Rendered below the editor — e.g. the IDE's interface-reference picker. */
44
+ belowInput?: ReactNode;
45
+ /** Editor flavour. Helpdesk uses the rich, Qonsole-style editor by default; pass
46
+ * `plain` for a simple textarea (e.g. deterministic play tests). */
47
+ editor?: TComposerEditor;
48
+ /** Initial draft text to seed the editor with (e.g. a restored draft). */
49
+ defaultText?: string;
50
+ /** Initial staged files (e.g. a restored draft's attachments, or a demo). */
51
+ defaultFiles?: File[];
52
+ }
53
+
54
+ /**
55
+ * The shared ticket reply composer — now a thin adapter over the universal
56
+ * `<Composer>` (the input extracted from qorus-ide's Qonsole chat). It maps the
57
+ * ticket vocabulary onto the composer: the staff `allowInternalNote` becomes a
58
+ * split send (primary "Send reply" + a caret "Add internal note", mode chosen at
59
+ * send time), and staged files convert to `IAttachmentUpload[]` via
60
+ * `fileToAttachment` before `onSend`. App-specific affordances still arrive
61
+ * through slots (`attachMenuItems`, `footerActions`, `belowInput`), so the
62
+ * IDE-only bits (screenshot capture, the reference picker) stay in qorus-ide. A
63
+ * closed ticket renders a muted notice.
64
+ */
65
+ export const TicketReplyBox = ({
66
+ onSend,
67
+ fileToAttachment = defaultFileToAttachment,
68
+ sending,
69
+ disabled,
70
+ disabledReason = 'This ticket is closed. Open a new ticket to continue the conversation.',
71
+ placeholder = 'Write a reply…',
72
+ sendLabel,
73
+ allowInternalNote,
74
+ attachMenuItems,
75
+ footerActions,
76
+ aboveInput,
77
+ belowInput,
78
+ editor = 'rich',
79
+ defaultText,
80
+ defaultFiles,
81
+ }: ITicketReplyBoxProps) => {
82
+ const resolvedPlaceholder =
83
+ typeof placeholder === 'function' ? placeholder(false) : placeholder;
84
+ // Label for a given send mode: `false` = public reply, `true` = internal note.
85
+ const labelFor = (note: boolean): string =>
86
+ sendLabel !== undefined
87
+ ? typeof sendLabel === 'function'
88
+ ? sendLabel(note)
89
+ : sendLabel
90
+ : note
91
+ ? 'Add internal note'
92
+ : 'Send reply';
93
+
94
+ // Staff surface splits the send button; customer surface is a single "Send reply".
95
+ // Both use the Qonsole-style minimal `custom1` accent (the Composer default); the
96
+ // internal note stays amber (`warning`) so it can't be mistaken for a public reply.
97
+ const sendActions: IComposerSendAction[] | undefined = allowInternalNote
98
+ ? [
99
+ {
100
+ id: 'reply',
101
+ label: labelFor(false),
102
+ icon: 'SendPlane2Line',
103
+ minimal: true,
104
+ customTheme: { main: 'custom1' },
105
+ },
106
+ {
107
+ id: 'internal',
108
+ label: labelFor(true),
109
+ icon: 'StickyNoteLine',
110
+ minimal: true,
111
+ intent: 'warning',
112
+ },
113
+ ]
114
+ : undefined;
115
+
116
+ const handleSend = async (
117
+ body: string,
118
+ { files, action }: { files: File[]; action?: string }
119
+ ): Promise<void> => {
120
+ const internal = action === 'internal';
121
+ const attachments = files.length
122
+ ? await Promise.all(files.map(fileToAttachment))
123
+ : undefined;
124
+ await onSend(body, { internal, attachments });
125
+ };
126
+
127
+ return (
128
+ <Composer
129
+ editor={editor}
130
+ defaultText={defaultText}
131
+ defaultFiles={defaultFiles}
132
+ placeholder={resolvedPlaceholder}
133
+ sending={sending}
134
+ disabled={disabled}
135
+ disabledReason={disabledReason}
136
+ onSend={handleSend}
137
+ sendLabel={labelFor(false)}
138
+ sendActions={sendActions}
139
+ sendMenuClassName='ticket-send-more'
140
+ attachMenuItems={attachMenuItems}
141
+ footerActions={footerActions}
142
+ aboveInput={aboveInput}
143
+ belowInput={belowInput}
144
+ />
145
+ );
146
+ };
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Authed attachment byte-fetching, shared by every ticket surface.
3
+ *
4
+ * Attachment bytes can't go through the JSON fetch helpers, so each app grew its
5
+ * own raw-`fetch` copy: qorus-ide in `views/support/api.ts`, admin-portal in
6
+ * `pages/SupportTickets/helpers.ts`. The two were the same function down to the
7
+ * error text ("Could not download the attachment") and the anchor-click dance —
8
+ * they differed only in how the URL is built, which auth header is sent, and
9
+ * which Error subclass is thrown.
10
+ *
11
+ * Those three differences are the parameters below. Everything else — the
12
+ * non-OK check, `URL.createObjectURL`, the temporary anchor, revoking the object
13
+ * URL — lives here once.
14
+ */
15
+
16
+ export interface ITicketAttachmentAccessConfig {
17
+ /** Absolute URL for one attachment's bytes. */
18
+ attachmentUrl: (ticketId: string, attachmentId: string) => string;
19
+ /**
20
+ * Headers for the byte request — typically auth. A function rather than a
21
+ * value because tokens are resolved per request, not at wire-up time.
22
+ */
23
+ headers?: () => Record<string, string>;
24
+ /**
25
+ * Error to throw on a non-OK response. Defaults to a plain `Error`; apps with
26
+ * their own API error type (carrying the status) pass a factory.
27
+ */
28
+ onError?: (message: string, status: number) => Error;
29
+ }
30
+
31
+ export interface ITicketAttachmentAccess {
32
+ /** Raw bytes. `failure` is the message used if the response isn't OK. */
33
+ fetchBlob: (ticketId: string, attachmentId: string, failure?: string) => Promise<Blob>;
34
+ /**
35
+ * An object URL for the bytes — for inline thumbnails and the lightbox.
36
+ *
37
+ * The caller owns the returned URL and must `URL.revokeObjectURL` it when the
38
+ * element goes away; this cannot do it for them without breaking the img.
39
+ */
40
+ fetchBlobUrl: (ticketId: string, attachmentId: string) => Promise<string>;
41
+ /** Save the attachment to disk under its original filename. */
42
+ download: (ticketId: string, attachmentId: string, filename: string) => Promise<void>;
43
+ }
44
+
45
+ const DEFAULT_DOWNLOAD_FAILURE = 'Could not download the attachment';
46
+ const DEFAULT_LOAD_FAILURE = 'Could not load the attachment';
47
+
48
+ /**
49
+ * Save a blob to disk under `filename`, via a temporary anchor.
50
+ *
51
+ * Exported because it is the half of `download` that has nothing to do with
52
+ * tickets — a surface that already holds the bytes shouldn't have to re-fetch
53
+ * them just to reuse the save behaviour.
54
+ */
55
+ export const saveBlobAs = (blob: Blob, filename: string): void => {
56
+ const url = URL.createObjectURL(blob);
57
+ const anchor = document.createElement('a');
58
+
59
+ anchor.href = url;
60
+ anchor.download = filename;
61
+ document.body.appendChild(anchor);
62
+ anchor.click();
63
+ anchor.remove();
64
+ // Safari needs the URL alive until the click is processed; a task boundary is
65
+ // enough and avoids leaking the blob for the life of the document.
66
+ setTimeout(() => URL.revokeObjectURL(url), 0);
67
+ };
68
+
69
+ export const createTicketAttachmentAccess = ({
70
+ attachmentUrl,
71
+ headers,
72
+ onError,
73
+ }: ITicketAttachmentAccessConfig): ITicketAttachmentAccess => {
74
+ const fetchBlob = async (
75
+ ticketId: string,
76
+ attachmentId: string,
77
+ failure: string = DEFAULT_LOAD_FAILURE
78
+ ): Promise<Blob> => {
79
+ const response = await fetch(attachmentUrl(ticketId, attachmentId), {
80
+ headers: headers?.() ?? {},
81
+ });
82
+
83
+ if (!response.ok) {
84
+ throw onError ? onError(failure, response.status) : new Error(failure);
85
+ }
86
+
87
+ return response.blob();
88
+ };
89
+
90
+ return {
91
+ fetchBlob,
92
+ fetchBlobUrl: async (ticketId, attachmentId) =>
93
+ URL.createObjectURL(await fetchBlob(ticketId, attachmentId, DEFAULT_LOAD_FAILURE)),
94
+ download: async (ticketId, attachmentId, filename) =>
95
+ saveBlobAs(await fetchBlob(ticketId, attachmentId, DEFAULT_DOWNLOAD_FAILURE), filename),
96
+ };
97
+ };
@@ -0,0 +1,24 @@
1
+ import { IAttachmentUpload } from './meta';
2
+
3
+ /**
4
+ * Read a picked `File` into the inline base64 upload shape the support API expects
5
+ * (the SaaS plane accepts attachments as base64 on the create/reply payload, with
6
+ * no separate multipart upload). Shared by every composer so the customer and
7
+ * staff surfaces encode files identically.
8
+ */
9
+ export const fileToAttachment = (file: File): Promise<IAttachmentUpload> =>
10
+ new Promise((resolve, reject) => {
11
+ const reader = new FileReader();
12
+ reader.onerror = () => reject(new Error(`Could not read ${file.name}`));
13
+ reader.onload = () => {
14
+ // reader.result is a data URL: "data:<type>;base64,<content>"
15
+ const result = String(reader.result);
16
+ const content = result.slice(result.indexOf(',') + 1);
17
+ resolve({
18
+ filename: file.name,
19
+ content_type: file.type || 'application/octet-stream',
20
+ content,
21
+ });
22
+ };
23
+ reader.readAsDataURL(file);
24
+ });
@@ -0,0 +1,10 @@
1
+ export * from './meta';
2
+ export * from './ticketModel';
3
+ export * from './attachmentAccess';
4
+ export * from './AttachmentChips';
5
+ export * from './TicketMetaTags';
6
+ export * from './TicketHeader';
7
+ export * from './InterfaceReferenceTags';
8
+ export * from './ReferencePicker';
9
+ export * from './fileToAttachment';
10
+ export * from './TicketReplyBox';