@open-mercato/core 0.6.4-develop.4217.1.c9aa050183 → 0.6.4-develop.4236.1.9fa6806b34

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 (370) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/staff_time_entry/index.js +37 -0
  3. package/dist/generated/entities/staff_time_entry/index.js.map +7 -0
  4. package/dist/generated/entities/staff_time_entry_segment/index.js +23 -0
  5. package/dist/generated/entities/staff_time_entry_segment/index.js.map +7 -0
  6. package/dist/generated/entities/staff_time_project/index.js +35 -0
  7. package/dist/generated/entities/staff_time_project/index.js.map +7 -0
  8. package/dist/generated/entities/staff_time_project_member/index.js +29 -0
  9. package/dist/generated/entities/staff_time_project_member/index.js.map +7 -0
  10. package/dist/generated/entities.ids.generated.js +5 -1
  11. package/dist/generated/entities.ids.generated.js.map +2 -2
  12. package/dist/generated/entity-fields-registry.js +64 -0
  13. package/dist/generated/entity-fields-registry.js.map +2 -2
  14. package/dist/helpers/integration/timesheetFixtures.js +50 -0
  15. package/dist/helpers/integration/timesheetFixtures.js.map +7 -0
  16. package/dist/modules/attachments/api/library/[id]/route.js +20 -16
  17. package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
  18. package/dist/modules/attachments/api/route.js +18 -14
  19. package/dist/modules/attachments/api/route.js.map +2 -2
  20. package/dist/modules/auth/api/roles/acl/route.js +10 -4
  21. package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
  22. package/dist/modules/auth/api/sidebar/preferences/route.js +27 -20
  23. package/dist/modules/auth/api/sidebar/preferences/route.js.map +2 -2
  24. package/dist/modules/auth/api/users/acl/route.js +16 -11
  25. package/dist/modules/auth/api/users/acl/route.js.map +2 -2
  26. package/dist/modules/auth/commands/users.js +87 -71
  27. package/dist/modules/auth/commands/users.js.map +2 -2
  28. package/dist/modules/auth/services/sidebarPreferencesService.js +39 -30
  29. package/dist/modules/auth/services/sidebarPreferencesService.js.map +2 -2
  30. package/dist/modules/catalog/commands/categories.js +61 -12
  31. package/dist/modules/catalog/commands/categories.js.map +2 -2
  32. package/dist/modules/catalog/commands/products.js +79 -54
  33. package/dist/modules/catalog/commands/products.js.map +2 -2
  34. package/dist/modules/catalog/commands/variants.js +29 -16
  35. package/dist/modules/catalog/commands/variants.js.map +2 -2
  36. package/dist/modules/currencies/commands/currencies.js +15 -8
  37. package/dist/modules/currencies/commands/currencies.js.map +2 -2
  38. package/dist/modules/customer_accounts/api/admin/users.js +27 -26
  39. package/dist/modules/customer_accounts/api/admin/users.js.map +2 -2
  40. package/dist/modules/customer_accounts/api/password/reset-confirm.js +5 -5
  41. package/dist/modules/customer_accounts/api/password/reset-confirm.js.map +2 -2
  42. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js +11 -10
  43. package/dist/modules/customer_accounts/api/portal/users/[id]/roles.js.map +2 -2
  44. package/dist/modules/customers/commands/addresses.js +35 -21
  45. package/dist/modules/customers/commands/addresses.js.map +2 -2
  46. package/dist/modules/customers/commands/companies.js +163 -162
  47. package/dist/modules/customers/commands/companies.js.map +2 -2
  48. package/dist/modules/customers/commands/deals.js +3 -4
  49. package/dist/modules/customers/commands/deals.js.map +2 -2
  50. package/dist/modules/customers/commands/interactions.js +19 -22
  51. package/dist/modules/customers/commands/interactions.js.map +2 -2
  52. package/dist/modules/customers/commands/people.js +18 -15
  53. package/dist/modules/customers/commands/people.js.map +2 -2
  54. package/dist/modules/customers/commands/personCompanyLinks.js +105 -94
  55. package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
  56. package/dist/modules/customers/commands/pipeline-stages.js +30 -23
  57. package/dist/modules/customers/commands/pipeline-stages.js.map +2 -2
  58. package/dist/modules/customers/commands/pipelines.js +27 -20
  59. package/dist/modules/customers/commands/pipelines.js.map +2 -2
  60. package/dist/modules/customers/commands/tags.js +13 -5
  61. package/dist/modules/customers/commands/tags.js.map +2 -2
  62. package/dist/modules/dashboards/api/users/widgets/route.js +0 -1
  63. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  64. package/dist/modules/dashboards/api/widgets/data/route.js +29 -1
  65. package/dist/modules/dashboards/api/widgets/data/route.js.map +2 -2
  66. package/dist/modules/data_sync/lib/sync-engine.js +4 -4
  67. package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
  68. package/dist/modules/data_sync/lib/sync-run-service.js +51 -27
  69. package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
  70. package/dist/modules/directory/commands/organizations.js +192 -158
  71. package/dist/modules/directory/commands/organizations.js.map +3 -3
  72. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js +22 -16
  73. package/dist/modules/inbox_ops/api/emails/[id]/reprocess/route.js.map +2 -2
  74. package/dist/modules/messages/commands/messages.js +77 -75
  75. package/dist/modules/messages/commands/messages.js.map +2 -2
  76. package/dist/modules/messages/commands/shared.js +132 -132
  77. package/dist/modules/messages/commands/shared.js.map +2 -2
  78. package/dist/modules/perspectives/api/[tableId]/route.js +37 -26
  79. package/dist/modules/perspectives/api/[tableId]/route.js.map +2 -2
  80. package/dist/modules/resources/commands/resources.js +125 -117
  81. package/dist/modules/resources/commands/resources.js.map +2 -2
  82. package/dist/modules/resources/commands/tags.js +7 -3
  83. package/dist/modules/resources/commands/tags.js.map +2 -2
  84. package/dist/modules/sales/api/quotes/send/route.js +12 -11
  85. package/dist/modules/sales/api/quotes/send/route.js.map +2 -2
  86. package/dist/modules/sales/commands/documents.js +629 -478
  87. package/dist/modules/sales/commands/documents.js.map +2 -2
  88. package/dist/modules/sales/commands/payments.js +146 -146
  89. package/dist/modules/sales/commands/payments.js.map +2 -2
  90. package/dist/modules/sales/commands/returns.js +68 -60
  91. package/dist/modules/sales/commands/returns.js.map +2 -2
  92. package/dist/modules/staff/acl.js +10 -1
  93. package/dist/modules/staff/acl.js.map +2 -2
  94. package/dist/modules/staff/analytics.js +33 -0
  95. package/dist/modules/staff/analytics.js.map +7 -0
  96. package/dist/modules/staff/api/guards.js +31 -0
  97. package/dist/modules/staff/api/guards.js.map +7 -0
  98. package/dist/modules/staff/api/interceptors.js +96 -0
  99. package/dist/modules/staff/api/interceptors.js.map +7 -0
  100. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js +170 -0
  101. package/dist/modules/staff/api/timesheets/my-projects/[projectId]/route.js.map +7 -0
  102. package/dist/modules/staff/api/timesheets/my-projects/route.js +103 -0
  103. package/dist/modules/staff/api/timesheets/my-projects/route.js.map +7 -0
  104. package/dist/modules/staff/api/timesheets/projects/kpis/route.js +147 -0
  105. package/dist/modules/staff/api/timesheets/projects/kpis/route.js.map +7 -0
  106. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js +171 -0
  107. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.js.map +7 -0
  108. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js +180 -0
  109. package/dist/modules/staff/api/timesheets/time-entries/[id]/segments/route.js.map +7 -0
  110. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js +155 -0
  111. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.js.map +7 -0
  112. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js +173 -0
  113. package/dist/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.js.map +7 -0
  114. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js +260 -0
  115. package/dist/modules/staff/api/timesheets/time-entries/bulk/route.js.map +7 -0
  116. package/dist/modules/staff/api/timesheets/time-entries/route.js +188 -0
  117. package/dist/modules/staff/api/timesheets/time-entries/route.js.map +7 -0
  118. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js +159 -0
  119. package/dist/modules/staff/api/timesheets/time-projects/[id]/employees/route.js.map +7 -0
  120. package/dist/modules/staff/api/timesheets/time-projects/route.js +230 -0
  121. package/dist/modules/staff/api/timesheets/time-projects/route.js.map +7 -0
  122. package/dist/modules/staff/backend/staff/timesheets/page.js +710 -0
  123. package/dist/modules/staff/backend/staff/timesheets/page.js.map +7 -0
  124. package/dist/modules/staff/backend/staff/timesheets/page.meta.js +22 -0
  125. package/dist/modules/staff/backend/staff/timesheets/page.meta.js.map +7 -0
  126. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js +125 -0
  127. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.js.map +7 -0
  128. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js +16 -0
  129. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.js.map +7 -0
  130. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js +418 -0
  131. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.js.map +7 -0
  132. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js +16 -0
  133. package/dist/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.js.map +7 -0
  134. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js +79 -0
  135. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.js.map +7 -0
  136. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js +16 -0
  137. package/dist/modules/staff/backend/staff/timesheets/projects/create/page.meta.js.map +7 -0
  138. package/dist/modules/staff/backend/staff/timesheets/projects/page.js +602 -0
  139. package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +7 -0
  140. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js +25 -0
  141. package/dist/modules/staff/backend/staff/timesheets/projects/page.meta.js.map +7 -0
  142. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js +123 -0
  143. package/dist/modules/staff/backend/staff/timesheets/projects/projectFormConfig.js.map +7 -0
  144. package/dist/modules/staff/cli.js +38 -1
  145. package/dist/modules/staff/cli.js.map +2 -2
  146. package/dist/modules/staff/commands/index.js +2 -0
  147. package/dist/modules/staff/commands/index.js.map +2 -2
  148. package/dist/modules/staff/commands/leave-requests.js +30 -28
  149. package/dist/modules/staff/commands/leave-requests.js.map +3 -3
  150. package/dist/modules/staff/commands/team-members.js +21 -20
  151. package/dist/modules/staff/commands/team-members.js.map +2 -2
  152. package/dist/modules/staff/commands/timesheets-entries.js +409 -0
  153. package/dist/modules/staff/commands/timesheets-entries.js.map +7 -0
  154. package/dist/modules/staff/commands/timesheets-projects.js +618 -0
  155. package/dist/modules/staff/commands/timesheets-projects.js.map +7 -0
  156. package/dist/modules/staff/data/enrichers.js +104 -0
  157. package/dist/modules/staff/data/enrichers.js.map +7 -0
  158. package/dist/modules/staff/data/entities.js +226 -1
  159. package/dist/modules/staff/data/entities.js.map +2 -2
  160. package/dist/modules/staff/data/validators.js +113 -1
  161. package/dist/modules/staff/data/validators.js.map +2 -2
  162. package/dist/modules/staff/events.js +13 -1
  163. package/dist/modules/staff/events.js.map +2 -2
  164. package/dist/modules/staff/lib/crud.js +7 -1
  165. package/dist/modules/staff/lib/crud.js.map +2 -2
  166. package/dist/modules/staff/lib/staffMemberResolver.js +15 -0
  167. package/dist/modules/staff/lib/staffMemberResolver.js.map +7 -0
  168. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js +60 -0
  169. package/dist/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.js.map +7 -0
  170. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js +260 -0
  171. package/dist/modules/staff/lib/timesheets-projects/computeProjectsKpis.js.map +7 -0
  172. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js +41 -0
  173. package/dist/modules/staff/lib/timesheets-projects/dateBuckets.js.map +7 -0
  174. package/dist/modules/staff/lib/timesheets-projects/initials.js +10 -0
  175. package/dist/modules/staff/lib/timesheets-projects/initials.js.map +7 -0
  176. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js +12 -0
  177. package/dist/modules/staff/lib/timesheets-projects/kpiMath.js.map +7 -0
  178. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js +55 -0
  179. package/dist/modules/staff/lib/timesheets-projects/listProjectMembersPreview.js.map +7 -0
  180. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js +66 -0
  181. package/dist/modules/staff/lib/timesheets-projects-ui/HoursSparkline.js.map +7 -0
  182. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js +81 -0
  183. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectCard.js.map +7 -0
  184. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js +58 -0
  185. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.js.map +7 -0
  186. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js +152 -0
  187. package/dist/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.js.map +7 -0
  188. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js +37 -0
  189. package/dist/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.js.map +7 -0
  190. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js +57 -0
  191. package/dist/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.js.map +7 -0
  192. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js +50 -0
  193. package/dist/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.js.map +7 -0
  194. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js +163 -0
  195. package/dist/modules/staff/lib/timesheets-ui/AddRowDropdown.js.map +7 -0
  196. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js +209 -0
  197. package/dist/modules/staff/lib/timesheets-ui/CalendarPicker.js.map +7 -0
  198. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js +52 -0
  199. package/dist/modules/staff/lib/timesheets-ui/ColorPicker.js.map +7 -0
  200. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js +77 -0
  201. package/dist/modules/staff/lib/timesheets-ui/CreateProjectDialog.js.map +7 -0
  202. package/dist/modules/staff/lib/timesheets-ui/ListView.js +173 -0
  203. package/dist/modules/staff/lib/timesheets-ui/ListView.js.map +7 -0
  204. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js +32 -0
  205. package/dist/modules/staff/lib/timesheets-ui/ProjectColorDot.js.map +7 -0
  206. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js +270 -0
  207. package/dist/modules/staff/lib/timesheets-ui/TimerBar.js.map +7 -0
  208. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js +57 -0
  209. package/dist/modules/staff/lib/timesheets-ui/ViewSwitcher.js.map +7 -0
  210. package/dist/modules/staff/lib/timesheets-ui/colors.js +43 -0
  211. package/dist/modules/staff/lib/timesheets-ui/colors.js.map +7 -0
  212. package/dist/modules/staff/migrations/Migration20260326135612.js +24 -0
  213. package/dist/modules/staff/migrations/Migration20260326135612.js.map +7 -0
  214. package/dist/modules/staff/migrations/Migration20260413102715.js +23 -0
  215. package/dist/modules/staff/migrations/Migration20260413102715.js.map +7 -0
  216. package/dist/modules/staff/migrations/Migration20260413111602.js +13 -0
  217. package/dist/modules/staff/migrations/Migration20260413111602.js.map +7 -0
  218. package/dist/modules/staff/migrations/Migration20260511112759.js +19 -0
  219. package/dist/modules/staff/migrations/Migration20260511112759.js.map +7 -0
  220. package/dist/modules/staff/search.js +35 -0
  221. package/dist/modules/staff/search.js.map +2 -2
  222. package/dist/modules/staff/setup.js +15 -1
  223. package/dist/modules/staff/setup.js.map +2 -2
  224. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js +16 -0
  225. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.js.map +7 -0
  226. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js +126 -0
  227. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.js.map +7 -0
  228. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js +26 -0
  229. package/dist/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.js.map +7 -0
  230. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js +15 -0
  231. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/config.js.map +7 -0
  232. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js +238 -0
  233. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.js.map +7 -0
  234. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js +26 -0
  235. package/dist/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.js.map +7 -0
  236. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js +145 -0
  237. package/dist/modules/staff/widgets/injection/timer-sidebar-indicator/widget.js.map +7 -0
  238. package/dist/modules/staff/widgets/injection-table.js +12 -0
  239. package/dist/modules/staff/widgets/injection-table.js.map +7 -0
  240. package/dist/modules/sync_excel/api/import/route.js +19 -17
  241. package/dist/modules/sync_excel/api/import/route.js.map +2 -2
  242. package/dist/modules/translations/commands/translations.js +22 -19
  243. package/dist/modules/translations/commands/translations.js.map +2 -2
  244. package/generated/entities/staff_time_entry/index.ts +17 -0
  245. package/generated/entities/staff_time_entry_segment/index.ts +10 -0
  246. package/generated/entities/staff_time_project/index.ts +16 -0
  247. package/generated/entities/staff_time_project_member/index.ts +13 -0
  248. package/generated/entities.ids.generated.ts +5 -1
  249. package/generated/entity-fields-registry.ts +64 -0
  250. package/package.json +7 -7
  251. package/src/helpers/integration/timesheetFixtures.ts +61 -0
  252. package/src/modules/attachments/api/library/[id]/route.ts +24 -17
  253. package/src/modules/attachments/api/route.ts +20 -14
  254. package/src/modules/auth/api/roles/acl/route.ts +11 -5
  255. package/src/modules/auth/api/sidebar/preferences/route.ts +33 -24
  256. package/src/modules/auth/api/users/acl/route.ts +17 -12
  257. package/src/modules/auth/commands/users.ts +96 -80
  258. package/src/modules/auth/services/sidebarPreferencesService.ts +40 -32
  259. package/src/modules/catalog/commands/categories.ts +61 -12
  260. package/src/modules/catalog/commands/products.ts +93 -60
  261. package/src/modules/catalog/commands/variants.ts +29 -16
  262. package/src/modules/currencies/commands/currencies.ts +27 -14
  263. package/src/modules/customer_accounts/api/admin/users.ts +31 -26
  264. package/src/modules/customer_accounts/api/password/reset-confirm.ts +5 -6
  265. package/src/modules/customer_accounts/api/portal/users/[id]/roles.ts +14 -13
  266. package/src/modules/customers/commands/addresses.ts +35 -23
  267. package/src/modules/customers/commands/companies.ts +166 -165
  268. package/src/modules/customers/commands/deals.ts +2 -4
  269. package/src/modules/customers/commands/interactions.ts +20 -26
  270. package/src/modules/customers/commands/people.ts +18 -15
  271. package/src/modules/customers/commands/personCompanyLinks.ts +109 -100
  272. package/src/modules/customers/commands/pipeline-stages.ts +31 -27
  273. package/src/modules/customers/commands/pipelines.ts +29 -23
  274. package/src/modules/customers/commands/tags.ts +13 -5
  275. package/src/modules/dashboards/api/users/widgets/route.ts +0 -1
  276. package/src/modules/dashboards/api/widgets/data/route.ts +36 -1
  277. package/src/modules/data_sync/lib/sync-engine.ts +4 -5
  278. package/src/modules/data_sync/lib/sync-run-service.ts +57 -28
  279. package/src/modules/directory/commands/organizations.ts +203 -166
  280. package/src/modules/inbox_ops/api/emails/[id]/reprocess/route.ts +26 -18
  281. package/src/modules/messages/commands/messages.ts +82 -80
  282. package/src/modules/messages/commands/shared.ts +138 -133
  283. package/src/modules/perspectives/api/[tableId]/route.ts +38 -27
  284. package/src/modules/resources/commands/resources.ts +127 -117
  285. package/src/modules/resources/commands/tags.ts +7 -3
  286. package/src/modules/sales/api/quotes/send/route.ts +17 -12
  287. package/src/modules/sales/commands/documents.ts +673 -481
  288. package/src/modules/sales/commands/payments.ts +158 -152
  289. package/src/modules/sales/commands/returns.ts +74 -63
  290. package/src/modules/staff/acl.ts +11 -0
  291. package/src/modules/staff/analytics.ts +30 -0
  292. package/src/modules/staff/api/guards.ts +59 -0
  293. package/src/modules/staff/api/interceptors.ts +122 -0
  294. package/src/modules/staff/api/timesheets/my-projects/[projectId]/route.ts +191 -0
  295. package/src/modules/staff/api/timesheets/my-projects/route.ts +115 -0
  296. package/src/modules/staff/api/timesheets/projects/kpis/route.ts +159 -0
  297. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/[segmentId]/route.ts +187 -0
  298. package/src/modules/staff/api/timesheets/time-entries/[id]/segments/route.ts +191 -0
  299. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-start/route.ts +168 -0
  300. package/src/modules/staff/api/timesheets/time-entries/[id]/timer-stop/route.ts +191 -0
  301. package/src/modules/staff/api/timesheets/time-entries/bulk/route.ts +292 -0
  302. package/src/modules/staff/api/timesheets/time-entries/route.ts +193 -0
  303. package/src/modules/staff/api/timesheets/time-projects/[id]/employees/route.ts +167 -0
  304. package/src/modules/staff/api/timesheets/time-projects/route.ts +244 -0
  305. package/src/modules/staff/backend/staff/timesheets/page.meta.ts +20 -0
  306. package/src/modules/staff/backend/staff/timesheets/page.tsx +899 -0
  307. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.meta.ts +12 -0
  308. package/src/modules/staff/backend/staff/timesheets/projects/[id]/edit/page.tsx +141 -0
  309. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.meta.ts +12 -0
  310. package/src/modules/staff/backend/staff/timesheets/projects/[id]/page.tsx +579 -0
  311. package/src/modules/staff/backend/staff/timesheets/projects/create/page.meta.ts +12 -0
  312. package/src/modules/staff/backend/staff/timesheets/projects/create/page.tsx +90 -0
  313. package/src/modules/staff/backend/staff/timesheets/projects/page.meta.ts +23 -0
  314. package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +765 -0
  315. package/src/modules/staff/backend/staff/timesheets/projects/projectFormConfig.ts +138 -0
  316. package/src/modules/staff/cli.ts +40 -1
  317. package/src/modules/staff/commands/index.ts +2 -0
  318. package/src/modules/staff/commands/leave-requests.ts +37 -29
  319. package/src/modules/staff/commands/team-members.ts +25 -20
  320. package/src/modules/staff/commands/timesheets-entries.ts +504 -0
  321. package/src/modules/staff/commands/timesheets-projects.ts +699 -0
  322. package/src/modules/staff/data/enrichers.ts +134 -0
  323. package/src/modules/staff/data/entities.ts +198 -0
  324. package/src/modules/staff/data/validators.ts +129 -0
  325. package/src/modules/staff/events.ts +13 -0
  326. package/src/modules/staff/i18n/de.json +209 -1
  327. package/src/modules/staff/i18n/en.json +209 -1
  328. package/src/modules/staff/i18n/es.json +209 -1
  329. package/src/modules/staff/i18n/pl.json +209 -1
  330. package/src/modules/staff/lib/crud.ts +8 -0
  331. package/src/modules/staff/lib/staffMemberResolver.ts +22 -0
  332. package/src/modules/staff/lib/timesheets-projects/computeProjectHoursTrend.ts +89 -0
  333. package/src/modules/staff/lib/timesheets-projects/computeProjectsKpis.ts +311 -0
  334. package/src/modules/staff/lib/timesheets-projects/dateBuckets.ts +37 -0
  335. package/src/modules/staff/lib/timesheets-projects/initials.ts +6 -0
  336. package/src/modules/staff/lib/timesheets-projects/kpiMath.ts +8 -0
  337. package/src/modules/staff/lib/timesheets-projects/listProjectMembersPreview.ts +83 -0
  338. package/src/modules/staff/lib/timesheets-projects-ui/HoursSparkline.tsx +75 -0
  339. package/src/modules/staff/lib/timesheets-projects-ui/ProjectCard.tsx +110 -0
  340. package/src/modules/staff/lib/timesheets-projects-ui/ProjectMembersAvatarStack.tsx +73 -0
  341. package/src/modules/staff/lib/timesheets-projects-ui/ProjectsKpiStrip.tsx +185 -0
  342. package/src/modules/staff/lib/timesheets-projects-ui/SavedViewTabs.tsx +53 -0
  343. package/src/modules/staff/lib/timesheets-projects-ui/ViewModeToggle.tsx +63 -0
  344. package/src/modules/staff/lib/timesheets-projects-ui/useProjectsViewMode.ts +63 -0
  345. package/src/modules/staff/lib/timesheets-ui/AddRowDropdown.tsx +188 -0
  346. package/src/modules/staff/lib/timesheets-ui/CalendarPicker.tsx +229 -0
  347. package/src/modules/staff/lib/timesheets-ui/ColorPicker.tsx +65 -0
  348. package/src/modules/staff/lib/timesheets-ui/CreateProjectDialog.tsx +99 -0
  349. package/src/modules/staff/lib/timesheets-ui/ListView.tsx +230 -0
  350. package/src/modules/staff/lib/timesheets-ui/ProjectColorDot.tsx +40 -0
  351. package/src/modules/staff/lib/timesheets-ui/TimerBar.tsx +327 -0
  352. package/src/modules/staff/lib/timesheets-ui/ViewSwitcher.tsx +60 -0
  353. package/src/modules/staff/lib/timesheets-ui/colors.ts +58 -0
  354. package/src/modules/staff/migrations/.snapshot-open-mercato.json +1148 -0
  355. package/src/modules/staff/migrations/Migration20260326135612.ts +26 -0
  356. package/src/modules/staff/migrations/Migration20260413102715.ts +25 -0
  357. package/src/modules/staff/migrations/Migration20260413111602.ts +13 -0
  358. package/src/modules/staff/migrations/Migration20260511112759.ts +21 -0
  359. package/src/modules/staff/search.ts +35 -0
  360. package/src/modules/staff/setup.ts +15 -0
  361. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/config.ts +17 -0
  362. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.client.tsx +158 -0
  363. package/src/modules/staff/widgets/dashboard/timesheets-hours-by-project/widget.ts +25 -0
  364. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/config.ts +15 -0
  365. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.client.tsx +297 -0
  366. package/src/modules/staff/widgets/dashboard/timesheets-time-reporting/widget.ts +25 -0
  367. package/src/modules/staff/widgets/injection/timer-sidebar-indicator/widget.tsx +161 -0
  368. package/src/modules/staff/widgets/injection-table.ts +10 -0
  369. package/src/modules/sync_excel/api/import/route.ts +23 -18
  370. package/src/modules/translations/commands/translations.ts +49 -41
@@ -0,0 +1,73 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+
5
+ export type AvatarMember = {
6
+ id: string
7
+ name: string
8
+ initials: string
9
+ avatarUrl?: string | null
10
+ }
11
+
12
+ export type ProjectMembersAvatarStackProps = {
13
+ members: AvatarMember[]
14
+ total: number
15
+ peopleCountLabel: string
16
+ className?: string
17
+ }
18
+
19
+ const AVATAR_PALETTE = [
20
+ 'bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-200',
21
+ 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-200',
22
+ 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200',
23
+ 'bg-rose-100 text-rose-800 dark:bg-rose-900/40 dark:text-rose-200',
24
+ 'bg-violet-100 text-violet-800 dark:bg-violet-900/40 dark:text-violet-200',
25
+ 'bg-cyan-100 text-cyan-800 dark:bg-cyan-900/40 dark:text-cyan-200',
26
+ ]
27
+
28
+ function pickPalette(id: string): string {
29
+ let hash = 0
30
+ for (let i = 0; i < id.length; i++) {
31
+ hash = (hash * 31 + id.charCodeAt(i)) | 0
32
+ }
33
+ return AVATAR_PALETTE[Math.abs(hash) % AVATAR_PALETTE.length]
34
+ }
35
+
36
+ export function ProjectMembersAvatarStack({
37
+ members,
38
+ total,
39
+ peopleCountLabel,
40
+ className,
41
+ }: ProjectMembersAvatarStackProps) {
42
+ const visible = members.slice(0, 4)
43
+ const overflow = Math.max(0, total - visible.length)
44
+
45
+ if (total === 0) {
46
+ return <span className={`text-xs text-muted-foreground ${className ?? ''}`}>—</span>
47
+ }
48
+
49
+ return (
50
+ <div className={`flex items-center gap-2 ${className ?? ''}`}>
51
+ <div className="flex -space-x-1.5">
52
+ {visible.map((member) => (
53
+ <span
54
+ key={member.id}
55
+ title={member.name}
56
+ className={`inline-flex h-6 w-6 items-center justify-center rounded-full border border-background text-[10px] font-semibold ${pickPalette(member.id)}`}
57
+ >
58
+ {member.initials}
59
+ </span>
60
+ ))}
61
+ {overflow > 0 ? (
62
+ <span
63
+ className="inline-flex h-6 w-6 items-center justify-center rounded-full border border-background bg-muted text-[10px] font-semibold text-foreground"
64
+ title={`+${overflow}`}
65
+ >
66
+ +{overflow}
67
+ </span>
68
+ ) : null}
69
+ </div>
70
+ <span className="text-xs text-muted-foreground">{peopleCountLabel}</span>
71
+ </div>
72
+ )
73
+ }
@@ -0,0 +1,185 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { ArrowDownRight, ArrowUpRight, Minus } from 'lucide-react'
5
+
6
+ type Delta = { current: number; previous: number; deltaPct: number | null }
7
+
8
+ export type PmKpis = {
9
+ role: 'pm'
10
+ totals: { total: number; active: number; onHold: number; completed: number }
11
+ hoursWeek: Delta
12
+ hoursMonth: Delta
13
+ teamActive: { count: number }
14
+ assignedToMe: { total: number; active: number }
15
+ }
16
+
17
+ export type CollabKpis = {
18
+ role: 'collab'
19
+ myProjects: { total: number; active: number }
20
+ myHoursWeek: Delta
21
+ myHoursMonth: Delta
22
+ }
23
+
24
+ type KpiLabels = {
25
+ totalProjects: string
26
+ totalProjectsSub: (args: { active: number; onHold: number }) => string
27
+ hoursWeek: string
28
+ hoursWeekSub: string
29
+ assignedToMe: string
30
+ assignedToMeSub: (active: number) => string
31
+ hoursMonth: string
32
+ hoursMonthSub: string
33
+ teamActive: string
34
+ teamActiveSub: string
35
+ myProjects: string
36
+ myProjectsSub: (active: number) => string
37
+ myHoursWeek: string
38
+ myHoursMonth: string
39
+ deltaUp: (pct: number) => string
40
+ deltaDown: (pct: number) => string
41
+ deltaFlat: string
42
+ noPrevious: string
43
+ }
44
+
45
+ function DeltaBadge({ pct, labels }: { pct: number | null; labels: KpiLabels }) {
46
+ if (pct === null) {
47
+ return <span className="text-[11px] text-muted-foreground/70">{labels.noPrevious}</span>
48
+ }
49
+ if (pct > 0) {
50
+ return (
51
+ <span
52
+ className="inline-flex items-center gap-0.5 text-[11px] font-medium text-emerald-600 tabular-nums"
53
+ aria-label={labels.deltaUp(pct)}
54
+ >
55
+ <ArrowUpRight className="h-3 w-3" aria-hidden="true" />
56
+ {pct}%
57
+ </span>
58
+ )
59
+ }
60
+ if (pct < 0) {
61
+ return (
62
+ <span
63
+ className="inline-flex items-center gap-0.5 text-[11px] font-medium text-rose-600 tabular-nums"
64
+ aria-label={labels.deltaDown(Math.abs(pct))}
65
+ >
66
+ <ArrowDownRight className="h-3 w-3" aria-hidden="true" />
67
+ {Math.abs(pct)}%
68
+ </span>
69
+ )
70
+ }
71
+ return (
72
+ <span
73
+ className="inline-flex items-center gap-0.5 text-[11px] text-muted-foreground/70"
74
+ aria-label={labels.deltaFlat}
75
+ >
76
+ <Minus className="h-3 w-3" aria-hidden="true" />
77
+ 0%
78
+ </span>
79
+ )
80
+ }
81
+
82
+ function KpiCard({
83
+ label,
84
+ value,
85
+ subtext,
86
+ delta,
87
+ labels,
88
+ }: {
89
+ label: string
90
+ value: React.ReactNode
91
+ subtext?: string
92
+ delta?: Delta
93
+ labels: KpiLabels
94
+ }) {
95
+ return (
96
+ <div className="flex flex-col gap-1 rounded-lg border border-border bg-card p-4">
97
+ <div className="flex items-center justify-between gap-2">
98
+ <p className="text-[11px] uppercase tracking-wide text-muted-foreground">{label}</p>
99
+ {delta ? <DeltaBadge pct={delta.deltaPct} labels={labels} /> : null}
100
+ </div>
101
+ <p className="text-2xl font-semibold tabular-nums text-foreground">{value}</p>
102
+ {subtext ? <p className="text-xs text-muted-foreground">{subtext}</p> : null}
103
+ </div>
104
+ )
105
+ }
106
+
107
+ export type ProjectsKpiStripProps = {
108
+ kpis: PmKpis | CollabKpis | null
109
+ labels: KpiLabels
110
+ isLoading?: boolean
111
+ }
112
+
113
+ export function ProjectsKpiStrip({ kpis, labels, isLoading }: ProjectsKpiStripProps) {
114
+ if (isLoading || !kpis) {
115
+ return (
116
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-5">
117
+ {Array.from({ length: 5 }).map((_, idx) => (
118
+ <div key={idx} className="h-[88px] animate-pulse rounded-lg border border-border bg-muted/40" />
119
+ ))}
120
+ </div>
121
+ )
122
+ }
123
+
124
+ if (kpis.role === 'pm') {
125
+ return (
126
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-5">
127
+ <KpiCard
128
+ label={labels.totalProjects}
129
+ value={kpis.totals.total}
130
+ subtext={labels.totalProjectsSub({ active: kpis.totals.active, onHold: kpis.totals.onHold })}
131
+ labels={labels}
132
+ />
133
+ <KpiCard
134
+ label={labels.hoursWeek}
135
+ value={`${kpis.hoursWeek.current}h`}
136
+ subtext={labels.hoursWeekSub}
137
+ delta={kpis.hoursWeek}
138
+ labels={labels}
139
+ />
140
+ <KpiCard
141
+ label={labels.hoursMonth}
142
+ value={`${kpis.hoursMonth.current}h`}
143
+ subtext={labels.hoursMonthSub}
144
+ delta={kpis.hoursMonth}
145
+ labels={labels}
146
+ />
147
+ <KpiCard
148
+ label={labels.assignedToMe}
149
+ value={kpis.assignedToMe.total}
150
+ subtext={labels.assignedToMeSub(kpis.assignedToMe.active)}
151
+ labels={labels}
152
+ />
153
+ <KpiCard
154
+ label={labels.teamActive}
155
+ value={kpis.teamActive.count}
156
+ subtext={labels.teamActiveSub}
157
+ labels={labels}
158
+ />
159
+ </div>
160
+ )
161
+ }
162
+
163
+ return (
164
+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
165
+ <KpiCard
166
+ label={labels.myProjects}
167
+ value={kpis.myProjects.total}
168
+ subtext={labels.myProjectsSub(kpis.myProjects.active)}
169
+ labels={labels}
170
+ />
171
+ <KpiCard
172
+ label={labels.myHoursWeek}
173
+ value={`${kpis.myHoursWeek.current}h`}
174
+ delta={kpis.myHoursWeek}
175
+ labels={labels}
176
+ />
177
+ <KpiCard
178
+ label={labels.myHoursMonth}
179
+ value={`${kpis.myHoursMonth.current}h`}
180
+ delta={kpis.myHoursMonth}
181
+ labels={labels}
182
+ />
183
+ </div>
184
+ )
185
+ }
@@ -0,0 +1,53 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { Button } from '@open-mercato/ui/primitives/button'
5
+
6
+ export type SavedViewTab = {
7
+ id: string
8
+ label: string
9
+ count?: number
10
+ }
11
+
12
+ export type SavedViewTabsProps = {
13
+ tabs: SavedViewTab[]
14
+ activeId: string
15
+ onSelect: (id: string) => void
16
+ className?: string
17
+ ariaLabel?: string
18
+ }
19
+
20
+ export function SavedViewTabs({ tabs, activeId, onSelect, className, ariaLabel }: SavedViewTabsProps) {
21
+ return (
22
+ <div
23
+ role="tablist"
24
+ aria-label={ariaLabel ?? 'Saved views'}
25
+ className={`flex items-center gap-1 border-b border-border ${className ?? ''}`}
26
+ >
27
+ {tabs.map((tab) => {
28
+ const isActive = tab.id === activeId
29
+ return (
30
+ <Button
31
+ key={tab.id}
32
+ type="button"
33
+ variant="ghost"
34
+ size="sm"
35
+ role="tab"
36
+ aria-selected={isActive}
37
+ className={`h-auto rounded-none px-3 py-2 text-sm hover:bg-transparent ${
38
+ isActive
39
+ ? 'border-b-2 border-foreground font-medium text-foreground'
40
+ : 'border-b-2 border-transparent text-muted-foreground hover:text-foreground'
41
+ }`}
42
+ onClick={() => onSelect(tab.id)}
43
+ >
44
+ {tab.label}
45
+ {typeof tab.count === 'number' ? (
46
+ <span className="ml-1.5 text-xs text-muted-foreground/70 tabular-nums">{tab.count}</span>
47
+ ) : null}
48
+ </Button>
49
+ )
50
+ })}
51
+ </div>
52
+ )
53
+ }
@@ -0,0 +1,63 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { LayoutGrid, List } from 'lucide-react'
5
+ import { Button } from '@open-mercato/ui/primitives/button'
6
+ import type { ProjectsViewMode } from './useProjectsViewMode'
7
+
8
+ export type ViewModeToggleProps = {
9
+ mode: ProjectsViewMode
10
+ onChange: (mode: ProjectsViewMode) => void
11
+ tableLabel: string
12
+ cardsLabel: string
13
+ className?: string
14
+ ariaLabel?: string
15
+ }
16
+
17
+ export function ViewModeToggle({
18
+ mode,
19
+ onChange,
20
+ tableLabel,
21
+ cardsLabel,
22
+ className,
23
+ ariaLabel,
24
+ }: ViewModeToggleProps) {
25
+ return (
26
+ <div
27
+ role="group"
28
+ aria-label={ariaLabel ?? 'View mode'}
29
+ className={`inline-flex items-center rounded-md border border-border p-0.5 ${className ?? ''}`}
30
+ >
31
+ <Button
32
+ type="button"
33
+ variant="ghost"
34
+ size="sm"
35
+ aria-pressed={mode === 'table'}
36
+ className={`h-auto gap-1.5 px-2.5 py-1 text-xs ${
37
+ mode === 'table'
38
+ ? 'bg-foreground text-background hover:bg-foreground'
39
+ : 'text-muted-foreground hover:bg-muted'
40
+ }`}
41
+ onClick={() => onChange('table')}
42
+ >
43
+ <List className="h-3.5 w-3.5" aria-hidden="true" />
44
+ {tableLabel}
45
+ </Button>
46
+ <Button
47
+ type="button"
48
+ variant="ghost"
49
+ size="sm"
50
+ aria-pressed={mode === 'cards'}
51
+ className={`h-auto gap-1.5 px-2.5 py-1 text-xs ${
52
+ mode === 'cards'
53
+ ? 'bg-foreground text-background hover:bg-foreground'
54
+ : 'text-muted-foreground hover:bg-muted'
55
+ }`}
56
+ onClick={() => onChange('cards')}
57
+ >
58
+ <LayoutGrid className="h-3.5 w-3.5" aria-hidden="true" />
59
+ {cardsLabel}
60
+ </Button>
61
+ </div>
62
+ )
63
+ }
@@ -0,0 +1,63 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+
5
+ export type ProjectsViewMode = 'table' | 'cards'
6
+
7
+ const STORAGE_KEY_PREFIX = 'staff.timesheets.projects.viewMode'
8
+
9
+ function storageKey(userKey: string | null | undefined): string {
10
+ return userKey ? `${STORAGE_KEY_PREFIX}:${userKey}` : STORAGE_KEY_PREFIX
11
+ }
12
+
13
+ function readStoredMode(userKey: string | null | undefined): ProjectsViewMode | null {
14
+ if (typeof window === 'undefined') return null
15
+ try {
16
+ const raw = window.localStorage.getItem(storageKey(userKey))
17
+ return raw === 'cards' || raw === 'table' ? raw : null
18
+ } catch {
19
+ return null
20
+ }
21
+ }
22
+
23
+ function writeStoredMode(userKey: string | null | undefined, mode: ProjectsViewMode): void {
24
+ if (typeof window === 'undefined') return
25
+ try {
26
+ window.localStorage.setItem(storageKey(userKey), mode)
27
+ } catch {
28
+ // ignore — quota errors etc. are non-critical
29
+ }
30
+ }
31
+
32
+ export function useProjectsViewMode({
33
+ userKey,
34
+ urlOverride,
35
+ fallback = 'table',
36
+ }: {
37
+ userKey: string | null | undefined
38
+ urlOverride?: string | null
39
+ fallback?: ProjectsViewMode
40
+ }): [ProjectsViewMode, (next: ProjectsViewMode) => void] {
41
+ const initial = React.useMemo<ProjectsViewMode>(() => {
42
+ if (urlOverride === 'cards' || urlOverride === 'table') return urlOverride
43
+ return readStoredMode(userKey) ?? fallback
44
+ }, [urlOverride, userKey, fallback])
45
+
46
+ const [mode, setMode] = React.useState<ProjectsViewMode>(initial)
47
+
48
+ React.useEffect(() => {
49
+ if (urlOverride === 'cards' || urlOverride === 'table') {
50
+ setMode(urlOverride)
51
+ }
52
+ }, [urlOverride])
53
+
54
+ const update = React.useCallback(
55
+ (next: ProjectsViewMode) => {
56
+ setMode(next)
57
+ writeStoredMode(userKey, next)
58
+ },
59
+ [userKey],
60
+ )
61
+
62
+ return [mode, update]
63
+ }
@@ -0,0 +1,188 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import { createPortal } from 'react-dom'
5
+ import { Button } from '@open-mercato/ui/primitives/button'
6
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
7
+ import { Plus, Search } from 'lucide-react'
8
+ import { ProjectColorDot } from './ProjectColorDot'
9
+
10
+ type ProjectOption = {
11
+ id: string
12
+ name: string
13
+ code: string | null
14
+ color?: string | null
15
+ }
16
+
17
+ type AddRowDropdownProps = {
18
+ assignedProjects: ProjectOption[]
19
+ visibleProjectIds: Set<string>
20
+ canCreateProject: boolean
21
+ onAddProject: (project: ProjectOption) => void
22
+ onCreateProject: () => void
23
+ }
24
+
25
+ const DROPDOWN_WIDTH = 280
26
+ const DROPDOWN_OFFSET = 4
27
+
28
+ export function AddRowDropdown({
29
+ assignedProjects,
30
+ visibleProjectIds,
31
+ canCreateProject,
32
+ onAddProject,
33
+ onCreateProject,
34
+ }: AddRowDropdownProps) {
35
+ const t = useT()
36
+ const [open, setOpen] = React.useState(false)
37
+ const [search, setSearch] = React.useState('')
38
+ const [position, setPosition] = React.useState<{ top: number; left: number } | null>(null)
39
+ const triggerRef = React.useRef<HTMLDivElement>(null)
40
+ const dropdownRef = React.useRef<HTMLDivElement>(null)
41
+ const searchInputRef = React.useRef<HTMLInputElement>(null)
42
+
43
+ const availableProjects = assignedProjects.filter(
44
+ (project) => !visibleProjectIds.has(project.id),
45
+ )
46
+
47
+ const filteredProjects = availableProjects.filter((project) =>
48
+ project.name.toLowerCase().includes(search.toLowerCase()),
49
+ )
50
+
51
+ React.useLayoutEffect(() => {
52
+ if (!open) return
53
+ const updatePosition = () => {
54
+ const node = triggerRef.current
55
+ if (!node) return
56
+ const rect = node.getBoundingClientRect()
57
+ const left = Math.max(8, Math.min(rect.left, window.innerWidth - DROPDOWN_WIDTH - 8))
58
+ setPosition({ top: rect.bottom + DROPDOWN_OFFSET, left })
59
+ }
60
+ updatePosition()
61
+ window.addEventListener('scroll', updatePosition, true)
62
+ window.addEventListener('resize', updatePosition)
63
+ return () => {
64
+ window.removeEventListener('scroll', updatePosition, true)
65
+ window.removeEventListener('resize', updatePosition)
66
+ }
67
+ }, [open])
68
+
69
+ React.useEffect(() => {
70
+ if (!open) return
71
+ function handleClickOutside(event: MouseEvent) {
72
+ const target = event.target as Node
73
+ if (
74
+ triggerRef.current && !triggerRef.current.contains(target) &&
75
+ dropdownRef.current && !dropdownRef.current.contains(target)
76
+ ) {
77
+ setOpen(false)
78
+ setSearch('')
79
+ }
80
+ }
81
+ function handleKeyDown(event: KeyboardEvent) {
82
+ if (event.key === 'Escape') {
83
+ setOpen(false)
84
+ setSearch('')
85
+ }
86
+ }
87
+ document.addEventListener('mousedown', handleClickOutside)
88
+ document.addEventListener('keydown', handleKeyDown)
89
+ return () => {
90
+ document.removeEventListener('mousedown', handleClickOutside)
91
+ document.removeEventListener('keydown', handleKeyDown)
92
+ }
93
+ }, [open])
94
+
95
+ React.useEffect(() => {
96
+ if (open && searchInputRef.current) {
97
+ searchInputRef.current.focus()
98
+ }
99
+ }, [open])
100
+
101
+ function handleToggle() {
102
+ setOpen((prev) => !prev)
103
+ setSearch('')
104
+ }
105
+
106
+ function handleSelectProject(project: ProjectOption) {
107
+ onAddProject(project)
108
+ setOpen(false)
109
+ setSearch('')
110
+ }
111
+
112
+ function handleCreateProject() {
113
+ onCreateProject()
114
+ setOpen(false)
115
+ setSearch('')
116
+ }
117
+
118
+ const dropdown = open && position && typeof document !== 'undefined' ? createPortal(
119
+ <div
120
+ ref={dropdownRef}
121
+ className="fixed z-50 rounded-lg border bg-popover shadow-lg"
122
+ style={{ top: position.top, left: position.left, width: DROPDOWN_WIDTH }}
123
+ >
124
+ <div className="flex items-center border-b px-3">
125
+ <Search className="h-4 w-4 text-muted-foreground shrink-0" />
126
+ <input
127
+ ref={searchInputRef}
128
+ type="text"
129
+ className="w-full px-3 py-2 text-sm bg-transparent outline-none placeholder:text-muted-foreground"
130
+ placeholder={t('staff.timesheets.my.addRow.searchPlaceholder', 'Search by project')}
131
+ value={search}
132
+ onChange={(event) => setSearch(event.target.value)}
133
+ />
134
+ </div>
135
+
136
+ <div className="max-h-[200px] overflow-y-auto">
137
+ {filteredProjects.length === 0 ? (
138
+ <div className="px-3 py-4 text-sm text-muted-foreground text-center">
139
+ {t('staff.timesheets.my.addRow.noProjects', 'No projects assigned')}
140
+ </div>
141
+ ) : (
142
+ filteredProjects.map((project) => (
143
+ <Button
144
+ key={project.id}
145
+ type="button"
146
+ variant="ghost"
147
+ className="w-full justify-start rounded-none px-3 py-2 text-sm cursor-pointer hover:bg-muted transition-colors"
148
+ onClick={() => handleSelectProject(project)}
149
+ >
150
+ <ProjectColorDot colorKey={project.color} projectName={project.name} size="sm" />
151
+ <span className="ml-1.5">{project.name}</span>
152
+ </Button>
153
+ ))
154
+ )}
155
+ </div>
156
+
157
+ {canCreateProject && (
158
+ <Button
159
+ type="button"
160
+ variant="ghost"
161
+ className="w-full justify-start rounded-none px-3 py-2 text-sm text-primary cursor-pointer hover:bg-muted border-t"
162
+ onClick={handleCreateProject}
163
+ >
164
+ <Plus className="h-4 w-4 mr-1" />
165
+ {t('staff.timesheets.my.addRow.createProject', 'Create a new project')}
166
+ </Button>
167
+ )}
168
+ </div>,
169
+ document.body,
170
+ ) : null
171
+
172
+ return (
173
+ <>
174
+ <div ref={triggerRef} className="inline-block">
175
+ <Button
176
+ type="button"
177
+ variant="ghost"
178
+ className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground cursor-pointer px-3 py-2"
179
+ onClick={handleToggle}
180
+ >
181
+ <Plus className="h-4 w-4" />
182
+ {t('staff.timesheets.my.addRow.trigger', 'Add row')}
183
+ </Button>
184
+ </div>
185
+ {dropdown}
186
+ </>
187
+ )
188
+ }