@open-mercato/core 0.10.1-develop.7717.1.2befe9c634 → 0.10.1-develop.7721.1.b5c4a00a68

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 (384) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/staff_support_routing_rule/index.js +21 -0
  3. package/dist/generated/entities/staff_support_routing_rule/index.js.map +7 -0
  4. package/dist/generated/entities/staff_support_ticket/index.js +37 -0
  5. package/dist/generated/entities/staff_support_ticket/index.js.map +7 -0
  6. package/dist/generated/entities/staff_time_project/index.js +2 -0
  7. package/dist/generated/entities/staff_time_project/index.js.map +2 -2
  8. package/dist/generated/entities/staff_time_project_member/index.js +2 -0
  9. package/dist/generated/entities/staff_time_project_member/index.js.map +2 -2
  10. package/dist/generated/entities/staff_time_task/index.js +4 -0
  11. package/dist/generated/entities/staff_time_task/index.js.map +2 -2
  12. package/dist/generated/entities/staff_time_task_comment/index.js +9 -1
  13. package/dist/generated/entities/staff_time_task_comment/index.js.map +2 -2
  14. package/dist/generated/entities.ids.generated.js +2 -0
  15. package/dist/generated/entities.ids.generated.js.map +2 -2
  16. package/dist/generated/entity-fields-registry.js +38 -0
  17. package/dist/generated/entity-fields-registry.js.map +2 -2
  18. package/dist/helpers/integration/auth.js +1 -0
  19. package/dist/helpers/integration/auth.js.map +2 -2
  20. package/dist/helpers/integration/communicationChannelsFixtures.js +20 -0
  21. package/dist/helpers/integration/communicationChannelsFixtures.js.map +2 -2
  22. package/dist/modules/catalog/api/bulk-delete/route.js +12 -2
  23. package/dist/modules/catalog/api/bulk-delete/route.js.map +2 -2
  24. package/dist/modules/communication_channels/api/post/test-seed/route.js +17 -3
  25. package/dist/modules/communication_channels/api/post/test-seed/route.js.map +2 -2
  26. package/dist/modules/communication_channels/lib/test-seed.js +38 -5
  27. package/dist/modules/communication_channels/lib/test-seed.js.map +2 -2
  28. package/dist/modules/messages/commands/messages.js +2 -3
  29. package/dist/modules/messages/commands/messages.js.map +2 -2
  30. package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js +2 -2
  31. package/dist/modules/portal/frontend/[orgSlug]/portal/dashboard/page.js.map +2 -2
  32. package/dist/modules/staff/api/portal/support-tickets/[id]/attachments/route.js +299 -0
  33. package/dist/modules/staff/api/portal/support-tickets/[id]/attachments/route.js.map +7 -0
  34. package/dist/modules/staff/api/portal/support-tickets/[id]/messages/route.js +91 -0
  35. package/dist/modules/staff/api/portal/support-tickets/[id]/messages/route.js.map +7 -0
  36. package/dist/modules/staff/api/portal/support-tickets/[id]/route.js +146 -0
  37. package/dist/modules/staff/api/portal/support-tickets/[id]/route.js.map +7 -0
  38. package/dist/modules/staff/api/portal/support-tickets/options/route.js +60 -0
  39. package/dist/modules/staff/api/portal/support-tickets/options/route.js.map +7 -0
  40. package/dist/modules/staff/api/portal/support-tickets/route.js +220 -0
  41. package/dist/modules/staff/api/portal/support-tickets/route.js.map +7 -0
  42. package/dist/modules/staff/api/timesheets/settings/route.js +7 -1
  43. package/dist/modules/staff/api/timesheets/settings/route.js.map +2 -2
  44. package/dist/modules/staff/api/timesheets/support-routing-rules/fallback-project/route.js +122 -0
  45. package/dist/modules/staff/api/timesheets/support-routing-rules/fallback-project/route.js.map +7 -0
  46. package/dist/modules/staff/api/timesheets/support-routing-rules/preview/route.js +180 -0
  47. package/dist/modules/staff/api/timesheets/support-routing-rules/preview/route.js.map +7 -0
  48. package/dist/modules/staff/api/timesheets/support-routing-rules/route.js +147 -0
  49. package/dist/modules/staff/api/timesheets/support-routing-rules/route.js.map +7 -0
  50. package/dist/modules/staff/api/timesheets/support-tickets/options/route.js +133 -0
  51. package/dist/modules/staff/api/timesheets/support-tickets/options/route.js.map +7 -0
  52. package/dist/modules/staff/api/timesheets/tasks/[id]/claim/route.js +33 -0
  53. package/dist/modules/staff/api/timesheets/tasks/[id]/claim/route.js.map +7 -0
  54. package/dist/modules/staff/api/timesheets/tasks/[id]/comments/route.js +25 -7
  55. package/dist/modules/staff/api/timesheets/tasks/[id]/comments/route.js.map +2 -2
  56. package/dist/modules/staff/api/timesheets/tasks/[id]/release/route.js +32 -0
  57. package/dist/modules/staff/api/timesheets/tasks/[id]/release/route.js.map +7 -0
  58. package/dist/modules/staff/api/timesheets/tasks/route.js +94 -47
  59. package/dist/modules/staff/api/timesheets/tasks/route.js.map +2 -2
  60. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +3 -0
  61. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +2 -2
  62. package/dist/modules/staff/api/timesheets/time-projects/route.js +3 -0
  63. package/dist/modules/staff/api/timesheets/time-projects/route.js.map +2 -2
  64. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.js +1 -0
  65. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.js.map +2 -2
  66. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.js +54 -4
  67. package/dist/modules/staff/backend/staff/time-tracking/projects/[id]/page.js.map +2 -2
  68. package/dist/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.js +21 -5
  69. package/dist/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.js.map +2 -2
  70. package/dist/modules/staff/backend/staff/time-tracking/settings/page.js +319 -254
  71. package/dist/modules/staff/backend/staff/time-tracking/settings/page.js.map +2 -2
  72. package/dist/modules/staff/backend/staff/time-tracking/support/page.js +363 -0
  73. package/dist/modules/staff/backend/staff/time-tracking/support/page.js.map +7 -0
  74. package/dist/modules/staff/backend/staff/time-tracking/support/page.meta.js +18 -0
  75. package/dist/modules/staff/backend/staff/time-tracking/support/page.meta.js.map +7 -0
  76. package/dist/modules/staff/cli.js +27 -0
  77. package/dist/modules/staff/cli.js.map +2 -2
  78. package/dist/modules/staff/commands/index.js +3 -0
  79. package/dist/modules/staff/commands/index.js.map +2 -2
  80. package/dist/modules/staff/commands/shared.js +10 -1
  81. package/dist/modules/staff/commands/shared.js.map +2 -2
  82. package/dist/modules/staff/commands/support-routing-rules.js +505 -0
  83. package/dist/modules/staff/commands/support-routing-rules.js.map +7 -0
  84. package/dist/modules/staff/commands/support-tickets.js +513 -0
  85. package/dist/modules/staff/commands/support-tickets.js.map +7 -0
  86. package/dist/modules/staff/commands/timesheets-projects.js +72 -14
  87. package/dist/modules/staff/commands/timesheets-projects.js.map +2 -2
  88. package/dist/modules/staff/commands/timesheets-task-assignment.js +270 -0
  89. package/dist/modules/staff/commands/timesheets-task-assignment.js.map +7 -0
  90. package/dist/modules/staff/commands/timesheets-task-comments.js +58 -12
  91. package/dist/modules/staff/commands/timesheets-task-comments.js.map +2 -2
  92. package/dist/modules/staff/commands/timesheets-tasks.js +91 -9
  93. package/dist/modules/staff/commands/timesheets-tasks.js.map +3 -3
  94. package/dist/modules/staff/data/enrichers.js +141 -0
  95. package/dist/modules/staff/data/enrichers.js.map +2 -2
  96. package/dist/modules/staff/data/entities.js +143 -2
  97. package/dist/modules/staff/data/entities.js.map +2 -2
  98. package/dist/modules/staff/data/extensions.js +8 -0
  99. package/dist/modules/staff/data/extensions.js.map +2 -2
  100. package/dist/modules/staff/data/validators.js +34 -5
  101. package/dist/modules/staff/data/validators.js.map +2 -2
  102. package/dist/modules/staff/encryption.js +6 -0
  103. package/dist/modules/staff/encryption.js.map +2 -2
  104. package/dist/modules/staff/events.js +25 -0
  105. package/dist/modules/staff/events.js.map +2 -2
  106. package/dist/modules/staff/events.payloads.js +54 -0
  107. package/dist/modules/staff/events.payloads.js.map +2 -2
  108. package/dist/modules/staff/extension-points.js +1 -0
  109. package/dist/modules/staff/extension-points.js.map +2 -2
  110. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.js +468 -0
  111. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.js.map +7 -0
  112. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.meta.js +12 -0
  113. package/dist/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.meta.js.map +7 -0
  114. package/dist/modules/staff/frontend/[orgSlug]/portal/support/new/page.js +316 -0
  115. package/dist/modules/staff/frontend/[orgSlug]/portal/support/new/page.js.map +7 -0
  116. package/dist/modules/staff/frontend/[orgSlug]/portal/support/new/page.meta.js +12 -0
  117. package/dist/modules/staff/frontend/[orgSlug]/portal/support/new/page.meta.js.map +7 -0
  118. package/dist/modules/staff/frontend/[orgSlug]/portal/support/page.js +190 -0
  119. package/dist/modules/staff/frontend/[orgSlug]/portal/support/page.js.map +7 -0
  120. package/dist/modules/staff/frontend/[orgSlug]/portal/support/page.meta.js +19 -0
  121. package/dist/modules/staff/frontend/[orgSlug]/portal/support/page.meta.js.map +7 -0
  122. package/dist/modules/staff/index.js +1 -1
  123. package/dist/modules/staff/index.js.map +2 -2
  124. package/dist/modules/staff/lib/crud.js +2 -0
  125. package/dist/modules/staff/lib/crud.js.map +2 -2
  126. package/dist/modules/staff/lib/support/attachments.js +36 -0
  127. package/dist/modules/staff/lib/support/attachments.js.map +7 -0
  128. package/dist/modules/staff/lib/support/dictionaries.js +87 -0
  129. package/dist/modules/staff/lib/support/dictionaries.js.map +7 -0
  130. package/dist/modules/staff/lib/support/notifications.js +111 -0
  131. package/dist/modules/staff/lib/support/notifications.js.map +7 -0
  132. package/dist/modules/staff/lib/support/portalAttachments.js +100 -0
  133. package/dist/modules/staff/lib/support/portalAttachments.js.map +7 -0
  134. package/dist/modules/staff/lib/support/portalBroadcast.js +117 -0
  135. package/dist/modules/staff/lib/support/portalBroadcast.js.map +7 -0
  136. package/dist/modules/staff/lib/support/portalRoute.js +99 -0
  137. package/dist/modules/staff/lib/support/portalRoute.js.map +7 -0
  138. package/dist/modules/staff/lib/support/portalStatus.js +12 -0
  139. package/dist/modules/staff/lib/support/portalStatus.js.map +7 -0
  140. package/dist/modules/staff/lib/support/portalTickets.js +148 -0
  141. package/dist/modules/staff/lib/support/portalTickets.js.map +7 -0
  142. package/dist/modules/staff/lib/support/routing.js +81 -0
  143. package/dist/modules/staff/lib/support/routing.js.map +7 -0
  144. package/dist/modules/staff/lib/support/routingRuleDraft.js +25 -0
  145. package/dist/modules/staff/lib/support/routingRuleDraft.js.map +7 -0
  146. package/dist/modules/staff/lib/support/seedDefaults.js +114 -0
  147. package/dist/modules/staff/lib/support/seedDefaults.js.map +7 -0
  148. package/dist/modules/staff/lib/support/supportActivity.js +26 -0
  149. package/dist/modules/staff/lib/support/supportActivity.js.map +7 -0
  150. package/dist/modules/staff/lib/support-ui/PortalSupportNotLinked.js +23 -0
  151. package/dist/modules/staff/lib/support-ui/PortalSupportNotLinked.js.map +7 -0
  152. package/dist/modules/staff/lib/support-ui/portalAttachmentValidation.js +112 -0
  153. package/dist/modules/staff/lib/support-ui/portalAttachmentValidation.js.map +7 -0
  154. package/dist/modules/staff/lib/support-ui/portalPendingUploads.js +45 -0
  155. package/dist/modules/staff/lib/support-ui/portalPendingUploads.js.map +7 -0
  156. package/dist/modules/staff/lib/support-ui/portalSupport.js +51 -0
  157. package/dist/modules/staff/lib/support-ui/portalSupport.js.map +7 -0
  158. package/dist/modules/staff/lib/time-tracking/access.js +3 -39
  159. package/dist/modules/staff/lib/time-tracking/access.js.map +2 -2
  160. package/dist/modules/staff/lib/time-tracking/listProjectAccess.js +54 -0
  161. package/dist/modules/staff/lib/time-tracking/listProjectAccess.js.map +7 -0
  162. package/dist/modules/staff/lib/time-tracking/portalRecipients.js +92 -2
  163. package/dist/modules/staff/lib/time-tracking/portalRecipients.js.map +2 -2
  164. package/dist/modules/staff/lib/time-tracking/projectAssignment.js +112 -0
  165. package/dist/modules/staff/lib/time-tracking/projectAssignment.js.map +7 -0
  166. package/dist/modules/staff/lib/time-tracking/settingKeys.js +14 -0
  167. package/dist/modules/staff/lib/time-tracking/settingKeys.js.map +2 -2
  168. package/dist/modules/staff/lib/time-tracking/settings.js +28 -1
  169. package/dist/modules/staff/lib/time-tracking/settings.js.map +2 -2
  170. package/dist/modules/staff/lib/time-tracking/taskAssignmentRoute.js +143 -0
  171. package/dist/modules/staff/lib/time-tracking/taskAssignmentRoute.js.map +7 -0
  172. package/dist/modules/staff/lib/time-tracking/workRecipients.js +92 -0
  173. package/dist/modules/staff/lib/time-tracking/workRecipients.js.map +7 -0
  174. package/dist/modules/staff/lib/time-tracking-ui/BoardFilterChips.js +32 -3
  175. package/dist/modules/staff/lib/time-tracking-ui/BoardFilterChips.js.map +2 -2
  176. package/dist/modules/staff/lib/time-tracking-ui/KanbanBoard.js +29 -0
  177. package/dist/modules/staff/lib/time-tracking-ui/KanbanBoard.js.map +2 -2
  178. package/dist/modules/staff/lib/time-tracking-ui/KanbanCard.js +4 -0
  179. package/dist/modules/staff/lib/time-tracking-ui/KanbanCard.js.map +2 -2
  180. package/dist/modules/staff/lib/time-tracking-ui/ProjectFormSections.js +141 -1
  181. package/dist/modules/staff/lib/time-tracking-ui/ProjectFormSections.js.map +2 -2
  182. package/dist/modules/staff/lib/time-tracking-ui/SupportAttachmentsSection.js +153 -0
  183. package/dist/modules/staff/lib/time-tracking-ui/SupportAttachmentsSection.js.map +7 -0
  184. package/dist/modules/staff/lib/time-tracking-ui/SupportRequestPanel.js +67 -0
  185. package/dist/modules/staff/lib/time-tracking-ui/SupportRequestPanel.js.map +7 -0
  186. package/dist/modules/staff/lib/time-tracking-ui/TaskBoardScreen.js +3 -1
  187. package/dist/modules/staff/lib/time-tracking-ui/TaskBoardScreen.js.map +2 -2
  188. package/dist/modules/staff/lib/time-tracking-ui/TaskCommentThread.js +80 -17
  189. package/dist/modules/staff/lib/time-tracking-ui/TaskCommentThread.js.map +2 -2
  190. package/dist/modules/staff/lib/time-tracking-ui/TaskDrawer.js +230 -41
  191. package/dist/modules/staff/lib/time-tracking-ui/TaskDrawer.js.map +2 -2
  192. package/dist/modules/staff/lib/time-tracking-ui/boardDirectory.js +21 -1
  193. package/dist/modules/staff/lib/time-tracking-ui/boardDirectory.js.map +2 -2
  194. package/dist/modules/staff/lib/time-tracking-ui/boardFilters.js +16 -4
  195. package/dist/modules/staff/lib/time-tracking-ui/boardFilters.js.map +2 -2
  196. package/dist/modules/staff/lib/time-tracking-ui/kanbanBoardData.js +3 -1
  197. package/dist/modules/staff/lib/time-tracking-ui/kanbanBoardData.js.map +2 -2
  198. package/dist/modules/staff/lib/time-tracking-ui/projectDefaultAssignee.js +68 -0
  199. package/dist/modules/staff/lib/time-tracking-ui/projectDefaultAssignee.js.map +7 -0
  200. package/dist/modules/staff/lib/time-tracking-ui/settingsTabs.js +7 -0
  201. package/dist/modules/staff/lib/time-tracking-ui/settingsTabs.js.map +7 -0
  202. package/dist/modules/staff/lib/time-tracking-ui/supportTicketData.js +50 -0
  203. package/dist/modules/staff/lib/time-tracking-ui/supportTicketData.js.map +7 -0
  204. package/dist/modules/staff/lib/time-tracking-ui/taskDrawerData.js +13 -1
  205. package/dist/modules/staff/lib/time-tracking-ui/taskDrawerData.js.map +2 -2
  206. package/dist/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.js +36 -2
  207. package/dist/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.js.map +2 -2
  208. package/dist/modules/staff/migrations/Migration20261009180543_staff.js +42 -0
  209. package/dist/modules/staff/migrations/Migration20261009180543_staff.js.map +7 -0
  210. package/dist/modules/staff/notifications.js +92 -0
  211. package/dist/modules/staff/notifications.js.map +2 -2
  212. package/dist/modules/staff/setup.js +6 -2
  213. package/dist/modules/staff/setup.js.map +2 -2
  214. package/dist/modules/staff/subscribers/support-portal-comment-created.js +26 -0
  215. package/dist/modules/staff/subscribers/support-portal-comment-created.js.map +7 -0
  216. package/dist/modules/staff/subscribers/support-portal-comment-deleted.js +26 -0
  217. package/dist/modules/staff/subscribers/support-portal-comment-deleted.js.map +7 -0
  218. package/dist/modules/staff/subscribers/support-portal-comment-updated.js +26 -0
  219. package/dist/modules/staff/subscribers/support-portal-comment-updated.js.map +7 -0
  220. package/dist/modules/staff/subscribers/support-portal-status-column-updated.js +24 -0
  221. package/dist/modules/staff/subscribers/support-portal-status-column-updated.js.map +7 -0
  222. package/dist/modules/staff/subscribers/support-portal-task-status-changed.js +25 -0
  223. package/dist/modules/staff/subscribers/support-portal-task-status-changed.js.map +7 -0
  224. package/dist/modules/staff/subscribers/support-portal-task-updated.js +25 -0
  225. package/dist/modules/staff/subscribers/support-portal-task-updated.js.map +7 -0
  226. package/dist/modules/staff/subscribers/support-ticket-created-notification.js +25 -0
  227. package/dist/modules/staff/subscribers/support-ticket-created-notification.js.map +7 -0
  228. package/dist/modules/staff/subscribers/support-ticket-customer-replied-notification.js +25 -0
  229. package/dist/modules/staff/subscribers/support-ticket-customer-replied-notification.js.map +7 -0
  230. package/dist/modules/staff/subscribers/support-ticket-unnotified-clear.js +26 -0
  231. package/dist/modules/staff/subscribers/support-ticket-unnotified-clear.js.map +7 -0
  232. package/dist/modules/staff/subscribers/time-task-assignee-notification.js +83 -0
  233. package/dist/modules/staff/subscribers/time-task-assignee-notification.js.map +7 -0
  234. package/dist/modules/staff/widgets/injection/portal-support-tickets/widget.client.js +112 -0
  235. package/dist/modules/staff/widgets/injection/portal-support-tickets/widget.client.js.map +7 -0
  236. package/dist/modules/staff/widgets/injection/portal-support-tickets/widget.js +17 -0
  237. package/dist/modules/staff/widgets/injection/portal-support-tickets/widget.js.map +7 -0
  238. package/dist/modules/staff/widgets/injection/time-tracking-settings-support/widget.client.js +870 -0
  239. package/dist/modules/staff/widgets/injection/time-tracking-settings-support/widget.client.js.map +7 -0
  240. package/dist/modules/staff/widgets/injection/time-tracking-settings-support/widget.js +17 -0
  241. package/dist/modules/staff/widgets/injection/time-tracking-settings-support/widget.js.map +7 -0
  242. package/dist/modules/staff/widgets/injection-table.js +16 -1
  243. package/dist/modules/staff/widgets/injection-table.js.map +2 -2
  244. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +4 -18
  245. package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
  246. package/dist/modules/wms/components/backend/WmsLotDetailPage.js +4 -18
  247. package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
  248. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +4 -18
  249. package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
  250. package/dist/modules/wms/lib/inventoryCsvExport.js +19 -0
  251. package/dist/modules/wms/lib/inventoryCsvExport.js.map +7 -0
  252. package/generated/entities/staff_support_routing_rule/index.ts +9 -0
  253. package/generated/entities/staff_support_ticket/index.ts +17 -0
  254. package/generated/entities/staff_time_project/index.ts +1 -0
  255. package/generated/entities/staff_time_project_member/index.ts +1 -0
  256. package/generated/entities/staff_time_task/index.ts +2 -0
  257. package/generated/entities/staff_time_task_comment/index.ts +4 -0
  258. package/generated/entities.ids.generated.ts +2 -0
  259. package/generated/entity-fields-registry.ts +38 -0
  260. package/package.json +8 -8
  261. package/src/helpers/integration/auth.ts +1 -1
  262. package/src/helpers/integration/communicationChannelsFixtures.ts +60 -2
  263. package/src/modules/catalog/api/bulk-delete/route.ts +12 -2
  264. package/src/modules/communication_channels/api/post/test-seed/route.ts +29 -12
  265. package/src/modules/communication_channels/lib/test-seed.ts +49 -10
  266. package/src/modules/messages/commands/messages.ts +8 -10
  267. package/src/modules/portal/frontend/[orgSlug]/portal/dashboard/page.tsx +2 -2
  268. package/src/modules/staff/AGENTS.md +22 -6
  269. package/src/modules/staff/api/portal/support-tickets/[id]/attachments/route.ts +327 -0
  270. package/src/modules/staff/api/portal/support-tickets/[id]/messages/route.ts +94 -0
  271. package/src/modules/staff/api/portal/support-tickets/[id]/route.ts +160 -0
  272. package/src/modules/staff/api/portal/support-tickets/options/route.ts +60 -0
  273. package/src/modules/staff/api/portal/support-tickets/route.ts +253 -0
  274. package/src/modules/staff/api/timesheets/settings/route.ts +7 -1
  275. package/src/modules/staff/api/timesheets/support-routing-rules/fallback-project/route.ts +131 -0
  276. package/src/modules/staff/api/timesheets/support-routing-rules/preview/route.ts +248 -0
  277. package/src/modules/staff/api/timesheets/support-routing-rules/route.ts +150 -0
  278. package/src/modules/staff/api/timesheets/support-tickets/options/route.ts +181 -0
  279. package/src/modules/staff/api/timesheets/tasks/[id]/claim/route.ts +31 -0
  280. package/src/modules/staff/api/timesheets/tasks/[id]/comments/route.ts +25 -7
  281. package/src/modules/staff/api/timesheets/tasks/[id]/release/route.ts +30 -0
  282. package/src/modules/staff/api/timesheets/tasks/route.ts +119 -67
  283. package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +3 -0
  284. package/src/modules/staff/api/timesheets/time-projects/route.ts +3 -0
  285. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/edit/page.tsx +1 -0
  286. package/src/modules/staff/backend/staff/time-tracking/projects/[id]/page.tsx +67 -2
  287. package/src/modules/staff/backend/staff/time-tracking/projects/projectFormConfig.ts +22 -3
  288. package/src/modules/staff/backend/staff/time-tracking/settings/page.tsx +405 -308
  289. package/src/modules/staff/backend/staff/time-tracking/support/page.meta.ts +14 -0
  290. package/src/modules/staff/backend/staff/time-tracking/support/page.tsx +428 -0
  291. package/src/modules/staff/cli.ts +28 -0
  292. package/src/modules/staff/commands/index.ts +3 -0
  293. package/src/modules/staff/commands/shared.ts +22 -1
  294. package/src/modules/staff/commands/support-routing-rules.ts +595 -0
  295. package/src/modules/staff/commands/support-tickets.ts +580 -0
  296. package/src/modules/staff/commands/timesheets-projects.ts +84 -13
  297. package/src/modules/staff/commands/timesheets-task-assignment.ts +319 -0
  298. package/src/modules/staff/commands/timesheets-task-comments.ts +70 -15
  299. package/src/modules/staff/commands/timesheets-tasks.ts +106 -15
  300. package/src/modules/staff/data/enrichers.ts +203 -0
  301. package/src/modules/staff/data/entities.ts +133 -2
  302. package/src/modules/staff/data/extensions.ts +9 -1
  303. package/src/modules/staff/data/validators.ts +36 -0
  304. package/src/modules/staff/encryption.ts +6 -0
  305. package/src/modules/staff/events.payloads.ts +87 -1
  306. package/src/modules/staff/events.ts +26 -0
  307. package/src/modules/staff/extension-points.ts +1 -0
  308. package/src/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.meta.ts +10 -0
  309. package/src/modules/staff/frontend/[orgSlug]/portal/support/[id]/page.tsx +553 -0
  310. package/src/modules/staff/frontend/[orgSlug]/portal/support/new/page.meta.ts +10 -0
  311. package/src/modules/staff/frontend/[orgSlug]/portal/support/new/page.tsx +346 -0
  312. package/src/modules/staff/frontend/[orgSlug]/portal/support/page.meta.ts +17 -0
  313. package/src/modules/staff/frontend/[orgSlug]/portal/support/page.tsx +253 -0
  314. package/src/modules/staff/i18n/de.json +291 -0
  315. package/src/modules/staff/i18n/en.json +291 -0
  316. package/src/modules/staff/i18n/es.json +291 -0
  317. package/src/modules/staff/i18n/ko.json +291 -0
  318. package/src/modules/staff/i18n/pl.json +291 -0
  319. package/src/modules/staff/index.ts +1 -1
  320. package/src/modules/staff/lib/crud.ts +2 -1
  321. package/src/modules/staff/lib/support/attachments.ts +43 -0
  322. package/src/modules/staff/lib/support/dictionaries.ts +120 -0
  323. package/src/modules/staff/lib/support/notifications.ts +138 -0
  324. package/src/modules/staff/lib/support/portalAttachments.ts +140 -0
  325. package/src/modules/staff/lib/support/portalBroadcast.ts +161 -0
  326. package/src/modules/staff/lib/support/portalRoute.ts +108 -0
  327. package/src/modules/staff/lib/support/portalStatus.ts +15 -0
  328. package/src/modules/staff/lib/support/portalTickets.ts +233 -0
  329. package/src/modules/staff/lib/support/routing.ts +117 -0
  330. package/src/modules/staff/lib/support/routingRuleDraft.ts +45 -0
  331. package/src/modules/staff/lib/support/seedDefaults.ts +151 -0
  332. package/src/modules/staff/lib/support/supportActivity.ts +39 -0
  333. package/src/modules/staff/lib/support-ui/PortalSupportNotLinked.tsx +20 -0
  334. package/src/modules/staff/lib/support-ui/portalAttachmentValidation.ts +125 -0
  335. package/src/modules/staff/lib/support-ui/portalPendingUploads.ts +49 -0
  336. package/src/modules/staff/lib/support-ui/portalSupport.ts +116 -0
  337. package/src/modules/staff/lib/time-tracking/access.ts +2 -62
  338. package/src/modules/staff/lib/time-tracking/listProjectAccess.ts +78 -0
  339. package/src/modules/staff/lib/time-tracking/portalRecipients.ts +173 -5
  340. package/src/modules/staff/lib/time-tracking/projectAssignment.ts +172 -0
  341. package/src/modules/staff/lib/time-tracking/settingKeys.ts +11 -0
  342. package/src/modules/staff/lib/time-tracking/settings.ts +46 -1
  343. package/src/modules/staff/lib/time-tracking/taskAssignmentRoute.ts +165 -0
  344. package/src/modules/staff/lib/time-tracking/workRecipients.ts +183 -0
  345. package/src/modules/staff/lib/time-tracking-ui/BoardFilterChips.tsx +36 -1
  346. package/src/modules/staff/lib/time-tracking-ui/KanbanBoard.tsx +30 -0
  347. package/src/modules/staff/lib/time-tracking-ui/KanbanCard.tsx +9 -0
  348. package/src/modules/staff/lib/time-tracking-ui/ProjectFormSections.tsx +185 -6
  349. package/src/modules/staff/lib/time-tracking-ui/SupportAttachmentsSection.tsx +188 -0
  350. package/src/modules/staff/lib/time-tracking-ui/SupportRequestPanel.tsx +102 -0
  351. package/src/modules/staff/lib/time-tracking-ui/TaskBoardScreen.tsx +2 -0
  352. package/src/modules/staff/lib/time-tracking-ui/TaskCommentThread.tsx +105 -22
  353. package/src/modules/staff/lib/time-tracking-ui/TaskDrawer.tsx +278 -43
  354. package/src/modules/staff/lib/time-tracking-ui/boardDirectory.ts +21 -0
  355. package/src/modules/staff/lib/time-tracking-ui/boardFilters.ts +16 -2
  356. package/src/modules/staff/lib/time-tracking-ui/kanbanBoardData.ts +4 -0
  357. package/src/modules/staff/lib/time-tracking-ui/projectDefaultAssignee.ts +117 -0
  358. package/src/modules/staff/lib/time-tracking-ui/settingsTabs.ts +17 -0
  359. package/src/modules/staff/lib/time-tracking-ui/supportTicketData.ts +71 -0
  360. package/src/modules/staff/lib/time-tracking-ui/taskDrawerData.ts +15 -0
  361. package/src/modules/staff/lib/time-tracking-ui/timeTrackingSettingsForm.ts +48 -1
  362. package/src/modules/staff/migrations/.snapshot-open-mercato.json +714 -0
  363. package/src/modules/staff/migrations/Migration20261009180543_staff.ts +50 -0
  364. package/src/modules/staff/notifications.ts +92 -0
  365. package/src/modules/staff/setup.ts +6 -2
  366. package/src/modules/staff/subscribers/support-portal-comment-created.ts +35 -0
  367. package/src/modules/staff/subscribers/support-portal-comment-deleted.ts +35 -0
  368. package/src/modules/staff/subscribers/support-portal-comment-updated.ts +35 -0
  369. package/src/modules/staff/subscribers/support-portal-status-column-updated.ts +36 -0
  370. package/src/modules/staff/subscribers/support-portal-task-status-changed.ts +34 -0
  371. package/src/modules/staff/subscribers/support-portal-task-updated.ts +34 -0
  372. package/src/modules/staff/subscribers/support-ticket-created-notification.ts +27 -0
  373. package/src/modules/staff/subscribers/support-ticket-customer-replied-notification.ts +27 -0
  374. package/src/modules/staff/subscribers/support-ticket-unnotified-clear.ts +29 -0
  375. package/src/modules/staff/subscribers/time-task-assignee-notification.ts +102 -0
  376. package/src/modules/staff/widgets/injection/portal-support-tickets/widget.client.tsx +151 -0
  377. package/src/modules/staff/widgets/injection/portal-support-tickets/widget.ts +16 -0
  378. package/src/modules/staff/widgets/injection/time-tracking-settings-support/widget.client.tsx +1058 -0
  379. package/src/modules/staff/widgets/injection/time-tracking-settings-support/widget.ts +17 -0
  380. package/src/modules/staff/widgets/injection-table.ts +15 -0
  381. package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +4 -20
  382. package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +4 -20
  383. package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +4 -19
  384. package/src/modules/wms/lib/inventoryCsvExport.ts +18 -0
@@ -0,0 +1,870 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import Link from "next/link";
5
+ import { Pencil, Plus, Save, Trash2 } from "lucide-react";
6
+ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@open-mercato/ui/primitives/dialog";
7
+ import { flash } from "@open-mercato/ui/backend/FlashMessages";
8
+ import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
9
+ import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
10
+ import { apiCall, readApiResultOrThrow, withScopedApiRequestHeaders } from "@open-mercato/ui/backend/utils/apiCall";
11
+ import { createCrud, deleteCrud, updateCrud } from "@open-mercato/ui/backend/utils/crud";
12
+ import { buildOptimisticLockHeader } from "@open-mercato/ui/backend/utils/optimisticLock";
13
+ import { surfaceRecordConflict } from "@open-mercato/ui/backend/conflicts";
14
+ import { raiseCrudError } from "@open-mercato/ui/backend/utils/serverErrors";
15
+ import { useGuardedMutation } from "@open-mercato/ui/backend/injection/useGuardedMutation";
16
+ import { Alert, AlertDescription, AlertTitle } from "@open-mercato/ui/primitives/alert";
17
+ import { Button } from "@open-mercato/ui/primitives/button";
18
+ import { IconButton } from "@open-mercato/ui/primitives/icon-button";
19
+ import { Input } from "@open-mercato/ui/primitives/input";
20
+ import { Label } from "@open-mercato/ui/primitives/label";
21
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@open-mercato/ui/primitives/select";
22
+ import { ComboboxInput } from "@open-mercato/ui/backend/inputs/ComboboxInput";
23
+ import { useBackendChrome } from "@open-mercato/ui/backend/BackendChromeProvider";
24
+ import { hasFeature } from "@open-mercato/shared/security/features";
25
+ import { StatusBadge } from "@open-mercato/ui/primitives/status-badge";
26
+ import { Switch } from "@open-mercato/ui/primitives/switch";
27
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@open-mercato/ui/primitives/table";
28
+ import { useOrganizationScopeVersion } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
29
+ import { useLocale, useT } from "@open-mercato/shared/lib/i18n/context";
30
+ import { ICON_SUGGESTIONS } from "@open-mercato/core/modules/dictionaries/components/dictionaryAppearance";
31
+ import {
32
+ DictionaryForm
33
+ } from "@open-mercato/core/modules/dictionaries/components/DictionaryForm";
34
+ import {
35
+ DictionaryTable
36
+ } from "@open-mercato/core/modules/dictionaries/components/DictionaryTable";
37
+ import { DEFAULT_SUPPORT_REFERENCE_PREFIX } from "../../../lib/time-tracking/settingKeys.js";
38
+ import {
39
+ buildRoutingRuleEditDraft,
40
+ rebaseRoutingRuleDialog,
41
+ routingRuleVersion
42
+ } from "../../../lib/support/routingRuleDraft.js";
43
+ const CATEGORY_DICTIONARY_KEY = "staff.support_ticket_category";
44
+ const ROUTING_API = "staff/timesheets/support-routing-rules";
45
+ const PREVIEW_URL = "/api/staff/timesheets/support-routing-rules/preview";
46
+ const FALLBACK_PROJECT_URL = "/api/staff/timesheets/support-routing-rules/fallback-project";
47
+ const PROJECTS_URL = "/api/staff/timesheets/time-projects";
48
+ const SETTINGS_URL = "/api/staff/timesheets/settings";
49
+ const UNNOTIFIED_INBOX_URL = "/backend/staff/time-tracking/support?supportUnnotified=true";
50
+ const SAVE_CONTEXT_ID = "staff.support.settings";
51
+ const DICTIONARIES_VIEW_FEATURE = "dictionaries.view";
52
+ const DICTIONARIES_MANAGE_FEATURE = "dictionaries.manage";
53
+ const PROJECT_SEARCH_PAGE_SIZE = 20;
54
+ const PREFIX_PATTERN = /^[A-Z][A-Z0-9]{1,9}$/;
55
+ const EMPTY_PREVIEW = { fallback: null, rules: [], categories: [] };
56
+ const DEFAULT_CATEGORY_VALUES = {
57
+ value: "",
58
+ label: "",
59
+ color: null,
60
+ icon: null
61
+ };
62
+ function isRecord(value) {
63
+ return typeof value === "object" && value !== null && !Array.isArray(value);
64
+ }
65
+ function toStringOrNull(value) {
66
+ return typeof value === "string" && value.length > 0 ? value : null;
67
+ }
68
+ function normalizeEntry(item) {
69
+ if (!isRecord(item)) return null;
70
+ const id = toStringOrNull(item.id);
71
+ const value = toStringOrNull(item.value);
72
+ if (!id || !value) return null;
73
+ return {
74
+ id,
75
+ value,
76
+ label: toStringOrNull(item.label) ?? value,
77
+ color: toStringOrNull(item.color),
78
+ icon: toStringOrNull(item.icon),
79
+ organizationId: toStringOrNull(item.organizationId),
80
+ tenantId: toStringOrNull(item.tenantId),
81
+ isInherited: item.isInherited === true,
82
+ createdAt: toStringOrNull(item.createdAt),
83
+ updatedAt: toStringOrNull(item.updatedAt)
84
+ };
85
+ }
86
+ function normalizeProject(item) {
87
+ if (!isRecord(item)) return null;
88
+ const id = toStringOrNull(item.id);
89
+ if (!id) return null;
90
+ return { id, name: toStringOrNull(item.name) ?? id, code: toStringOrNull(item.code) };
91
+ }
92
+ function projectLabel(project) {
93
+ const name = project.name ?? project.id;
94
+ return project.code ? `${name} (${project.code})` : name;
95
+ }
96
+ async function searchProjects(query) {
97
+ const params = new URLSearchParams({
98
+ page: "1",
99
+ pageSize: String(PROJECT_SEARCH_PAGE_SIZE),
100
+ sortField: "name",
101
+ sortDir: "asc"
102
+ });
103
+ const term = query?.trim() ?? "";
104
+ if (term) params.set("q", term);
105
+ try {
106
+ const call = await apiCall(`${PROJECTS_URL}?${params.toString()}`);
107
+ if (!call.ok) return [];
108
+ return (call.result?.items ?? []).map(normalizeProject).filter((project) => project !== null).map((project) => ({ value: project.id, label: projectLabel(project) }));
109
+ } catch {
110
+ return [];
111
+ }
112
+ }
113
+ function SupportProjectPicker({ labelId, value, knownProjects, placeholder, disabled, testId, onChange }) {
114
+ const seedOptions = React.useMemo(
115
+ () => knownProjects.map((project) => ({ value: project.id, label: projectLabel(project) })),
116
+ [knownProjects]
117
+ );
118
+ return /* @__PURE__ */ jsx("div", { role: "group", "aria-labelledby": labelId, "data-testid": testId, children: /* @__PURE__ */ jsx(
119
+ ComboboxInput,
120
+ {
121
+ value,
122
+ onChange: (next) => {
123
+ if (next && next !== value) onChange(next);
124
+ },
125
+ seedOptions,
126
+ loadSuggestions: searchProjects,
127
+ allowCustomValues: false,
128
+ placeholder,
129
+ disabled
130
+ }
131
+ ) });
132
+ }
133
+ function SupportSettingsTab({ context }) {
134
+ const t = useT();
135
+ const locale = useLocale();
136
+ const unnotifiedTicketsLabel = React.useCallback(
137
+ (count) => {
138
+ let category;
139
+ try {
140
+ category = new Intl.PluralRules(locale).select(count);
141
+ } catch {
142
+ category = count === 1 ? "one" : "other";
143
+ }
144
+ if (category === "one") return t("staff.support.settings.routing.unnotifiedTickets.one", "{count} ticket was not notified to anyone.", { count });
145
+ if (category === "few") return t("staff.support.settings.routing.unnotifiedTickets.few", "{count} tickets were not notified to anyone.", { count });
146
+ if (category === "many") return t("staff.support.settings.routing.unnotifiedTickets.many", "{count} tickets were not notified to anyone.", { count });
147
+ return t("staff.support.settings.routing.unnotifiedTickets.other", "{count} tickets were not notified to anyone.", { count });
148
+ },
149
+ [locale, t]
150
+ );
151
+ const scopeVersion = useOrganizationScopeVersion();
152
+ const { confirm, ConfirmDialogElement } = useConfirmDialog();
153
+ const { payload: chromePayload, isReady: chromeReady } = useBackendChrome();
154
+ const grantedFeatures = chromePayload?.grantedFeatures;
155
+ const canManageSettings = context.canManage;
156
+ const canViewCategories = hasFeature(grantedFeatures, DICTIONARIES_VIEW_FEATURE);
157
+ const canManageCategories = canManageSettings && hasFeature(grantedFeatures, DICTIONARIES_MANAGE_FEATURE);
158
+ const { runMutation, retryLastMutation } = useGuardedMutation({
159
+ contextId: SAVE_CONTEXT_ID,
160
+ blockedMessage: t("staff.support.settings.errors.saveBlocked", "Save blocked by validation")
161
+ });
162
+ const routingContext = React.useMemo(() => ({
163
+ formId: SAVE_CONTEXT_ID,
164
+ resourceKind: "staff.support.routing_rule",
165
+ retryLastMutation
166
+ }), [retryLastMutation]);
167
+ const categoryContext = React.useMemo(() => ({
168
+ formId: SAVE_CONTEXT_ID,
169
+ resourceKind: "staff.support.categories",
170
+ retryLastMutation
171
+ }), [retryLastMutation]);
172
+ const settingsContext = React.useMemo(() => ({
173
+ formId: SAVE_CONTEXT_ID,
174
+ resourceKind: "staff.timesheets.settings",
175
+ retryLastMutation
176
+ }), [retryLastMutation]);
177
+ const [categoryEntries, setCategoryEntries] = React.useState([]);
178
+ const [dictionaryId, setDictionaryId] = React.useState(null);
179
+ const [categoriesLoading, setCategoriesLoading] = React.useState(true);
180
+ const [categoriesError, setCategoriesError] = React.useState(null);
181
+ const [categoryDialog, setCategoryDialog] = React.useState(null);
182
+ const [categorySubmitting, setCategorySubmitting] = React.useState(false);
183
+ const [preview, setPreview] = React.useState(EMPTY_PREVIEW);
184
+ const [routingLoading, setRoutingLoading] = React.useState(true);
185
+ const [routingError, setRoutingError] = React.useState(null);
186
+ const [ruleDialog, setRuleDialog] = React.useState(null);
187
+ const [ruleSubmitting, setRuleSubmitting] = React.useState(false);
188
+ const [creatingFallback, setCreatingFallback] = React.useState(false);
189
+ const { settings, onSettingsSaved } = context;
190
+ const savedPrefix = settings.support?.referencePrefix ?? DEFAULT_SUPPORT_REFERENCE_PREFIX;
191
+ const [prefix, setPrefix] = React.useState(savedPrefix);
192
+ const [prefixError, setPrefixError] = React.useState(null);
193
+ const [prefixSaving, setPrefixSaving] = React.useState(false);
194
+ const loadCategories = React.useCallback(async () => {
195
+ if (!chromeReady) return;
196
+ if (!canViewCategories) {
197
+ setCategoryEntries([]);
198
+ setDictionaryId(null);
199
+ setCategoriesError(null);
200
+ setCategoriesLoading(false);
201
+ return;
202
+ }
203
+ setCategoriesLoading(true);
204
+ setCategoriesError(null);
205
+ try {
206
+ const dictionaries = await readApiResultOrThrow(
207
+ "/api/dictionaries",
208
+ void 0,
209
+ { fallback: { items: [] }, errorMessage: t("staff.support.settings.errors.load", "Failed to load support settings.") }
210
+ );
211
+ const dictionary = (dictionaries.items ?? []).find((item) => item.key === CATEGORY_DICTIONARY_KEY);
212
+ const id = dictionary?.id ?? null;
213
+ setDictionaryId(id);
214
+ if (!id) {
215
+ setCategoryEntries([]);
216
+ return;
217
+ }
218
+ const entries = await readApiResultOrThrow(
219
+ `/api/dictionaries/${encodeURIComponent(id)}/entries`,
220
+ void 0,
221
+ { fallback: { items: [] }, errorMessage: t("staff.support.settings.errors.load", "Failed to load support settings.") }
222
+ );
223
+ setCategoryEntries(
224
+ (entries.items ?? []).map(normalizeEntry).filter((entry) => entry !== null)
225
+ );
226
+ } catch (err) {
227
+ setCategoriesError(err instanceof Error ? err.message : t("staff.support.settings.errors.load", "Failed to load support settings."));
228
+ } finally {
229
+ setCategoriesLoading(false);
230
+ }
231
+ }, [canViewCategories, chromeReady, t]);
232
+ const loadRouting = React.useCallback(async () => {
233
+ setRoutingLoading(true);
234
+ setRoutingError(null);
235
+ try {
236
+ const errorMessage = t("staff.support.settings.errors.load", "Failed to load support settings.");
237
+ const previewResult = await readApiResultOrThrow(PREVIEW_URL, void 0, { fallback: EMPTY_PREVIEW, errorMessage }) ?? EMPTY_PREVIEW;
238
+ setPreview(previewResult);
239
+ setRuleDialog((current) => rebaseRoutingRuleDialog(current, previewResult));
240
+ } catch (err) {
241
+ setRoutingError(err instanceof Error ? err.message : t("staff.support.settings.errors.load", "Failed to load support settings."));
242
+ } finally {
243
+ setRoutingLoading(false);
244
+ }
245
+ }, [t]);
246
+ React.useEffect(() => {
247
+ setPrefix(savedPrefix);
248
+ }, [savedPrefix]);
249
+ React.useEffect(() => {
250
+ void loadCategories();
251
+ }, [loadCategories, scopeVersion]);
252
+ React.useEffect(() => {
253
+ void loadRouting();
254
+ }, [loadRouting, scopeVersion]);
255
+ const reloadAll = React.useCallback(async () => {
256
+ await Promise.all([loadCategories(), loadRouting()]);
257
+ }, [loadCategories, loadRouting]);
258
+ const surfaceMutationError = React.useCallback((err, fallbackKey, fallback, onRefresh) => {
259
+ if (surfaceRecordConflict(err, t, onRefresh ? { onRefresh } : void 0)) return;
260
+ flash(err instanceof Error ? err.message : t(fallbackKey, fallback), "error");
261
+ }, [t]);
262
+ const submitCategory = React.useCallback(async (values) => {
263
+ if (!categoryDialog || !dictionaryId || categorySubmitting) return;
264
+ setCategorySubmitting(true);
265
+ try {
266
+ if (categoryDialog.mode === "create") {
267
+ await runMutation({
268
+ operation: async () => {
269
+ const call = await apiCall(`/api/dictionaries/${encodeURIComponent(dictionaryId)}/entries`, {
270
+ method: "POST",
271
+ headers: { "content-type": "application/json" },
272
+ body: JSON.stringify(values)
273
+ });
274
+ if (!call.ok) await raiseCrudError(call.response, t("staff.support.settings.errors.save", "Failed to save."));
275
+ return call;
276
+ },
277
+ context: categoryContext,
278
+ mutationPayload: { action: "create", ...values }
279
+ });
280
+ } else {
281
+ const entry = categoryDialog.entry;
282
+ const payload = {};
283
+ if (values.value !== entry.value) payload.value = values.value;
284
+ if (values.label !== entry.label) payload.label = values.label;
285
+ if ((values.color ?? null) !== (entry.color ?? null)) payload.color = values.color ?? null;
286
+ if ((values.icon ?? null) !== (entry.icon ?? null)) payload.icon = values.icon ?? null;
287
+ await runMutation({
288
+ operation: async () => {
289
+ const call = await withScopedApiRequestHeaders(
290
+ buildOptimisticLockHeader(entry.updatedAt),
291
+ () => apiCall(`/api/dictionaries/${encodeURIComponent(dictionaryId)}/entries/${encodeURIComponent(entry.id)}`, {
292
+ method: "PATCH",
293
+ headers: { "content-type": "application/json" },
294
+ body: JSON.stringify(payload)
295
+ })
296
+ );
297
+ if (!call.ok) await raiseCrudError(call.response, t("staff.support.settings.errors.save", "Failed to save."));
298
+ return call;
299
+ },
300
+ context: categoryContext,
301
+ mutationPayload: { action: "update", id: entry.id, ...payload }
302
+ });
303
+ }
304
+ flash(t("staff.support.settings.categories.saved", "Category saved."), "success");
305
+ setCategoryDialog(null);
306
+ await reloadAll();
307
+ } catch (err) {
308
+ surfaceMutationError(err, "staff.support.settings.errors.save", "Failed to save.", () => {
309
+ void loadCategories();
310
+ });
311
+ } finally {
312
+ setCategorySubmitting(false);
313
+ }
314
+ }, [categoryContext, categoryDialog, categorySubmitting, dictionaryId, loadCategories, reloadAll, surfaceMutationError, runMutation, t]);
315
+ const deleteCategory = React.useCallback(async (entry) => {
316
+ if (!dictionaryId) return;
317
+ const confirmed = await confirm({
318
+ title: t("staff.support.settings.categories.confirmDelete", 'Delete category "{value}"?', { value: entry.label || entry.value }),
319
+ variant: "destructive"
320
+ });
321
+ if (!confirmed) return;
322
+ try {
323
+ await runMutation({
324
+ operation: async () => {
325
+ const call = await withScopedApiRequestHeaders(
326
+ buildOptimisticLockHeader(entry.updatedAt),
327
+ () => apiCall(`/api/dictionaries/${encodeURIComponent(dictionaryId)}/entries/${encodeURIComponent(entry.id)}`, {
328
+ method: "DELETE"
329
+ })
330
+ );
331
+ if (!call.ok) await raiseCrudError(call.response, t("staff.support.settings.errors.delete", "Failed to delete."));
332
+ return call;
333
+ },
334
+ context: categoryContext,
335
+ mutationPayload: { action: "delete", id: entry.id }
336
+ });
337
+ flash(t("staff.support.settings.categories.deleted", "Category deleted."), "success");
338
+ await reloadAll();
339
+ } catch (err) {
340
+ surfaceMutationError(err, "staff.support.settings.errors.delete", "Failed to delete.", () => {
341
+ void loadCategories();
342
+ });
343
+ }
344
+ }, [categoryContext, confirm, dictionaryId, loadCategories, reloadAll, surfaceMutationError, runMutation, t]);
345
+ const createFallbackProject = React.useCallback(async () => {
346
+ setCreatingFallback(true);
347
+ try {
348
+ await runMutation({
349
+ operation: async () => {
350
+ const call = await apiCall(FALLBACK_PROJECT_URL, { method: "POST" });
351
+ if (!call.ok) await raiseCrudError(call.response, t("staff.support.settings.errors.save", "Failed to save."));
352
+ return call;
353
+ },
354
+ context: routingContext,
355
+ mutationPayload: { action: "create_fallback_project" }
356
+ });
357
+ flash(t("staff.support.settings.routing.fallbackCreated", "Fallback project created."), "success");
358
+ await loadRouting();
359
+ } catch (err) {
360
+ surfaceMutationError(err, "staff.support.settings.errors.save", "Failed to save.");
361
+ } finally {
362
+ setCreatingFallback(false);
363
+ }
364
+ }, [loadRouting, surfaceMutationError, routingContext, runMutation, t]);
365
+ const updateRule = React.useCallback(async (ruleId, expectedUpdatedAt, patch) => {
366
+ try {
367
+ await runMutation({
368
+ operation: () => updateCrud(ROUTING_API, { id: ruleId, ...patch }, {
369
+ headers: buildOptimisticLockHeader(expectedUpdatedAt),
370
+ errorMessage: t("staff.support.settings.errors.save", "Failed to save.")
371
+ }),
372
+ context: routingContext,
373
+ mutationPayload: { action: "update", id: ruleId, ...patch }
374
+ });
375
+ flash(t("staff.support.settings.routing.saved", "Routing saved."), "success");
376
+ await loadRouting();
377
+ return true;
378
+ } catch (err) {
379
+ surfaceMutationError(err, "staff.support.settings.errors.save", "Failed to save.", () => {
380
+ void loadRouting();
381
+ });
382
+ return false;
383
+ }
384
+ }, [loadRouting, surfaceMutationError, routingContext, runMutation, t]);
385
+ const deleteRule = React.useCallback(async (rule) => {
386
+ const confirmed = await confirm({
387
+ title: t("staff.support.settings.routing.confirmDelete", "Delete this rule? The category will use the fallback project."),
388
+ variant: "destructive"
389
+ });
390
+ if (!confirmed) return;
391
+ try {
392
+ await runMutation({
393
+ operation: () => deleteCrud(ROUTING_API, rule.id, {
394
+ headers: buildOptimisticLockHeader(routingRuleVersion(rule)),
395
+ errorMessage: t("staff.support.settings.errors.delete", "Failed to delete.")
396
+ }),
397
+ context: routingContext,
398
+ mutationPayload: { action: "delete", id: rule.id }
399
+ });
400
+ flash(t("staff.support.settings.routing.deleted", "Rule deleted."), "success");
401
+ await loadRouting();
402
+ } catch (err) {
403
+ surfaceMutationError(err, "staff.support.settings.errors.delete", "Failed to delete.", () => {
404
+ void loadRouting();
405
+ });
406
+ }
407
+ }, [confirm, loadRouting, surfaceMutationError, routingContext, runMutation, t]);
408
+ const submitRuleDialog = React.useCallback(async () => {
409
+ if (!ruleDialog || !ruleDialog.timeProjectId || ruleSubmitting) return;
410
+ if (ruleDialog.mode === "create" && !ruleDialog.categoryValue) return;
411
+ setRuleSubmitting(true);
412
+ try {
413
+ if (ruleDialog.mode === "create") {
414
+ await runMutation({
415
+ operation: () => createCrud(ROUTING_API, {
416
+ categoryValue: ruleDialog.categoryValue,
417
+ timeProjectId: ruleDialog.timeProjectId
418
+ }, { errorMessage: t("staff.support.settings.errors.save", "Failed to save.") }),
419
+ context: routingContext,
420
+ mutationPayload: { action: "create", categoryValue: ruleDialog.categoryValue, timeProjectId: ruleDialog.timeProjectId }
421
+ });
422
+ flash(t("staff.support.settings.routing.saved", "Routing saved."), "success");
423
+ setRuleDialog(null);
424
+ await loadRouting();
425
+ } else {
426
+ const ok = await updateRule(ruleDialog.ruleId, ruleDialog.expectedUpdatedAt, { timeProjectId: ruleDialog.timeProjectId });
427
+ if (ok) setRuleDialog(null);
428
+ }
429
+ } catch (err) {
430
+ surfaceMutationError(err, "staff.support.settings.errors.save", "Failed to save.", () => {
431
+ void loadRouting();
432
+ });
433
+ } finally {
434
+ setRuleSubmitting(false);
435
+ }
436
+ }, [loadRouting, surfaceMutationError, routingContext, ruleDialog, ruleSubmitting, runMutation, t, updateRule]);
437
+ const savePrefix = React.useCallback(async () => {
438
+ const value = prefix.trim().toUpperCase();
439
+ if (!PREFIX_PATTERN.test(value)) {
440
+ setPrefixError(t("staff.support.settings.prefix.invalid", "Use 2\u201310 uppercase letters or digits, starting with a letter."));
441
+ return;
442
+ }
443
+ setPrefixError(null);
444
+ setPrefixSaving(true);
445
+ try {
446
+ const next = { ...settings, support: { ...settings.support ?? {}, referencePrefix: value } };
447
+ const call = await runMutation({
448
+ operation: async () => {
449
+ const call2 = await apiCall(SETTINGS_URL, {
450
+ method: "PUT",
451
+ headers: { "content-type": "application/json" },
452
+ body: JSON.stringify(next)
453
+ });
454
+ if (!call2.ok) await raiseCrudError(call2.response, t("staff.support.settings.errors.save", "Failed to save."));
455
+ return call2;
456
+ },
457
+ context: settingsContext,
458
+ mutationPayload: { support: { referencePrefix: value } }
459
+ });
460
+ if (call.result) onSettingsSaved(call.result);
461
+ flash(t("staff.support.settings.prefix.saved", "Reference prefix saved."), "success");
462
+ } catch (err) {
463
+ surfaceMutationError(err, "staff.support.settings.errors.save", "Failed to save.");
464
+ } finally {
465
+ setPrefixSaving(false);
466
+ }
467
+ }, [onSettingsSaved, prefix, surfaceMutationError, runMutation, settings, settingsContext, t]);
468
+ const categoryLabels = React.useMemo(() => {
469
+ const map = /* @__PURE__ */ new Map();
470
+ for (const category of preview.categories) map.set(category.value, category.label);
471
+ for (const entry of categoryEntries) if (!map.has(entry.value)) map.set(entry.value, entry.label);
472
+ return map;
473
+ }, [categoryEntries, preview.categories]);
474
+ const overrides = React.useMemo(() => preview.rules.filter((rule) => !rule.isFallback), [preview.rules]);
475
+ const categoriesWithoutRule = React.useMemo(() => {
476
+ const ruled = new Set(overrides.map((rule) => rule.categoryValue));
477
+ return preview.categories.filter((category) => !ruled.has(category.value));
478
+ }, [overrides, preview.categories]);
479
+ const fallbackName = preview.fallback ? projectLabel(preview.fallback.project) : "";
480
+ const knownProjects = React.useMemo(() => {
481
+ const byId = /* @__PURE__ */ new Map();
482
+ const remember = (project) => {
483
+ if (!byId.has(project.id)) byId.set(project.id, { id: project.id, name: project.name ?? project.id, code: project.code });
484
+ };
485
+ if (preview.fallback) remember(preview.fallback.project);
486
+ for (const rule of preview.rules) remember(rule.project);
487
+ for (const category of preview.categories) if (category.route) remember(category.route.project);
488
+ return [...byId.values()];
489
+ }, [preview]);
490
+ const problemText = (problem) => {
491
+ if (problem === "paused") return t("staff.support.settings.routing.problem.paused", "The rule is paused.");
492
+ if (problem === "category_missing") return t("staff.support.settings.routing.problem.categoryMissing", "The category no longer exists.");
493
+ return t("staff.support.settings.routing.problem.projectUnusable", "The project is completed, deleted, or has no default status.");
494
+ };
495
+ const nobodyNotifiedText = t(
496
+ "staff.support.settings.routing.nobodyNotified",
497
+ "No one in this project will be notified about tickets routed here: it has no active assigner, no usable default assignee and no owner. New tickets go to the organization's project managers instead."
498
+ );
499
+ const unnotifiedTicketCount = typeof preview.unnotifiedTicketCount === "number" ? preview.unnotifiedTicketCount : 0;
500
+ const tableTranslations = React.useMemo(() => ({
501
+ title: t("staff.support.settings.categories.title", "Categories"),
502
+ valueColumn: t("staff.support.settings.categories.value", "Value"),
503
+ labelColumn: t("staff.support.settings.categories.label", "Label"),
504
+ appearanceColumn: t("staff.support.settings.categories.appearance", "Appearance"),
505
+ addLabel: t("staff.support.settings.categories.add", "Add category"),
506
+ editLabel: t("staff.support.settings.actions.edit", "Edit"),
507
+ deleteLabel: t("staff.support.settings.actions.delete", "Delete"),
508
+ refreshLabel: t("staff.support.settings.actions.refresh", "Refresh"),
509
+ inheritedLabel: t("staff.support.settings.categories.inherited", "Inherited"),
510
+ inheritedTooltip: t("staff.support.settings.categories.inheritedTooltip", "Defined by a parent organization."),
511
+ emptyLabel: t("staff.support.settings.categories.empty", "No categories yet."),
512
+ searchPlaceholder: t("staff.support.settings.categories.search", "Search categories")
513
+ }), [t]);
514
+ const categoryFormValues = React.useMemo(() => {
515
+ if (categoryDialog?.mode === "edit") {
516
+ return {
517
+ value: categoryDialog.entry.value,
518
+ label: categoryDialog.entry.label,
519
+ color: categoryDialog.entry.color,
520
+ icon: categoryDialog.entry.icon
521
+ };
522
+ }
523
+ return DEFAULT_CATEGORY_VALUES;
524
+ }, [categoryDialog]);
525
+ const categoryDialogTitle = categoryDialog?.mode === "edit" ? t("staff.support.settings.categories.editTitle", "Edit category") : t("staff.support.settings.categories.createTitle", "Add category");
526
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
527
+ /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
528
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.description", "Configure support ticket categories, where each category is routed, and the ticket reference prefix.") }),
529
+ /* @__PURE__ */ jsxs("section", { className: "rounded-xl border border-border bg-card text-card-foreground", children: [
530
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 border-b border-border px-6 py-4", children: [
531
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-medium", children: t("staff.support.settings.categories.title", "Categories") }),
532
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.categories.description", "Categories customers pick when they file a ticket in the portal.") })
533
+ ] }),
534
+ /* @__PURE__ */ jsx("div", { className: "px-2 py-4 sm:px-4", children: chromeReady && !canViewCategories ? /* @__PURE__ */ jsx(Alert, { status: "information", children: /* @__PURE__ */ jsx(AlertDescription, { children: t("staff.support.settings.categories.noAccess", "You do not have permission to view the support categories.") }) }) : categoriesError ? /* @__PURE__ */ jsx(
535
+ ErrorMessage,
536
+ {
537
+ label: categoriesError,
538
+ action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => {
539
+ void loadCategories();
540
+ }, children: t("staff.support.settings.actions.retry", "Try again") })
541
+ }
542
+ ) : !categoriesLoading && !dictionaryId ? /* @__PURE__ */ jsx(Alert, { status: "warning", children: /* @__PURE__ */ jsx(AlertDescription, { children: t("staff.support.settings.categories.missingDictionary", "The support categories dictionary has not been seeded for this organization yet.") }) }) : /* @__PURE__ */ jsx(
543
+ DictionaryTable,
544
+ {
545
+ entries: categoryEntries,
546
+ loading: categoriesLoading,
547
+ canManage: canManageCategories,
548
+ onCreate: () => setCategoryDialog({ mode: "create" }),
549
+ onEdit: (entry) => setCategoryDialog({ mode: "edit", entry: categoryEntries.find((row) => row.id === entry.id) ?? entry }),
550
+ onDelete: (entry) => {
551
+ void deleteCategory(categoryEntries.find((row) => row.id === entry.id) ?? entry);
552
+ },
553
+ onRefresh: () => {
554
+ void loadCategories();
555
+ },
556
+ translations: tableTranslations
557
+ }
558
+ ) })
559
+ ] }),
560
+ /* @__PURE__ */ jsxs("section", { className: "rounded-xl border border-border bg-card text-card-foreground", children: [
561
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 border-b border-border px-6 py-4", children: [
562
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-medium", children: t("staff.support.settings.routing.title", "Routing") }),
563
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.routing.description", "Every category without a working rule goes to the fallback project. Add a rule to send a category to its own project.") })
564
+ ] }),
565
+ /* @__PURE__ */ jsx("div", { className: "space-y-6 px-6 py-4", children: routingLoading ? /* @__PURE__ */ jsx(LoadingMessage, { label: t("staff.support.settings.routing.loading", "Loading routing\u2026") }) : routingError ? /* @__PURE__ */ jsx(
566
+ ErrorMessage,
567
+ {
568
+ label: routingError,
569
+ action: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => {
570
+ void loadRouting();
571
+ }, children: t("staff.support.settings.actions.retry", "Try again") })
572
+ }
573
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
574
+ unnotifiedTicketCount > 0 ? /* @__PURE__ */ jsx(Alert, { status: "warning", "data-testid": "support-unnotified-tickets", children: /* @__PURE__ */ jsxs(AlertDescription, { children: [
575
+ unnotifiedTicketsLabel(unnotifiedTicketCount),
576
+ " ",
577
+ /* @__PURE__ */ jsx(Link, { className: "font-medium underline", href: UNNOTIFIED_INBOX_URL, children: t("staff.support.settings.routing.unnotifiedTicketsLink", "Open them in the Support Inbox") })
578
+ ] }) }) : null,
579
+ !preview.fallback ? /* @__PURE__ */ jsxs(
580
+ Alert,
581
+ {
582
+ status: "warning",
583
+ footer: /* @__PURE__ */ jsxs(Button, { type: "button", onClick: () => {
584
+ void createFallbackProject();
585
+ }, disabled: creatingFallback || !canManageSettings, children: [
586
+ /* @__PURE__ */ jsx(Plus, { className: "mr-2 h-4 w-4" }),
587
+ t("staff.support.settings.routing.createFallback", "Create fallback project")
588
+ ] }),
589
+ children: [
590
+ /* @__PURE__ */ jsx(AlertTitle, { children: t("staff.support.settings.routing.noFallbackTitle", "No fallback project") }),
591
+ /* @__PURE__ */ jsx(AlertDescription, { children: t("staff.support.settings.routing.noFallbackDescription", "Customers cannot file tickets for categories without their own rule until a fallback project exists.") })
592
+ ]
593
+ }
594
+ ) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
595
+ !preview.fallback.project.usable ? /* @__PURE__ */ jsxs(Alert, { status: "error", children: [
596
+ /* @__PURE__ */ jsx(AlertTitle, { children: t("staff.support.settings.routing.fallbackUnusableTitle", "The fallback project cannot receive tickets") }),
597
+ /* @__PURE__ */ jsx(AlertDescription, { children: t("staff.support.settings.routing.fallbackUnusableDescription", "It is completed, deleted, or has no default status. Point the fallback rule at another project.") })
598
+ ] }) : null,
599
+ preview.fallback.project.nobodyNotified === true ? /* @__PURE__ */ jsx(Alert, { status: "warning", "data-testid": "support-fallback-nobody-notified", children: /* @__PURE__ */ jsx(AlertDescription, { children: nobodyNotifiedText }) }) : null,
600
+ /* @__PURE__ */ jsxs("div", { className: "max-w-md space-y-2", children: [
601
+ /* @__PURE__ */ jsx(Label, { id: "support-fallback-project-label", children: t("staff.support.settings.routing.fallbackProject", "Fallback project") }),
602
+ /* @__PURE__ */ jsx(
603
+ SupportProjectPicker,
604
+ {
605
+ labelId: "support-fallback-project-label",
606
+ testId: "support-fallback-project",
607
+ value: preview.fallback.project.id,
608
+ knownProjects,
609
+ placeholder: t("staff.support.settings.routing.searchProject", "Search projects"),
610
+ disabled: !canManageSettings,
611
+ onChange: (projectId) => {
612
+ if (preview.fallback) {
613
+ void updateRule(preview.fallback.ruleId, routingRuleVersion(preview.fallback), { timeProjectId: projectId });
614
+ }
615
+ }
616
+ }
617
+ )
618
+ ] })
619
+ ] }),
620
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
621
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
622
+ /* @__PURE__ */ jsx("h3", { className: "text-base font-medium", children: t("staff.support.settings.routing.overrides", "Category rules") }),
623
+ /* @__PURE__ */ jsxs(
624
+ Button,
625
+ {
626
+ type: "button",
627
+ variant: "outline",
628
+ disabled: categoriesWithoutRule.length === 0 || !canManageSettings,
629
+ onClick: () => setRuleDialog({
630
+ mode: "create",
631
+ categoryValue: categoriesWithoutRule[0]?.value ?? "",
632
+ timeProjectId: ""
633
+ }),
634
+ children: [
635
+ /* @__PURE__ */ jsx(Plus, { className: "mr-2 h-4 w-4" }),
636
+ t("staff.support.settings.routing.addRule", "Add rule")
637
+ ]
638
+ }
639
+ )
640
+ ] }),
641
+ overrides.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.routing.noOverrides", "No category rules. Every category goes to the fallback project.") }) : /* @__PURE__ */ jsxs(Table, { children: [
642
+ /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
643
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.category", "Category") }),
644
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.project", "Project") }),
645
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.active", "Active") }),
646
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.state", "State") }),
647
+ /* @__PURE__ */ jsx(TableHead, { className: "w-24" })
648
+ ] }) }),
649
+ /* @__PURE__ */ jsx(TableBody, { children: overrides.map((rule) => /* @__PURE__ */ jsxs(TableRow, { children: [
650
+ /* @__PURE__ */ jsx(TableCell, { children: categoryLabels.get(rule.categoryValue ?? "") ?? rule.categoryValue }),
651
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
652
+ /* @__PURE__ */ jsx("span", { children: projectLabel(rule.project) }),
653
+ rule.project.nobodyNotified === true ? /* @__PURE__ */ jsx(Alert, { status: "warning", size: "xs", "data-testid": "support-rule-nobody-notified", children: /* @__PURE__ */ jsx(AlertDescription, { children: nobodyNotifiedText }) }) : null
654
+ ] }) }),
655
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(
656
+ Switch,
657
+ {
658
+ checked: rule.isActive,
659
+ disabled: !canManageSettings,
660
+ "aria-label": t("staff.support.settings.routing.active", "Active"),
661
+ onCheckedChange: (checked) => {
662
+ void updateRule(rule.id, routingRuleVersion(rule), { isActive: checked });
663
+ }
664
+ }
665
+ ) }),
666
+ /* @__PURE__ */ jsx(TableCell, { children: rule.problem ? /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
667
+ /* @__PURE__ */ jsx(StatusBadge, { variant: "warning", dot: true, children: t("staff.support.settings.routing.fallingBack", "Falling back to {project}", { project: fallbackName }) }),
668
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: problemText(rule.problem) })
669
+ ] }) : /* @__PURE__ */ jsx(StatusBadge, { variant: "success", dot: true, children: t("staff.support.settings.routing.routing", "Routing") }) }),
670
+ /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-1", children: [
671
+ /* @__PURE__ */ jsx(
672
+ IconButton,
673
+ {
674
+ type: "button",
675
+ variant: "ghost",
676
+ "aria-label": t("staff.support.settings.actions.edit", "Edit"),
677
+ disabled: !canManageSettings,
678
+ onClick: () => setRuleDialog(buildRoutingRuleEditDraft(rule)),
679
+ children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" })
680
+ }
681
+ ),
682
+ /* @__PURE__ */ jsx(
683
+ IconButton,
684
+ {
685
+ type: "button",
686
+ variant: "ghost",
687
+ "aria-label": t("staff.support.settings.actions.delete", "Delete"),
688
+ disabled: !canManageSettings,
689
+ onClick: () => {
690
+ void deleteRule(rule);
691
+ },
692
+ children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
693
+ }
694
+ )
695
+ ] }) })
696
+ ] }, rule.id)) })
697
+ ] })
698
+ ] }),
699
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
700
+ /* @__PURE__ */ jsx("h3", { className: "text-base font-medium", children: t("staff.support.settings.preview.title", "Where tickets go now") }),
701
+ preview.categories.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.preview.empty", "No categories to route.") }) : /* @__PURE__ */ jsxs(Table, { children: [
702
+ /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
703
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.category", "Category") }),
704
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.routing.project", "Project") }),
705
+ /* @__PURE__ */ jsx(TableHead, { children: t("staff.support.settings.preview.via", "Routed by") })
706
+ ] }) }),
707
+ /* @__PURE__ */ jsx(TableBody, { children: preview.categories.map((category) => /* @__PURE__ */ jsxs(TableRow, { children: [
708
+ /* @__PURE__ */ jsx(TableCell, { children: category.label }),
709
+ /* @__PURE__ */ jsx(TableCell, { children: category.route ? projectLabel(category.route.project) : /* @__PURE__ */ jsx(StatusBadge, { variant: "error", dot: true, children: t("staff.support.settings.preview.unavailable", "Not available on portal") }) }),
710
+ /* @__PURE__ */ jsx(TableCell, { children: category.route ? category.route.via === "category" ? t("staff.support.settings.preview.viaCategory", "Category rule") : t("staff.support.settings.preview.viaFallback", "Fallback rule") : "\u2014" })
711
+ ] }, category.value)) })
712
+ ] })
713
+ ] })
714
+ ] }) })
715
+ ] }),
716
+ /* @__PURE__ */ jsxs("section", { className: "rounded-xl border border-border bg-card text-card-foreground", children: [
717
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 border-b border-border px-6 py-4", children: [
718
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-medium", children: t("staff.support.settings.prefix.title", "Reference prefix") }),
719
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("staff.support.settings.prefix.description", "Customers see ticket references such as SUP-1042. The prefix applies to the whole tenant.") })
720
+ ] }),
721
+ /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex max-w-md items-end gap-2", children: [
722
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-2", children: [
723
+ /* @__PURE__ */ jsx(Label, { htmlFor: "support-reference-prefix", children: t("staff.support.settings.referencePrefix", "Reference prefix") }),
724
+ /* @__PURE__ */ jsx(
725
+ Input,
726
+ {
727
+ id: "support-reference-prefix",
728
+ value: prefix,
729
+ maxLength: 10,
730
+ disabled: !canManageSettings,
731
+ onChange: (event) => setPrefix(event.target.value.toUpperCase()),
732
+ "aria-invalid": prefixError ? true : void 0
733
+ }
734
+ ),
735
+ prefixError ? /* @__PURE__ */ jsx("p", { className: "text-sm text-status-error-text", children: prefixError }) : null
736
+ ] }),
737
+ /* @__PURE__ */ jsxs(Button, { type: "button", onClick: () => {
738
+ void savePrefix();
739
+ }, disabled: prefixSaving || !canManageSettings, children: [
740
+ /* @__PURE__ */ jsx(Save, { className: "mr-2 h-4 w-4" }),
741
+ t("staff.support.settings.actions.save", "Save")
742
+ ] })
743
+ ] }) })
744
+ ] })
745
+ ] }),
746
+ /* @__PURE__ */ jsx(Dialog, { open: categoryDialog !== null, onOpenChange: (open) => {
747
+ if (!open) setCategoryDialog(null);
748
+ }, children: /* @__PURE__ */ jsxs(
749
+ DialogContent,
750
+ {
751
+ className: "max-w-lg",
752
+ onKeyDown: (event) => {
753
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
754
+ event.preventDefault();
755
+ if (categorySubmitting) return;
756
+ event.currentTarget.querySelector("form")?.requestSubmit();
757
+ }
758
+ },
759
+ children: [
760
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: categoryDialogTitle }) }),
761
+ /* @__PURE__ */ jsx(
762
+ DictionaryForm,
763
+ {
764
+ mode: categoryDialog?.mode === "edit" ? "edit" : "create",
765
+ initialValues: categoryFormValues,
766
+ onSubmit: submitCategory,
767
+ onCancel: () => setCategoryDialog(null),
768
+ submitting: categorySubmitting,
769
+ translations: {
770
+ title: categoryDialogTitle,
771
+ valueLabel: t("staff.support.settings.categories.value", "Value"),
772
+ labelLabel: t("staff.support.settings.categories.label", "Label"),
773
+ saveLabel: t("staff.support.settings.actions.save", "Save"),
774
+ cancelLabel: t("staff.support.settings.actions.cancel", "Cancel"),
775
+ appearance: {
776
+ colorLabel: t("staff.support.settings.categories.colorLabel", "Color"),
777
+ colorHelp: t("staff.support.settings.categories.colorHelp", "Shown as the category badge color."),
778
+ colorClearLabel: t("staff.support.settings.categories.colorClear", "Clear color"),
779
+ iconLabel: t("staff.support.settings.categories.iconLabel", "Icon"),
780
+ iconPlaceholder: t("staff.support.settings.categories.iconPlaceholder", "Icon name"),
781
+ iconPickerTriggerLabel: t("staff.support.settings.categories.iconBrowse", "Browse icons"),
782
+ iconSearchPlaceholder: t("staff.support.settings.categories.iconSearchPlaceholder", "Search icons"),
783
+ iconSearchEmptyLabel: t("staff.support.settings.categories.iconSearchEmpty", "No icons found."),
784
+ iconSuggestionsLabel: t("staff.support.settings.categories.iconSuggestions", "Suggestions"),
785
+ iconClearLabel: t("staff.support.settings.categories.iconClear", "Clear icon"),
786
+ previewEmptyLabel: t("staff.support.settings.categories.previewEmpty", "No appearance")
787
+ }
788
+ },
789
+ iconSuggestions: ICON_SUGGESTIONS
790
+ }
791
+ )
792
+ ]
793
+ }
794
+ ) }),
795
+ /* @__PURE__ */ jsx(Dialog, { open: ruleDialog !== null, onOpenChange: (open) => {
796
+ if (!open) setRuleDialog(null);
797
+ }, children: /* @__PURE__ */ jsxs(
798
+ DialogContent,
799
+ {
800
+ className: "max-w-lg",
801
+ onKeyDown: (event) => {
802
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
803
+ event.preventDefault();
804
+ if (ruleSubmitting) return;
805
+ void submitRuleDialog();
806
+ }
807
+ },
808
+ children: [
809
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: ruleDialog?.mode === "edit" ? t("staff.support.settings.routing.editRuleTitle", "Edit rule") : t("staff.support.settings.routing.addRuleTitle", "Add rule") }) }),
810
+ ruleDialog ? /* @__PURE__ */ jsxs(
811
+ "form",
812
+ {
813
+ className: "space-y-4",
814
+ onSubmit: (event) => {
815
+ event.preventDefault();
816
+ void submitRuleDialog();
817
+ },
818
+ children: [
819
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
820
+ /* @__PURE__ */ jsx(Label, { htmlFor: "support-rule-category", children: t("staff.support.settings.routing.category", "Category") }),
821
+ ruleDialog.mode === "create" ? /* @__PURE__ */ jsxs(
822
+ Select,
823
+ {
824
+ value: ruleDialog.categoryValue,
825
+ onValueChange: (value) => setRuleDialog({ ...ruleDialog, categoryValue: value }),
826
+ children: [
827
+ /* @__PURE__ */ jsx(SelectTrigger, { id: "support-rule-category", children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("staff.support.settings.routing.selectCategory", "Select a category") }) }),
828
+ /* @__PURE__ */ jsx(SelectContent, { children: categoriesWithoutRule.map((category) => /* @__PURE__ */ jsx(SelectItem, { value: category.value, children: category.label }, category.value)) })
829
+ ]
830
+ }
831
+ ) : /* @__PURE__ */ jsx("p", { id: "support-rule-category", className: "text-sm", children: categoryLabels.get(ruleDialog.categoryValue) ?? ruleDialog.categoryValue })
832
+ ] }),
833
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
834
+ /* @__PURE__ */ jsx(Label, { id: "support-rule-project-label", children: t("staff.support.settings.routing.project", "Project") }),
835
+ /* @__PURE__ */ jsx(
836
+ SupportProjectPicker,
837
+ {
838
+ labelId: "support-rule-project-label",
839
+ testId: "support-rule-project",
840
+ value: ruleDialog.timeProjectId,
841
+ knownProjects,
842
+ placeholder: t("staff.support.settings.routing.selectProject", "Select a project"),
843
+ onChange: (projectId) => setRuleDialog({ ...ruleDialog, timeProjectId: projectId })
844
+ }
845
+ )
846
+ ] }),
847
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
848
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => setRuleDialog(null), children: t("staff.support.settings.actions.cancel", "Cancel") }),
849
+ /* @__PURE__ */ jsx(
850
+ Button,
851
+ {
852
+ type: "submit",
853
+ disabled: ruleSubmitting || !ruleDialog.timeProjectId || ruleDialog.mode === "create" && !ruleDialog.categoryValue,
854
+ children: t("staff.support.settings.actions.save", "Save")
855
+ }
856
+ )
857
+ ] })
858
+ ]
859
+ }
860
+ ) : null
861
+ ]
862
+ }
863
+ ) }),
864
+ ConfirmDialogElement
865
+ ] });
866
+ }
867
+ export {
868
+ SupportSettingsTab as default
869
+ };
870
+ //# sourceMappingURL=widget.client.js.map