@open-mercato/core 0.6.4-develop.4210.1.d412061cfe → 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,765 @@
1
+ "use client"
2
+
3
+ import * as React from 'react'
4
+ import Link from 'next/link'
5
+ import { useRouter, useSearchParams } from 'next/navigation'
6
+ import type { ColumnDef, SortingState } from '@tanstack/react-table'
7
+ import { Page, PageBody } from '@open-mercato/ui/backend/Page'
8
+ import { DataTable, withDataTableNamespaces } from '@open-mercato/ui/backend/DataTable'
9
+ import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterOverlay'
10
+ import { RowActions } from '@open-mercato/ui/backend/RowActions'
11
+ import { Button } from '@open-mercato/ui/primitives/button'
12
+ import { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'
13
+ import { deleteCrud } from '@open-mercato/ui/backend/utils/crud'
14
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
15
+ import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
16
+ import { useOrganizationScopeVersion } from '@open-mercato/shared/lib/frontend/useOrganizationScope'
17
+ import { useT, type TranslateFn } from '@open-mercato/shared/lib/i18n/context'
18
+ import { formatDateTime } from '@open-mercato/shared/lib/time'
19
+ import { ProjectColorDot } from '../../../../lib/timesheets-ui/ProjectColorDot'
20
+ import { resolveProjectColorHex } from '../../../../lib/timesheets-ui/colors'
21
+ import {
22
+ ProjectsKpiStrip,
23
+ type PmKpis,
24
+ type CollabKpis,
25
+ } from '../../../../lib/timesheets-projects-ui/ProjectsKpiStrip'
26
+ import { SavedViewTabs } from '../../../../lib/timesheets-projects-ui/SavedViewTabs'
27
+ import { HoursSparkline } from '../../../../lib/timesheets-projects-ui/HoursSparkline'
28
+ import {
29
+ ProjectMembersAvatarStack,
30
+ type AvatarMember,
31
+ } from '../../../../lib/timesheets-projects-ui/ProjectMembersAvatarStack'
32
+ import { ViewModeToggle } from '../../../../lib/timesheets-projects-ui/ViewModeToggle'
33
+ import {
34
+ useProjectsViewMode,
35
+ type ProjectsViewMode,
36
+ } from '../../../../lib/timesheets-projects-ui/useProjectsViewMode'
37
+ import {
38
+ ProjectCard,
39
+ type ProjectCardData,
40
+ type ProjectCardLabels,
41
+ } from '../../../../lib/timesheets-projects-ui/ProjectCard'
42
+
43
+ const PAGE_SIZE = 50
44
+ const INCLUDE_FIELDS = 'hoursWeek,hoursTrend,members,myRole'
45
+
46
+ type StaffEnrichment = {
47
+ hoursWeek?: number
48
+ hoursTrend?: number[]
49
+ myRole?: string | null
50
+ members?: AvatarMember[]
51
+ memberCount?: number
52
+ }
53
+
54
+ type ProjectRow = {
55
+ id: string
56
+ name: string
57
+ code: string | null
58
+ customerId: string | null
59
+ customerName: string | null
60
+ status: string
61
+ projectType: string | null
62
+ color: string | null
63
+ startDate: string | null
64
+ updatedAt: string | null
65
+ hoursWeek: number
66
+ hoursTrend: number[]
67
+ myRole: string | null
68
+ members: AvatarMember[]
69
+ memberCount: number
70
+ }
71
+
72
+ type ProjectsResponse = {
73
+ items?: Array<Record<string, unknown>>
74
+ total?: number
75
+ totalPages?: number
76
+ }
77
+
78
+ type KpisResponse = PmKpis | CollabKpis
79
+
80
+ function formatRelativeTime(iso: string | null, fallback: string, t: TranslateFn): string {
81
+ if (!iso) return fallback
82
+ const parsed = new Date(iso)
83
+ if (Number.isNaN(parsed.getTime())) return fallback
84
+ const diffMs = Date.now() - parsed.getTime()
85
+ const minutes = Math.round(diffMs / 60000)
86
+ if (minutes < 1) return t('staff.timesheets.projects.portfolio.relativeTime.justNow', 'just now')
87
+ if (minutes < 60) return t('staff.timesheets.projects.portfolio.relativeTime.minutesAgo', '{minutes}m ago', { minutes })
88
+ const hours = Math.round(minutes / 60)
89
+ if (hours < 24) return t('staff.timesheets.projects.portfolio.relativeTime.hoursAgo', '{hours}h ago', { hours })
90
+ const days = Math.round(hours / 24)
91
+ if (days < 14) return t('staff.timesheets.projects.portfolio.relativeTime.daysAgo', '{days}d ago', { days })
92
+ return formatDateTime(iso) ?? fallback
93
+ }
94
+
95
+ function mapApiProject(item: Record<string, unknown>): ProjectRow {
96
+ const id = typeof item.id === 'string' ? item.id : ''
97
+ const name = typeof item.name === 'string' ? item.name : id
98
+ const code = typeof item.code === 'string' && item.code.trim().length ? item.code.trim() : null
99
+ const customerId =
100
+ typeof item.customerId === 'string'
101
+ ? item.customerId
102
+ : typeof item.customer_id === 'string'
103
+ ? item.customer_id
104
+ : null
105
+ const customerName =
106
+ typeof item.customerName === 'string'
107
+ ? item.customerName
108
+ : typeof item.customer_name === 'string'
109
+ ? item.customer_name
110
+ : null
111
+ const status = typeof item.status === 'string' ? item.status : 'active'
112
+ const projectType =
113
+ typeof item.projectType === 'string'
114
+ ? item.projectType
115
+ : typeof item.project_type === 'string'
116
+ ? item.project_type
117
+ : null
118
+ const color = typeof item.color === 'string' ? item.color : null
119
+ const startDate =
120
+ typeof item.startDate === 'string'
121
+ ? item.startDate
122
+ : typeof item.start_date === 'string'
123
+ ? item.start_date
124
+ : null
125
+ const updatedAt =
126
+ typeof item.updatedAt === 'string'
127
+ ? item.updatedAt
128
+ : typeof item.updated_at === 'string'
129
+ ? item.updated_at
130
+ : null
131
+ const enrichment =
132
+ (item as { _staff?: StaffEnrichment })._staff ?? ({} as StaffEnrichment)
133
+ const hoursWeek = typeof enrichment.hoursWeek === 'number' ? enrichment.hoursWeek : 0
134
+ const hoursTrend = Array.isArray(enrichment.hoursTrend)
135
+ ? enrichment.hoursTrend.filter((v): v is number => typeof v === 'number')
136
+ : []
137
+ const members = Array.isArray(enrichment.members)
138
+ ? enrichment.members
139
+ .filter((m): m is AvatarMember => !!m && typeof m === 'object' && typeof (m as AvatarMember).id === 'string')
140
+ .map((m) => ({
141
+ id: m.id,
142
+ name: m.name ?? '',
143
+ initials: m.initials ?? '',
144
+ avatarUrl: m.avatarUrl ?? null,
145
+ }))
146
+ : []
147
+ const memberCount = typeof enrichment.memberCount === 'number' ? enrichment.memberCount : members.length
148
+ const myRole = typeof enrichment.myRole === 'string' ? enrichment.myRole : null
149
+
150
+ return withDataTableNamespaces(
151
+ {
152
+ id,
153
+ name,
154
+ code,
155
+ customerId,
156
+ customerName,
157
+ status,
158
+ projectType,
159
+ color,
160
+ startDate,
161
+ updatedAt,
162
+ hoursWeek,
163
+ hoursTrend,
164
+ myRole,
165
+ members,
166
+ memberCount,
167
+ },
168
+ item,
169
+ )
170
+ }
171
+
172
+ export default function TimesheetProjectsPage() {
173
+ const t = useT()
174
+ const router = useRouter()
175
+ const searchParams = useSearchParams()
176
+ const scopeVersion = useOrganizationScopeVersion()
177
+ const { confirm, ConfirmDialogElement } = useConfirmDialog()
178
+
179
+ const [rows, setRows] = React.useState<ProjectRow[]>([])
180
+ const [page, setPage] = React.useState(1)
181
+ const [total, setTotal] = React.useState(0)
182
+ const [totalPages, setTotalPages] = React.useState(1)
183
+ const [sorting, setSorting] = React.useState<SortingState>([{ id: 'updatedAt', desc: true }])
184
+ const [search, setSearch] = React.useState('')
185
+ const [filterValues, setFilterValues] = React.useState<FilterValues>({})
186
+ const [isLoading, setIsLoading] = React.useState(true)
187
+ const [isRefreshing, setIsRefreshing] = React.useState(false)
188
+ const hasLoadedOnceRef = React.useRef(false)
189
+ const [reloadToken, setReloadToken] = React.useState(0)
190
+ const [kpis, setKpis] = React.useState<KpisResponse | null>(null)
191
+ const [isLoadingKpis, setIsLoadingKpis] = React.useState(true)
192
+
193
+ const activeTab = searchParams.get('tab') ?? 'all'
194
+ const urlViewMode = searchParams.get('view')
195
+ const [viewMode, setViewMode] = useProjectsViewMode({
196
+ userKey: null,
197
+ urlOverride: urlViewMode,
198
+ })
199
+
200
+ const labels = React.useMemo(
201
+ () => ({
202
+ title: t('staff.timesheets.projects.page.title', 'Projects'),
203
+ table: {
204
+ name: t('staff.timesheets.projects.table.name', 'Project'),
205
+ status: t('staff.timesheets.projects.table.status', 'Status'),
206
+ type: t('staff.timesheets.projects.table.type', 'Type'),
207
+ updatedAt: t('staff.timesheets.projects.table.updatedAt', 'Updated'),
208
+ empty: t('staff.timesheets.projects.table.empty', 'No projects yet.'),
209
+ search: t('staff.timesheets.projects.table.search', 'Search projects...'),
210
+ team: t('staff.timesheets.projects.portfolio.team', 'Team'),
211
+ myRole: t('staff.timesheets.projects.portfolio.myRole', 'My role'),
212
+ hoursWeek: t('staff.timesheets.projects.portfolio.hoursWeek', 'Hours / week'),
213
+ myHoursWeek: t('staff.timesheets.projects.portfolio.myHoursWeek', 'My hours / week'),
214
+ },
215
+ actions: {
216
+ add: t('staff.timesheets.projects.actions.add', 'Add Project'),
217
+ addFirst: t('staff.timesheets.projects.actions.addFirst', '+ Add first project'),
218
+ viewDetails: t('staff.timesheets.projects.actions.viewDetails', 'View Details'),
219
+ delete: t('staff.timesheets.projects.actions.delete', 'Delete'),
220
+ deleteConfirm: t('staff.timesheets.projects.actions.deleteConfirm', 'Delete project "{{name}}"?'),
221
+ refresh: t('staff.timesheets.projects.actions.refresh', 'Refresh'),
222
+ },
223
+ messages: {
224
+ deleted: t('staff.timesheets.projects.messages.deleted', 'Project deleted.'),
225
+ },
226
+ errors: {
227
+ load: t('staff.timesheets.projects.errors.load', 'Failed to load projects.'),
228
+ delete: t('staff.timesheets.projects.errors.delete', 'Failed to delete project.'),
229
+ },
230
+ statuses: {
231
+ all: t('staff.timesheets.projects.statuses.all', 'All'),
232
+ active: t('staff.timesheets.projects.statuses.active', 'Active'),
233
+ on_hold: t('staff.timesheets.projects.statuses.onHold', 'On Hold'),
234
+ completed: t('staff.timesheets.projects.statuses.completed', 'Completed'),
235
+ },
236
+ tabs: {
237
+ all: t('staff.timesheets.projects.portfolio.tabs.all', 'All'),
238
+ active: t('staff.timesheets.projects.portfolio.tabs.active', 'Active'),
239
+ onHold: t('staff.timesheets.projects.portfolio.tabs.onHold', 'On Hold'),
240
+ completed: t('staff.timesheets.projects.portfolio.tabs.completed', 'Completed'),
241
+ mine: t('staff.timesheets.projects.portfolio.tabs.mine', 'Mine'),
242
+ },
243
+ viewMode: {
244
+ table: t('staff.timesheets.projects.portfolio.viewMode.table', 'Table'),
245
+ cards: t('staff.timesheets.projects.portfolio.viewMode.cards', 'Cards'),
246
+ },
247
+ kpi: {
248
+ totalProjects: t('staff.timesheets.projects.portfolio.kpi.totalProjects', 'Total Projects'),
249
+ hoursWeek: t('staff.timesheets.projects.portfolio.kpi.hoursWeek', 'Hours this week'),
250
+ hoursWeekSub: t('staff.timesheets.projects.portfolio.kpi.hoursWeekSub', 'vs previous week'),
251
+ assignedToMe: t('staff.timesheets.projects.portfolio.kpi.assignedToMe', 'Assigned to me'),
252
+ hoursMonth: t('staff.timesheets.projects.portfolio.kpi.hoursMonth', 'Hours this month'),
253
+ hoursMonthSub: t('staff.timesheets.projects.portfolio.kpi.hoursMonthSub', 'vs previous month'),
254
+ teamActive: t('staff.timesheets.projects.portfolio.kpi.teamActive', 'Active team'),
255
+ teamActiveSub: t('staff.timesheets.projects.portfolio.kpi.teamActiveSub', 'Members with entries this month'),
256
+ myProjects: t('staff.timesheets.projects.portfolio.kpi.myProjects', 'My projects'),
257
+ myHoursWeek: t('staff.timesheets.projects.portfolio.kpi.myHoursWeek', 'My hours this week'),
258
+ myHoursMonth: t('staff.timesheets.projects.portfolio.kpi.myHoursMonth', 'My hours this month'),
259
+ deltaFlat: t('staff.timesheets.projects.portfolio.kpi.deltaFlat', 'no change'),
260
+ noPrevious: t('staff.timesheets.projects.portfolio.kpi.noPrevious', 'no previous data'),
261
+ },
262
+ card: {
263
+ hoursPanelPm: t('staff.timesheets.projects.portfolio.card.hoursPanelPm', 'Team hours · last 7w'),
264
+ hoursPanelCollab: t('staff.timesheets.projects.portfolio.card.hoursPanelCollab', 'My hours · last 7w'),
265
+ sparklineAria: t('staff.timesheets.projects.portfolio.sparkline.ariaLabel', 'Hours per week, last 7 weeks'),
266
+ role: t('staff.timesheets.projects.portfolio.card.role', 'Role'),
267
+ },
268
+ emptyState: {
269
+ noProjects: t('staff.timesheets.projects.portfolio.emptyState.noProjects', 'No projects yet.'),
270
+ noAssignments: t(
271
+ 'staff.timesheets.projects.portfolio.emptyState.noAssignments',
272
+ "You aren't assigned to any projects yet. Ask a PM to add you.",
273
+ ),
274
+ noMatches: t('staff.timesheets.projects.portfolio.emptyState.noMatches', 'No projects match these filters.'),
275
+ },
276
+ }),
277
+ [t],
278
+ )
279
+
280
+ const kpiLabels = React.useMemo(
281
+ () => ({
282
+ totalProjects: labels.kpi.totalProjects,
283
+ totalProjectsSub: ({ active, onHold }: { active: number; onHold: number }) =>
284
+ `${active} ${labels.statuses.active.toLowerCase()} · ${onHold} ${labels.statuses.on_hold.toLowerCase()}`,
285
+ hoursWeek: labels.kpi.hoursWeek,
286
+ hoursWeekSub: labels.kpi.hoursWeekSub,
287
+ assignedToMe: labels.kpi.assignedToMe,
288
+ assignedToMeSub: (active: number) => `${active} ${labels.statuses.active.toLowerCase()}`,
289
+ hoursMonth: labels.kpi.hoursMonth,
290
+ hoursMonthSub: labels.kpi.hoursMonthSub,
291
+ teamActive: labels.kpi.teamActive,
292
+ teamActiveSub: labels.kpi.teamActiveSub,
293
+ myProjects: labels.kpi.myProjects,
294
+ myProjectsSub: (active: number) => `${active} ${labels.statuses.active.toLowerCase()}`,
295
+ myHoursWeek: labels.kpi.myHoursWeek,
296
+ myHoursMonth: labels.kpi.myHoursMonth,
297
+ deltaUp: (pct: number) => `up ${pct}%`,
298
+ deltaDown: (pct: number) => `down ${pct}%`,
299
+ deltaFlat: labels.kpi.deltaFlat,
300
+ noPrevious: labels.kpi.noPrevious,
301
+ }),
302
+ [labels],
303
+ )
304
+
305
+ const isPmRole = kpis?.role === 'pm'
306
+
307
+ const filters = React.useMemo<FilterDef[]>(
308
+ () => [
309
+ {
310
+ id: 'status',
311
+ label: labels.table.status,
312
+ type: 'select',
313
+ options: [
314
+ { value: 'active', label: labels.statuses.active },
315
+ { value: 'on_hold', label: labels.statuses.on_hold },
316
+ { value: 'completed', label: labels.statuses.completed },
317
+ ],
318
+ },
319
+ ],
320
+ [labels.table.status, labels.statuses],
321
+ )
322
+
323
+ const tabs = React.useMemo(() => {
324
+ const base = [
325
+ { id: 'all', label: labels.tabs.all },
326
+ { id: 'active', label: labels.tabs.active },
327
+ ]
328
+ if (isPmRole) {
329
+ base.push({ id: 'on_hold', label: labels.tabs.onHold })
330
+ }
331
+ base.push({ id: 'completed', label: labels.tabs.completed })
332
+ if (isPmRole) {
333
+ base.push({ id: 'mine', label: labels.tabs.mine })
334
+ }
335
+ return base
336
+ }, [labels.tabs, isPmRole])
337
+
338
+ const statusFromTab = (tabId: string): string | null => {
339
+ if (tabId === 'active' || tabId === 'on_hold' || tabId === 'completed') return tabId
340
+ return null
341
+ }
342
+ const mineFromTab = (tabId: string): boolean => tabId === 'mine' || !isPmRole
343
+
344
+ const loadKpis = React.useCallback(async () => {
345
+ setIsLoadingKpis(true)
346
+ try {
347
+ const payload = await readApiResultOrThrow<KpisResponse>(
348
+ '/api/staff/timesheets/projects/kpis',
349
+ undefined,
350
+ {
351
+ errorMessage: labels.errors.load,
352
+ fallback: null as unknown as KpisResponse,
353
+ },
354
+ )
355
+ setKpis(payload)
356
+ } catch {
357
+ setKpis(null)
358
+ } finally {
359
+ setIsLoadingKpis(false)
360
+ }
361
+ }, [labels.errors.load])
362
+
363
+ const loadProjects = React.useCallback(async () => {
364
+ if (hasLoadedOnceRef.current) {
365
+ setIsRefreshing(true)
366
+ } else {
367
+ setIsLoading(true)
368
+ }
369
+ try {
370
+ const params = new URLSearchParams({
371
+ page: String(page),
372
+ pageSize: String(PAGE_SIZE),
373
+ include: INCLUDE_FIELDS,
374
+ })
375
+ const sort = sorting[0]
376
+ if (sort?.id) {
377
+ params.set('sortField', sort.id)
378
+ params.set('sortDir', sort.desc ? 'desc' : 'asc')
379
+ }
380
+ if (search.trim()) params.set('q', search.trim())
381
+ const tabStatus = statusFromTab(activeTab)
382
+ if (tabStatus) params.set('status', tabStatus)
383
+ else if (typeof filterValues.status === 'string' && filterValues.status.length > 0) {
384
+ params.set('status', filterValues.status)
385
+ }
386
+ if (mineFromTab(activeTab)) params.set('mine', '1')
387
+
388
+ const payload = await readApiResultOrThrow<ProjectsResponse>(
389
+ `/api/staff/timesheets/time-projects?${params.toString()}`,
390
+ undefined,
391
+ { errorMessage: labels.errors.load, fallback: { items: [], total: 0, totalPages: 1 } },
392
+ )
393
+ const items = Array.isArray(payload.items) ? payload.items : []
394
+ setRows(items.map(mapApiProject))
395
+ setTotal(typeof payload.total === 'number' ? payload.total : items.length)
396
+ setTotalPages(
397
+ typeof payload.totalPages === 'number'
398
+ ? payload.totalPages
399
+ : Math.max(1, Math.ceil(items.length / PAGE_SIZE)),
400
+ )
401
+ } catch (error) {
402
+ console.error('staff.timesheets.projects.list', error)
403
+ flash(labels.errors.load, 'error')
404
+ } finally {
405
+ setIsLoading(false)
406
+ setIsRefreshing(false)
407
+ hasLoadedOnceRef.current = true
408
+ }
409
+ }, [labels.errors.load, page, search, sorting, filterValues.status, activeTab, isPmRole])
410
+
411
+ React.useEffect(() => {
412
+ void loadKpis()
413
+ }, [loadKpis, scopeVersion, reloadToken])
414
+
415
+ React.useEffect(() => {
416
+ void loadProjects()
417
+ }, [loadProjects, scopeVersion, reloadToken])
418
+
419
+ const handleTabSelect = React.useCallback(
420
+ (id: string) => {
421
+ const params = new URLSearchParams(searchParams.toString())
422
+ if (id === 'all') params.delete('tab')
423
+ else params.set('tab', id)
424
+ router.replace(`?${params.toString()}`)
425
+ setPage(1)
426
+ },
427
+ [router, searchParams],
428
+ )
429
+
430
+ const handleViewModeChange = React.useCallback(
431
+ (next: ProjectsViewMode) => {
432
+ setViewMode(next)
433
+ const params = new URLSearchParams(searchParams.toString())
434
+ if (next === 'table') params.delete('view')
435
+ else params.set('view', next)
436
+ router.replace(`?${params.toString()}`)
437
+ },
438
+ [router, searchParams, setViewMode],
439
+ )
440
+
441
+ const handleSearchChange = React.useCallback((value: string) => {
442
+ setSearch(value)
443
+ setPage(1)
444
+ }, [])
445
+
446
+ const handleFiltersApply = React.useCallback((values: FilterValues) => {
447
+ setFilterValues(values)
448
+ setPage(1)
449
+ }, [])
450
+
451
+ const handleFiltersClear = React.useCallback(() => {
452
+ setFilterValues({})
453
+ setPage(1)
454
+ }, [])
455
+
456
+ const handleRefresh = React.useCallback(() => {
457
+ setReloadToken((token) => token + 1)
458
+ }, [])
459
+
460
+ const handleDelete = React.useCallback(
461
+ async (entry: ProjectRow) => {
462
+ const message = labels.actions.deleteConfirm.replace('{{name}}', entry.name)
463
+ const confirmed = await confirm({
464
+ title: labels.actions.delete,
465
+ text: message,
466
+ variant: 'destructive',
467
+ })
468
+ if (!confirmed) return
469
+ try {
470
+ await deleteCrud('staff/timesheets/time-projects', entry.id, { errorMessage: labels.errors.delete })
471
+ flash(labels.messages.deleted, 'success')
472
+ handleRefresh()
473
+ } catch (error) {
474
+ console.error('staff.timesheets.projects.delete', error)
475
+ flash(labels.errors.delete, 'error')
476
+ }
477
+ },
478
+ [confirm, handleRefresh, labels.actions.deleteConfirm, labels.actions.delete, labels.errors.delete, labels.messages.deleted],
479
+ )
480
+
481
+ const columns = React.useMemo<ColumnDef<ProjectRow>[]>(
482
+ () => [
483
+ {
484
+ accessorKey: 'name',
485
+ header: labels.table.name,
486
+ meta: { priority: 1, sticky: true },
487
+ cell: ({ row }) => (
488
+ <div className="flex items-center gap-2.5">
489
+ <ProjectColorDot colorKey={row.original.color} projectName={row.original.name} size="sm" />
490
+ <div className="flex min-w-0 flex-col">
491
+ <span className="truncate text-sm font-medium text-foreground">{row.original.name}</span>
492
+ <span className="truncate font-mono text-[11px] text-muted-foreground">
493
+ {row.original.code ?? '—'}
494
+ {row.original.customerName ? ` · ${row.original.customerName}` : ''}
495
+ </span>
496
+ </div>
497
+ </div>
498
+ ),
499
+ },
500
+ {
501
+ accessorKey: 'status',
502
+ header: labels.table.status,
503
+ meta: { priority: 2 },
504
+ cell: ({ row }) => {
505
+ const badgeClass =
506
+ row.original.status === 'active'
507
+ ? 'bg-lime-100 text-lime-800 dark:bg-lime-900/30 dark:text-lime-300'
508
+ : row.original.status === 'on_hold'
509
+ ? 'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300'
510
+ : 'bg-muted text-muted-foreground'
511
+ const statusLabel =
512
+ labels.statuses[row.original.status as keyof typeof labels.statuses] ?? row.original.status
513
+ return (
514
+ <span
515
+ className={`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium ${badgeClass}`}
516
+ >
517
+ {statusLabel}
518
+ </span>
519
+ )
520
+ },
521
+ },
522
+ {
523
+ accessorKey: 'projectType',
524
+ header: labels.table.type,
525
+ meta: { priority: 3 },
526
+ cell: ({ row }) =>
527
+ row.original.projectType ? (
528
+ <span className="text-sm text-foreground">{row.original.projectType}</span>
529
+ ) : (
530
+ <span className="text-xs text-muted-foreground/70">—</span>
531
+ ),
532
+ },
533
+ isPmRole
534
+ ? {
535
+ accessorKey: 'members',
536
+ id: 'members',
537
+ header: labels.table.team,
538
+ enableSorting: false,
539
+ meta: { priority: 4 },
540
+ cell: ({ row }) => (
541
+ <ProjectMembersAvatarStack
542
+ members={row.original.members}
543
+ total={row.original.memberCount}
544
+ peopleCountLabel={`${row.original.memberCount}`}
545
+ />
546
+ ),
547
+ }
548
+ : {
549
+ accessorKey: 'myRole',
550
+ header: labels.table.myRole,
551
+ enableSorting: false,
552
+ meta: { priority: 4 },
553
+ cell: ({ row }) =>
554
+ row.original.myRole ? (
555
+ <span className="text-sm text-foreground">{row.original.myRole}</span>
556
+ ) : (
557
+ <span className="text-xs text-muted-foreground/70">—</span>
558
+ ),
559
+ },
560
+ {
561
+ accessorKey: 'hoursWeek',
562
+ header: isPmRole ? labels.table.hoursWeek : labels.table.myHoursWeek,
563
+ enableSorting: false,
564
+ meta: { priority: 5 },
565
+ cell: ({ row }) => {
566
+ const stripe = resolveProjectColorHex(row.original.color, row.original.name)
567
+ return (
568
+ <div className="flex items-center justify-end gap-2">
569
+ <HoursSparkline
570
+ values={row.original.hoursTrend}
571
+ color={stripe}
572
+ ariaLabel={labels.card.sparklineAria}
573
+ />
574
+ <span className="text-xs font-medium tabular-nums text-foreground">
575
+ {row.original.hoursWeek > 0 ? `${row.original.hoursWeek}h` : '—'}
576
+ </span>
577
+ </div>
578
+ )
579
+ },
580
+ },
581
+ {
582
+ accessorKey: 'updatedAt',
583
+ header: labels.table.updatedAt,
584
+ meta: { priority: 6 },
585
+ cell: ({ row }) => (
586
+ <span className="text-xs text-muted-foreground">
587
+ {formatRelativeTime(row.original.updatedAt, '—', t)}
588
+ </span>
589
+ ),
590
+ },
591
+ ],
592
+ [labels.table, labels.statuses, labels.card.sparklineAria, isPmRole],
593
+ )
594
+
595
+ const cardLabels = React.useMemo<ProjectCardLabels>(
596
+ () => ({
597
+ hoursPanelPm: labels.card.hoursPanelPm,
598
+ hoursPanelCollab: labels.card.hoursPanelCollab,
599
+ sparklineAria: labels.card.sparklineAria,
600
+ peopleCount: (count: number) => `${count}`,
601
+ role: labels.card.role,
602
+ noCustomer: '—',
603
+ statuses: labels.statuses,
604
+ }),
605
+ [labels.card, labels.statuses],
606
+ )
607
+
608
+ const canManage = isPmRole
609
+
610
+ const emptyStateCopy = React.useMemo(() => {
611
+ const hasFiltersApplied = activeTab !== 'all' || search.trim().length > 0 || Object.values(filterValues).some(Boolean)
612
+ if (hasFiltersApplied) return labels.emptyState.noMatches
613
+ if (!canManage) return labels.emptyState.noAssignments
614
+ return labels.emptyState.noProjects
615
+ }, [activeTab, search, filterValues, canManage, labels.emptyState])
616
+
617
+ const cardsData: ProjectCardData[] = rows.map((row) => ({
618
+ id: row.id,
619
+ name: row.name,
620
+ code: row.code,
621
+ customerName: row.customerName,
622
+ color: row.color,
623
+ status: row.status,
624
+ hoursWeek: row.hoursWeek,
625
+ hoursTrend: row.hoursTrend,
626
+ members: row.members,
627
+ memberCount: row.memberCount,
628
+ myRole: row.myRole,
629
+ updatedAt: row.updatedAt,
630
+ }))
631
+
632
+ return (
633
+ <Page>
634
+ <PageBody>
635
+ <div className="mb-4">
636
+ <ProjectsKpiStrip kpis={kpis} labels={kpiLabels} isLoading={isLoadingKpis} />
637
+ </div>
638
+
639
+ <div className="mb-3 flex flex-wrap items-center justify-between gap-3">
640
+ <SavedViewTabs
641
+ tabs={tabs}
642
+ activeId={activeTab}
643
+ onSelect={handleTabSelect}
644
+ ariaLabel={t('staff.timesheets.projects.portfolio.savedViews.ariaLabel', 'Saved views')}
645
+ />
646
+ <ViewModeToggle
647
+ mode={viewMode}
648
+ onChange={handleViewModeChange}
649
+ tableLabel={labels.viewMode.table}
650
+ cardsLabel={labels.viewMode.cards}
651
+ ariaLabel={t('staff.timesheets.projects.portfolio.viewMode.ariaLabel', 'View mode')}
652
+ />
653
+ </div>
654
+
655
+ {viewMode === 'cards' ? (
656
+ <div>
657
+ {isLoading ? (
658
+ <div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
659
+ {Array.from({ length: 6 }).map((_, idx) => (
660
+ <div key={idx} className="h-48 animate-pulse rounded-lg border border-border bg-muted/40" />
661
+ ))}
662
+ </div>
663
+ ) : rows.length === 0 ? (
664
+ <div className="rounded-lg border border-dashed border-border bg-card p-10 text-center">
665
+ <p className="text-sm text-muted-foreground">{emptyStateCopy}</p>
666
+ {canManage ? (
667
+ <div className="mt-3">
668
+ <Button asChild size="sm">
669
+ <Link href="/backend/staff/timesheets/projects/create">
670
+ {labels.actions.addFirst}
671
+ </Link>
672
+ </Button>
673
+ </div>
674
+ ) : null}
675
+ </div>
676
+ ) : (
677
+ <div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
678
+ {cardsData.map((card) => (
679
+ <ProjectCard
680
+ key={card.id}
681
+ data={card}
682
+ labels={cardLabels}
683
+ showTeam={isPmRole}
684
+ href={`/backend/staff/timesheets/projects/${card.id}`}
685
+ />
686
+ ))}
687
+ </div>
688
+ )}
689
+ </div>
690
+ ) : (
691
+ <DataTable<ProjectRow>
692
+ title={labels.title}
693
+ data={rows}
694
+ columns={columns}
695
+ isLoading={isLoading}
696
+ searchValue={search}
697
+ onSearchChange={handleSearchChange}
698
+ searchPlaceholder={labels.table.search}
699
+ filters={filters}
700
+ filterValues={filterValues}
701
+ onFiltersApply={handleFiltersApply}
702
+ onFiltersClear={handleFiltersClear}
703
+ emptyState={
704
+ <div className="py-12 text-center">
705
+ <p className="text-sm text-muted-foreground mb-4">{emptyStateCopy}</p>
706
+ {canManage ? (
707
+ <Button asChild size="sm">
708
+ <Link href="/backend/staff/timesheets/projects/create">{labels.actions.addFirst}</Link>
709
+ </Button>
710
+ ) : null}
711
+ </div>
712
+ }
713
+ actions={
714
+ canManage ? (
715
+ <Button asChild size="sm">
716
+ <Link href="/backend/staff/timesheets/projects/create">{labels.actions.add}</Link>
717
+ </Button>
718
+ ) : undefined
719
+ }
720
+ refreshButton={{
721
+ label: labels.actions.refresh,
722
+ onRefresh: handleRefresh,
723
+ isRefreshing: isLoading || isRefreshing,
724
+ }}
725
+ sortable
726
+ sorting={sorting}
727
+ onSortingChange={setSorting}
728
+ pagination={{
729
+ page,
730
+ pageSize: PAGE_SIZE,
731
+ total,
732
+ totalPages,
733
+ onPageChange: setPage,
734
+ }}
735
+ rowActions={(row) => (
736
+ <RowActions
737
+ items={[
738
+ {
739
+ id: 'view',
740
+ label: labels.actions.viewDetails,
741
+ href: `/backend/staff/timesheets/projects/${row.id}`,
742
+ },
743
+ ...(canManage
744
+ ? [
745
+ {
746
+ id: 'delete',
747
+ label: labels.actions.delete,
748
+ destructive: true,
749
+ onSelect: () => {
750
+ void handleDelete(row)
751
+ },
752
+ },
753
+ ]
754
+ : []),
755
+ ]}
756
+ />
757
+ )}
758
+ onRowClick={(row) => router.push(`/backend/staff/timesheets/projects/${row.id}`)}
759
+ />
760
+ )}
761
+ </PageBody>
762
+ {ConfirmDialogElement}
763
+ </Page>
764
+ )
765
+ }