@omersx/bemms 0.0.0-stage → 1.0.0

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 (335) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +203 -2
  3. package/drizzle.config.ts +11 -0
  4. package/next.config.ts +51 -0
  5. package/package.json +99 -3
  6. package/postcss.config.mjs +7 -0
  7. package/public/hospital_demo_devices.csv +32 -0
  8. package/public/icons/icon-192.png +0 -0
  9. package/public/icons/icon-512.png +0 -0
  10. package/public/icons/icon-maskable-512.png +0 -0
  11. package/public/manifest.webmanifest +31 -0
  12. package/public/sw.js +177 -0
  13. package/src/app/(auth)/layout.tsx +20 -0
  14. package/src/app/(auth)/login/page.tsx +135 -0
  15. package/src/app/(dashboard)/admin/audit-logs/page.tsx +178 -0
  16. package/src/app/(dashboard)/admin/data/page.tsx +37 -0
  17. package/src/app/(dashboard)/admin/departments/[deptId]/edit/page.tsx +206 -0
  18. package/src/app/(dashboard)/admin/departments/[deptId]/page.tsx +71 -0
  19. package/src/app/(dashboard)/admin/departments/new/page.tsx +6 -0
  20. package/src/app/(dashboard)/admin/departments/page.tsx +6 -0
  21. package/src/app/(dashboard)/admin/general/page.tsx +374 -0
  22. package/src/app/(dashboard)/admin/hospitals/[hospitalId]/edit/page.tsx +304 -0
  23. package/src/app/(dashboard)/admin/hospitals/[hospitalId]/page.tsx +94 -0
  24. package/src/app/(dashboard)/admin/hospitals/new/page.tsx +302 -0
  25. package/src/app/(dashboard)/admin/hospitals/page.tsx +6 -0
  26. package/src/app/(dashboard)/admin/layout.tsx +49 -0
  27. package/src/app/(dashboard)/admin/organizations/[orgId]/edit/page.tsx +172 -0
  28. package/src/app/(dashboard)/admin/organizations/[orgId]/page.tsx +82 -0
  29. package/src/app/(dashboard)/admin/organizations/new/page.tsx +150 -0
  30. package/src/app/(dashboard)/admin/organizations/page.tsx +6 -0
  31. package/src/app/(dashboard)/admin/page.tsx +258 -0
  32. package/src/app/(dashboard)/admin/roles/page.tsx +153 -0
  33. package/src/app/(dashboard)/admin/settings/page.tsx +69 -0
  34. package/src/app/(dashboard)/admin/users/[userId]/edit/page.tsx +153 -0
  35. package/src/app/(dashboard)/admin/users/[userId]/page.tsx +317 -0
  36. package/src/app/(dashboard)/admin/users/invite/page.tsx +3 -0
  37. package/src/app/(dashboard)/admin/users/new/page.tsx +5 -0
  38. package/src/app/(dashboard)/admin/users/page.tsx +23 -0
  39. package/src/app/(dashboard)/dashboard/page.tsx +462 -0
  40. package/src/app/(dashboard)/departments/[deptId]/page.tsx +39 -0
  41. package/src/app/(dashboard)/departments/new/page.tsx +330 -0
  42. package/src/app/(dashboard)/departments/page.tsx +52 -0
  43. package/src/app/(dashboard)/devices/[id]/edit/page.tsx +131 -0
  44. package/src/app/(dashboard)/devices/[id]/page.tsx +408 -0
  45. package/src/app/(dashboard)/devices/[id]/qr/page.tsx +54 -0
  46. package/src/app/(dashboard)/devices/new/page.tsx +382 -0
  47. package/src/app/(dashboard)/devices/page.tsx +80 -0
  48. package/src/app/(dashboard)/engineering-team/page.tsx +41 -0
  49. package/src/app/(dashboard)/layout.tsx +43 -0
  50. package/src/app/(dashboard)/maintenance/checklists/page.tsx +57 -0
  51. package/src/app/(dashboard)/maintenance/page.tsx +231 -0
  52. package/src/app/(dashboard)/maintenance/plans/page.tsx +142 -0
  53. package/src/app/(dashboard)/maintenance/tasks/[id]/page.tsx +997 -0
  54. package/src/app/(dashboard)/maintenance/tasks/page.tsx +119 -0
  55. package/src/app/(dashboard)/more/page.tsx +310 -0
  56. package/src/app/(dashboard)/my-department/page.tsx +151 -0
  57. package/src/app/(dashboard)/notifications/notification-list.tsx +103 -0
  58. package/src/app/(dashboard)/notifications/page.tsx +59 -0
  59. package/src/app/(dashboard)/profile/page.tsx +27 -0
  60. package/src/app/(dashboard)/reports/costs/page.tsx +127 -0
  61. package/src/app/(dashboard)/reports/history/page.tsx +105 -0
  62. package/src/app/(dashboard)/reports/inventory/page.tsx +116 -0
  63. package/src/app/(dashboard)/reports/maintenance/page.tsx +136 -0
  64. package/src/app/(dashboard)/reports/page.tsx +120 -0
  65. package/src/app/(dashboard)/reports/tickets/page.tsx +139 -0
  66. package/src/app/(dashboard)/reports/workload/page.tsx +135 -0
  67. package/src/app/(dashboard)/rounds/[id]/page.tsx +197 -0
  68. package/src/app/(dashboard)/rounds/history/page.tsx +82 -0
  69. package/src/app/(dashboard)/rounds/page.tsx +107 -0
  70. package/src/app/(dashboard)/scan/[code]/page.tsx +154 -0
  71. package/src/app/(dashboard)/scan/page.tsx +73 -0
  72. package/src/app/(dashboard)/team/page.tsx +42 -0
  73. package/src/app/(dashboard)/tickets/[id]/page.tsx +465 -0
  74. package/src/app/(dashboard)/tickets/create/page.tsx +722 -0
  75. package/src/app/(dashboard)/tickets/page.tsx +55 -0
  76. package/src/app/(dashboard)/tickets/triage/page.tsx +161 -0
  77. package/src/app/api/admin/data/export/route.ts +316 -0
  78. package/src/app/api/auth/[...nextauth]/route.ts +3 -0
  79. package/src/app/api/health/route.ts +46 -0
  80. package/src/app/api/notifications/sse/route.ts +91 -0
  81. package/src/app/api/notifications/subscribe/route.ts +54 -0
  82. package/src/app/api/notifications/vapid-key/route.ts +7 -0
  83. package/src/app/api/reports/export/route.ts +102 -0
  84. package/src/app/api/tickets/[id]/attachments/route.ts +129 -0
  85. package/src/app/api/tickets/[id]/live-sync/route.ts +52 -0
  86. package/src/app/error.tsx +54 -0
  87. package/src/app/globals.css +89 -0
  88. package/src/app/layout.tsx +59 -0
  89. package/src/app/not-found.tsx +32 -0
  90. package/src/app/page.tsx +5 -0
  91. package/src/components/admin/add-department-user-dialog.tsx +759 -0
  92. package/src/components/admin/add-engineer-dialog.tsx +773 -0
  93. package/src/components/admin/add-user-type-dialog.tsx +89 -0
  94. package/src/components/admin/audit-log-export.tsx +113 -0
  95. package/src/components/admin/audit-log-filters.tsx +255 -0
  96. package/src/components/admin/audit-log-table.tsx +383 -0
  97. package/src/components/admin/data-management/danger-zone.tsx +301 -0
  98. package/src/components/admin/data-management/data-management-tabs.tsx +61 -0
  99. package/src/components/admin/data-management/export-center.tsx +301 -0
  100. package/src/components/admin/data-management/import-wizard.tsx +558 -0
  101. package/src/components/admin/settings-forms/features-form.tsx +115 -0
  102. package/src/components/admin/settings-forms/health-panel.tsx +182 -0
  103. package/src/components/admin/settings-forms/localization-form.tsx +203 -0
  104. package/src/components/admin/settings-forms/retention-form.tsx +164 -0
  105. package/src/components/admin/settings-forms/security-form.tsx +186 -0
  106. package/src/components/admin/system-settings-tabs.tsx +88 -0
  107. package/src/components/admin/user-role-dialog.tsx +293 -0
  108. package/src/components/admin/user-status-dialog.tsx +166 -0
  109. package/src/components/admin/users-page-client.tsx +514 -0
  110. package/src/components/dashboard/action-buttons.tsx +93 -0
  111. package/src/components/dashboard/admin-alerts.tsx +86 -0
  112. package/src/components/dashboard/availability-alerts.tsx +65 -0
  113. package/src/components/dashboard/maintenance-due-list.tsx +87 -0
  114. package/src/components/dashboard/round-widget.tsx +110 -0
  115. package/src/components/dashboard/stat-card.tsx +38 -0
  116. package/src/components/dashboard/ticket-list-compact.tsx +86 -0
  117. package/src/components/departments/department-cards-view.tsx +244 -0
  118. package/src/components/departments/department-detail-view.tsx +467 -0
  119. package/src/components/departments/department-visuals.tsx +190 -0
  120. package/src/components/departments/my-department-view.tsx +333 -0
  121. package/src/components/devices/change-status-dialog.tsx +146 -0
  122. package/src/components/devices/device-action-buttons.tsx +125 -0
  123. package/src/components/devices/device-availability-banner.tsx +59 -0
  124. package/src/components/devices/device-badges.tsx +55 -0
  125. package/src/components/devices/device-documents-tab.tsx +93 -0
  126. package/src/components/devices/device-maintenance-tab.tsx +113 -0
  127. package/src/components/devices/device-mini-qr.tsx +109 -0
  128. package/src/components/devices/device-qr-card.tsx +187 -0
  129. package/src/components/devices/device-signatures-tab.tsx +607 -0
  130. package/src/components/devices/device-tickets-tab.tsx +139 -0
  131. package/src/components/devices/device-timelines.tsx +124 -0
  132. package/src/components/devices/qr-camera-scanner.tsx +167 -0
  133. package/src/components/devices/qr-code-display.tsx +139 -0
  134. package/src/components/devices/quick-add-category-dialog.tsx +135 -0
  135. package/src/components/devices/quick-add-manufacturer-dialog.tsx +212 -0
  136. package/src/components/devices/transfer-device-dialog.tsx +190 -0
  137. package/src/components/layout/header.tsx +80 -0
  138. package/src/components/layout/mobile-nav.tsx +91 -0
  139. package/src/components/layout/more-item-badge.tsx +15 -0
  140. package/src/components/layout/nav-badge.tsx +72 -0
  141. package/src/components/layout/sidebar.tsx +297 -0
  142. package/src/components/maintenance/maintenance-badges.tsx +579 -0
  143. package/src/components/maintenance/maintenance-nav.tsx +107 -0
  144. package/src/components/maintenance/parts-costs-manager.tsx +909 -0
  145. package/src/components/maintenance/signature-card.tsx +413 -0
  146. package/src/components/maintenance/task-action-bar.tsx +955 -0
  147. package/src/components/notifications/notification-bell.tsx +367 -0
  148. package/src/components/notifications/notification-item.tsx +93 -0
  149. package/src/components/notifications/notification-preferences.tsx +182 -0
  150. package/src/components/profile/user-profile-view.tsx +626 -0
  151. package/src/components/providers/nav-counts-provider.tsx +235 -0
  152. package/src/components/providers/session-provider.tsx +7 -0
  153. package/src/components/providers/theme-provider.tsx +124 -0
  154. package/src/components/pwa/install-prompt.tsx +82 -0
  155. package/src/components/pwa/sw-register.tsx +43 -0
  156. package/src/components/reports/export-button.tsx +62 -0
  157. package/src/components/reports/filter-chips.tsx +47 -0
  158. package/src/components/reports/summary-cards.tsx +40 -0
  159. package/src/components/reports/transparency-header.tsx +54 -0
  160. package/src/components/rounds/department-visit-sheet.tsx +199 -0
  161. package/src/components/rounds/mention-textarea.tsx +187 -0
  162. package/src/components/rounds/round-calendar.tsx +233 -0
  163. package/src/components/rounds/round-department-list.tsx +281 -0
  164. package/src/components/rounds/round-history-client.tsx +218 -0
  165. package/src/components/rounds/start-round-card.tsx +184 -0
  166. package/src/components/shared/confirm-dialog.tsx +67 -0
  167. package/src/components/shared/data-table.tsx +104 -0
  168. package/src/components/shared/page-header.tsx +20 -0
  169. package/src/components/shared/sign-out-button.tsx +52 -0
  170. package/src/components/shared/status-badge.tsx +42 -0
  171. package/src/components/shared/table-search.tsx +55 -0
  172. package/src/components/signatures/sign-action-dialog.tsx +253 -0
  173. package/src/components/signatures/signature-history.tsx +121 -0
  174. package/src/components/signatures/signature-status-panel.tsx +164 -0
  175. package/src/components/team/department-coverage.tsx +141 -0
  176. package/src/components/team/edit-engineer-dialog.tsx +242 -0
  177. package/src/components/team/engineer-card.tsx +180 -0
  178. package/src/components/team/engineer-details-dialog.tsx +432 -0
  179. package/src/components/team/schedule-calendar.tsx +204 -0
  180. package/src/components/team/staff-engineer-team-view.tsx +368 -0
  181. package/src/components/team/team-header-stats.tsx +88 -0
  182. package/src/components/team/team-page-client.tsx +216 -0
  183. package/src/components/theme/theme-selector-card.tsx +63 -0
  184. package/src/components/theme/theme-toggle.tsx +65 -0
  185. package/src/components/tickets/staff-status-label.tsx +58 -0
  186. package/src/components/tickets/staff-ticket-card.tsx +109 -0
  187. package/src/components/tickets/staff-ticket-progress-tracker.tsx +405 -0
  188. package/src/components/tickets/staff-tickets-view.tsx +182 -0
  189. package/src/components/tickets/ticket-action-buttons.tsx +873 -0
  190. package/src/components/tickets/ticket-auto-refresh.tsx +197 -0
  191. package/src/components/tickets/ticket-badges.tsx +43 -0
  192. package/src/components/tickets/ticket-card.tsx +197 -0
  193. package/src/components/tickets/ticket-cards-view.tsx +395 -0
  194. package/src/components/tickets/ticket-comment-section.tsx +684 -0
  195. package/src/components/tickets/ticket-dispatch-status.tsx +184 -0
  196. package/src/components/tickets/ticket-list-auto-refresh.tsx +55 -0
  197. package/src/components/tickets/ticket-reporter-profile.tsx +235 -0
  198. package/src/components/tickets/ticket-signatures-panel.tsx +32 -0
  199. package/src/components/tickets/ticket-timeline.tsx +131 -0
  200. package/src/components/tickets/ticket-triage-panel.tsx +124 -0
  201. package/src/components/tickets/tickets-nav.tsx +107 -0
  202. package/src/components/ui/avatar.tsx +43 -0
  203. package/src/components/ui/badge.tsx +34 -0
  204. package/src/components/ui/button.tsx +58 -0
  205. package/src/components/ui/card.tsx +77 -0
  206. package/src/components/ui/checkbox.tsx +31 -0
  207. package/src/components/ui/dialog.tsx +123 -0
  208. package/src/components/ui/dropdown-menu.tsx +126 -0
  209. package/src/components/ui/form.tsx +179 -0
  210. package/src/components/ui/input.tsx +24 -0
  211. package/src/components/ui/label.tsx +27 -0
  212. package/src/components/ui/popover.tsx +34 -0
  213. package/src/components/ui/progress.tsx +36 -0
  214. package/src/components/ui/scroll-area.tsx +47 -0
  215. package/src/components/ui/select.tsx +160 -0
  216. package/src/components/ui/separator.tsx +25 -0
  217. package/src/components/ui/sheet.tsx +131 -0
  218. package/src/components/ui/switch.tsx +30 -0
  219. package/src/components/ui/table.tsx +121 -0
  220. package/src/components/ui/tabs.tsx +62 -0
  221. package/src/components/ui/textarea.tsx +23 -0
  222. package/src/components/ui/tooltip.tsx +27 -0
  223. package/src/lib/actions/__tests__/devices.test.ts +176 -0
  224. package/src/lib/actions/__tests__/signatures.test.ts +303 -0
  225. package/src/lib/actions/__tests__/tickets.test.ts +243 -0
  226. package/src/lib/actions/audit-logs.ts +298 -0
  227. package/src/lib/actions/checklists.ts +429 -0
  228. package/src/lib/actions/dashboard.ts +358 -0
  229. package/src/lib/actions/data-management.ts +723 -0
  230. package/src/lib/actions/departments.ts +369 -0
  231. package/src/lib/actions/device-categories.ts +117 -0
  232. package/src/lib/actions/devices.ts +748 -0
  233. package/src/lib/actions/engineer-rounds.ts +973 -0
  234. package/src/lib/actions/engineers.ts +285 -0
  235. package/src/lib/actions/hospitals.ts +148 -0
  236. package/src/lib/actions/locations.ts +115 -0
  237. package/src/lib/actions/maintenance-plans.ts +316 -0
  238. package/src/lib/actions/maintenance-tasks.ts +415 -0
  239. package/src/lib/actions/manufacturers.ts +132 -0
  240. package/src/lib/actions/nav-counts.ts +144 -0
  241. package/src/lib/actions/notifications.ts +136 -0
  242. package/src/lib/actions/organizations.ts +99 -0
  243. package/src/lib/actions/qr.ts +147 -0
  244. package/src/lib/actions/report-history.ts +77 -0
  245. package/src/lib/actions/reports.ts +192 -0
  246. package/src/lib/actions/roles.ts +32 -0
  247. package/src/lib/actions/signature-auth.ts +377 -0
  248. package/src/lib/actions/signatures.ts +532 -0
  249. package/src/lib/actions/system-settings.ts +274 -0
  250. package/src/lib/actions/tickets.ts +1445 -0
  251. package/src/lib/actions/users.ts +740 -0
  252. package/src/lib/audit/index.ts +103 -0
  253. package/src/lib/auth/__tests__/rbac.test.ts +33 -0
  254. package/src/lib/auth/index.ts +338 -0
  255. package/src/lib/auth/password.ts +10 -0
  256. package/src/lib/auth/rbac.ts +103 -0
  257. package/src/lib/auth/types.ts +57 -0
  258. package/src/lib/constants/departments.ts +16 -0
  259. package/src/lib/constants/manufacturers.ts +32 -0
  260. package/src/lib/db/index.ts +23 -0
  261. package/src/lib/db/schema/audit-logs.ts +42 -0
  262. package/src/lib/db/schema/departments.ts +39 -0
  263. package/src/lib/db/schema/device-categories.ts +38 -0
  264. package/src/lib/db/schema/devices.ts +195 -0
  265. package/src/lib/db/schema/engineer-profiles.ts +63 -0
  266. package/src/lib/db/schema/engineer-rounds.ts +115 -0
  267. package/src/lib/db/schema/enums.ts +148 -0
  268. package/src/lib/db/schema/hospitals.ts +34 -0
  269. package/src/lib/db/schema/index.ts +24 -0
  270. package/src/lib/db/schema/locations.ts +46 -0
  271. package/src/lib/db/schema/maintenance-plans.ts +99 -0
  272. package/src/lib/db/schema/maintenance-records.ts +161 -0
  273. package/src/lib/db/schema/maintenance-tasks.ts +196 -0
  274. package/src/lib/db/schema/manufacturers.ts +60 -0
  275. package/src/lib/db/schema/notifications.ts +48 -0
  276. package/src/lib/db/schema/organizations.ts +24 -0
  277. package/src/lib/db/schema/report-history.ts +28 -0
  278. package/src/lib/db/schema/roles.ts +59 -0
  279. package/src/lib/db/schema/sessions.ts +46 -0
  280. package/src/lib/db/schema/signature-events.ts +48 -0
  281. package/src/lib/db/schema/signature-policies.ts +60 -0
  282. package/src/lib/db/schema/signatures.ts +87 -0
  283. package/src/lib/db/schema/tickets.ts +169 -0
  284. package/src/lib/db/schema/user-assignments.ts +85 -0
  285. package/src/lib/db/schema/users.ts +39 -0
  286. package/src/lib/db/seed.ts +131 -0
  287. package/src/lib/logger/__tests__/logger.test.ts +154 -0
  288. package/src/lib/logger/formatters.ts +159 -0
  289. package/src/lib/logger/index.ts +184 -0
  290. package/src/lib/logger/types.ts +48 -0
  291. package/src/lib/notifications/create.ts +71 -0
  292. package/src/lib/notifications/dispatcher.ts +490 -0
  293. package/src/lib/notifications/index.ts +7 -0
  294. package/src/lib/notifications/push-sender.ts +128 -0
  295. package/src/lib/notifications/push.ts +64 -0
  296. package/src/lib/notifications/triggers.ts +166 -0
  297. package/src/lib/utils/__tests__/crypto.test.ts +30 -0
  298. package/src/lib/utils/__tests__/export.test.ts +55 -0
  299. package/src/lib/utils/__tests__/nav-badge.test.ts +147 -0
  300. package/src/lib/utils/__tests__/staff-status.test.ts +50 -0
  301. package/src/lib/utils/attestations.ts +19 -0
  302. package/src/lib/utils/crypto.ts +18 -0
  303. package/src/lib/utils/csv-parser.ts +181 -0
  304. package/src/lib/utils/export.ts +45 -0
  305. package/src/lib/utils/nav-badge.ts +225 -0
  306. package/src/lib/utils/sound.ts +152 -0
  307. package/src/lib/utils/staff-status.ts +115 -0
  308. package/src/lib/utils.ts +6 -0
  309. package/src/lib/validators/__tests__/auth.test.ts +127 -0
  310. package/src/lib/validators/__tests__/data-management.test.ts +182 -0
  311. package/src/lib/validators/__tests__/devices-profile.test.ts +129 -0
  312. package/src/lib/validators/__tests__/devices.test.ts +98 -0
  313. package/src/lib/validators/__tests__/engineer-rounds.test.ts +170 -0
  314. package/src/lib/validators/__tests__/maintenance.test.ts +178 -0
  315. package/src/lib/validators/__tests__/signatures.test.ts +154 -0
  316. package/src/lib/validators/__tests__/system-settings.test.ts +119 -0
  317. package/src/lib/validators/__tests__/tickets.test.ts +176 -0
  318. package/src/lib/validators/__tests__/users.test.ts +92 -0
  319. package/src/lib/validators/auth.ts +32 -0
  320. package/src/lib/validators/data-management.ts +67 -0
  321. package/src/lib/validators/departments.ts +14 -0
  322. package/src/lib/validators/devices.ts +94 -0
  323. package/src/lib/validators/engineer-rounds.ts +70 -0
  324. package/src/lib/validators/hospitals.ts +17 -0
  325. package/src/lib/validators/locations.ts +15 -0
  326. package/src/lib/validators/maintenance.ts +211 -0
  327. package/src/lib/validators/organizations.ts +11 -0
  328. package/src/lib/validators/reports.ts +31 -0
  329. package/src/lib/validators/signatures.ts +49 -0
  330. package/src/lib/validators/system-settings.ts +55 -0
  331. package/src/lib/validators/tickets.ts +125 -0
  332. package/src/lib/validators/users.ts +43 -0
  333. package/src/middleware.ts +45 -0
  334. package/tailwind.config.ts +76 -0
  335. package/tsconfig.json +28 -0
@@ -0,0 +1,67 @@
1
+ "use client";
2
+
3
+ import {
4
+ Dialog,
5
+ DialogContent,
6
+ DialogDescription,
7
+ DialogFooter,
8
+ DialogHeader,
9
+ DialogTitle,
10
+ DialogTrigger,
11
+ } from "@/components/ui/dialog";
12
+ import { Button } from "@/components/ui/button";
13
+ import { ReactNode, useState } from "react";
14
+
15
+ interface ConfirmDialogProps {
16
+ title: string;
17
+ description: string;
18
+ confirmLabel?: string;
19
+ cancelLabel?: string;
20
+ variant?: "default" | "destructive";
21
+ onConfirm: () => void | Promise<void>;
22
+ trigger: ReactNode;
23
+ }
24
+
25
+ export function ConfirmDialog({
26
+ title,
27
+ description,
28
+ confirmLabel = "Confirm",
29
+ cancelLabel = "Cancel",
30
+ variant = "default",
31
+ onConfirm,
32
+ trigger,
33
+ }: ConfirmDialogProps) {
34
+ const [open, setOpen] = useState(false);
35
+ const [isLoading, setIsLoading] = useState(false);
36
+
37
+ const handleConfirm = async () => {
38
+ setIsLoading(true);
39
+ try {
40
+ await onConfirm();
41
+ setOpen(false);
42
+ } finally {
43
+ setIsLoading(false);
44
+ }
45
+ };
46
+
47
+ return (
48
+ <Dialog open={open} onOpenChange={setOpen}>
49
+ <DialogTrigger asChild>{trigger}</DialogTrigger>
50
+ <DialogContent>
51
+ <DialogHeader>
52
+ <DialogTitle>{title}</DialogTitle>
53
+ <DialogDescription>{description}</DialogDescription>
54
+ </DialogHeader>
55
+ <DialogFooter>
56
+ <Button variant="outline" onClick={() => setOpen(false)} disabled={isLoading}>
57
+ {cancelLabel}
58
+ </Button>
59
+ <Button variant={variant} onClick={handleConfirm} disabled={isLoading}>
60
+ {isLoading ? "Loading..." : confirmLabel}
61
+ </Button>
62
+ </DialogFooter>
63
+ </DialogContent>
64
+ </Dialog>
65
+ );
66
+ }
67
+
@@ -0,0 +1,104 @@
1
+ import {
2
+ Table,
3
+ TableBody,
4
+ TableCell,
5
+ TableHead,
6
+ TableHeader,
7
+ TableRow,
8
+ } from "@/components/ui/table";
9
+ import { TableSearch } from "./table-search";
10
+
11
+ export interface ColumnDef<T> {
12
+ key: string;
13
+ header: string;
14
+ render?: (item: T) => React.ReactNode;
15
+ }
16
+
17
+ interface DataTableProps<T> {
18
+ columns: ColumnDef<T>[];
19
+ data: T[];
20
+ searchable?: boolean;
21
+ searchPlaceholder?: string;
22
+ emptyMessage?: string;
23
+ searchKey?: string;
24
+ }
25
+
26
+ function getSearchText(item: any): string {
27
+ return Object.entries(item)
28
+ .map(([_, v]) => {
29
+ if (v === null || v === undefined) return "";
30
+ if (typeof v === "object") {
31
+ if ("name" in v && typeof (v as any).name === "string") return (v as any).name;
32
+ if ("title" in v && typeof (v as any).title === "string") return (v as any).title;
33
+ return "";
34
+ }
35
+ return String(v);
36
+ })
37
+ .join(" ")
38
+ .toLowerCase();
39
+ }
40
+
41
+ export function DataTable<T extends Record<string, any>>({
42
+ columns,
43
+ data,
44
+ searchable = false,
45
+ searchPlaceholder = "Search...",
46
+ emptyMessage = "No results found.",
47
+ searchKey,
48
+ }: DataTableProps<T>) {
49
+ const isSearchable = searchable || Boolean(searchKey) || (searchPlaceholder !== "Search..." && Boolean(searchPlaceholder));
50
+
51
+ const tableContent = (
52
+ <div className="rounded-md border bg-card overflow-hidden">
53
+ <Table>
54
+ <TableHeader>
55
+ <TableRow>
56
+ {columns.map((column) => (
57
+ <TableHead key={column.key}>{column.header}</TableHead>
58
+ ))}
59
+ </TableRow>
60
+ </TableHeader>
61
+ <TableBody>
62
+ {data.length === 0 ? (
63
+ <TableRow>
64
+ <TableCell colSpan={columns.length} className="h-24 text-center">
65
+ {emptyMessage}
66
+ </TableCell>
67
+ </TableRow>
68
+ ) : (
69
+ <>
70
+ {data.map((item, i) => (
71
+ <TableRow
72
+ key={item.id || i}
73
+ data-search-row={getSearchText(item)}
74
+ >
75
+ {columns.map((column) => (
76
+ <TableCell key={column.key}>
77
+ {column.render ? column.render(item) : item[column.key]}
78
+ </TableCell>
79
+ ))}
80
+ </TableRow>
81
+ ))}
82
+ <TableRow data-no-results style={{ display: "none" }}>
83
+ <TableCell colSpan={columns.length} className="h-24 text-center text-muted-foreground">
84
+ No matching records found.
85
+ </TableCell>
86
+ </TableRow>
87
+ </>
88
+ )}
89
+ </TableBody>
90
+ </Table>
91
+ </div>
92
+ );
93
+
94
+ if (isSearchable) {
95
+ return (
96
+ <TableSearch placeholder={searchPlaceholder} emptyMessage={emptyMessage}>
97
+ {tableContent}
98
+ </TableSearch>
99
+ );
100
+ }
101
+
102
+ return tableContent;
103
+ }
104
+
@@ -0,0 +1,20 @@
1
+ import { ReactNode } from "react";
2
+
3
+ interface PageHeaderProps {
4
+ title: string;
5
+ description?: string;
6
+ children?: ReactNode;
7
+ }
8
+
9
+ export function PageHeader({ title, description, children }: PageHeaderProps) {
10
+ return (
11
+ <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
12
+ <div>
13
+ <h1 className="text-2xl font-bold tracking-tight">{title}</h1>
14
+ {description && <p className="text-muted-foreground mt-1">{description}</p>}
15
+ </div>
16
+ {children && <div className="flex items-center gap-2">{children}</div>}
17
+ </div>
18
+ );
19
+ }
20
+
@@ -0,0 +1,52 @@
1
+ 'use client'
2
+
3
+ import { useState } from 'react'
4
+ import { signOut } from 'next-auth/react'
5
+ import { LogOut, Loader2 } from 'lucide-react'
6
+ import { Button, ButtonProps } from '@/components/ui/button'
7
+ import { cn } from '@/lib/utils'
8
+
9
+ interface SignOutButtonProps extends ButtonProps {
10
+ showIcon?: boolean
11
+ label?: string
12
+ redirectUrl?: string
13
+ }
14
+
15
+ export function SignOutButton({
16
+ showIcon = true,
17
+ label = 'Log out',
18
+ redirectUrl = '/login',
19
+ className,
20
+ variant = 'outline',
21
+ size = 'default',
22
+ ...props
23
+ }: SignOutButtonProps) {
24
+ const [loading, setLoading] = useState(false)
25
+
26
+ const handleSignOut = async () => {
27
+ try {
28
+ setLoading(true)
29
+ await signOut({ callbackUrl: redirectUrl })
30
+ } catch {
31
+ setLoading(false)
32
+ }
33
+ }
34
+
35
+ return (
36
+ <Button
37
+ variant={variant}
38
+ size={size}
39
+ disabled={loading}
40
+ onClick={handleSignOut}
41
+ className={cn(className)}
42
+ {...props}
43
+ >
44
+ {loading ? (
45
+ <Loader2 className="w-4 h-4 animate-spin mr-2" />
46
+ ) : showIcon ? (
47
+ <LogOut className="w-4 h-4 mr-2" />
48
+ ) : null}
49
+ {loading ? 'Logging out...' : label}
50
+ </Button>
51
+ )
52
+ }
@@ -0,0 +1,42 @@
1
+ import { Badge } from "@/components/ui/badge";
2
+ import { cn } from "@/lib/utils";
3
+
4
+ export type Status = "active" | "inactive" | "archived" | "invited" | "suspended" | "deactivated" | string | null | undefined;
5
+
6
+ interface StatusBadgeProps {
7
+ status?: Status;
8
+ className?: string;
9
+ }
10
+
11
+ export function StatusBadge({ status, className }: StatusBadgeProps) {
12
+ const displayStatus = status || "unknown";
13
+ const normalizedStatus = displayStatus.toLowerCase();
14
+
15
+ let variant: "default" | "secondary" | "destructive" | "outline" = "default";
16
+
17
+ switch (normalizedStatus) {
18
+ case "active":
19
+ variant = "default";
20
+ break;
21
+ case "inactive":
22
+ case "invited":
23
+ variant = "secondary";
24
+ break;
25
+ case "archived":
26
+ variant = "outline";
27
+ break;
28
+ case "suspended":
29
+ case "deactivated":
30
+ variant = "destructive";
31
+ break;
32
+ default:
33
+ variant = "secondary";
34
+ }
35
+
36
+ return (
37
+ <Badge variant={variant} className={cn("capitalize", className)}>
38
+ {displayStatus}
39
+ </Badge>
40
+ );
41
+ }
42
+
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+
3
+ import { useState, useRef, useEffect, ReactNode } from "react";
4
+ import { Input } from "@/components/ui/input";
5
+ import { Search } from "lucide-react";
6
+
7
+ interface TableSearchProps {
8
+ children: ReactNode;
9
+ placeholder?: string;
10
+ emptyMessage?: string;
11
+ }
12
+
13
+ export function TableSearch({
14
+ children,
15
+ placeholder = "Search...",
16
+ emptyMessage = "No matching records found.",
17
+ }: TableSearchProps) {
18
+ const [query, setQuery] = useState("");
19
+ const containerRef = useRef<HTMLDivElement>(null);
20
+
21
+ useEffect(() => {
22
+ if (!containerRef.current) return;
23
+ const rows = containerRef.current.querySelectorAll<HTMLTableRowElement>("tbody tr[data-search-row]");
24
+ const q = query.toLowerCase().trim();
25
+ let visibleCount = 0;
26
+
27
+ rows.forEach((row) => {
28
+ const text = row.getAttribute("data-search-row") || "";
29
+ const matches = !q || text.includes(q);
30
+ row.style.display = matches ? "" : "none";
31
+ if (matches) visibleCount++;
32
+ });
33
+
34
+ const noResultsRow = containerRef.current.querySelector<HTMLTableRowElement>("tbody tr[data-no-results]");
35
+ if (noResultsRow) {
36
+ noResultsRow.style.display = (visibleCount === 0 && rows.length > 0 && q.length > 0) ? "" : "none";
37
+ }
38
+ }, [query]);
39
+
40
+ return (
41
+ <div ref={containerRef} className="space-y-4">
42
+ <div className="relative max-w-sm">
43
+ <Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
44
+ <Input
45
+ placeholder={placeholder}
46
+ className="pl-8 bg-card"
47
+ value={query}
48
+ onChange={(e) => setQuery(e.target.value)}
49
+ />
50
+ </div>
51
+ {children}
52
+ </div>
53
+ );
54
+ }
55
+
@@ -0,0 +1,253 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { useState } from "react"
5
+ import {
6
+ Dialog,
7
+ DialogContent,
8
+ DialogHeader,
9
+ DialogTitle,
10
+ DialogDescription,
11
+ } from "@/components/ui/dialog"
12
+ import { Button } from "@/components/ui/button"
13
+ import { Input } from "@/components/ui/input"
14
+ import { Label } from "@/components/ui/label"
15
+ import { Textarea } from "@/components/ui/textarea"
16
+ import { Separator } from "@/components/ui/separator"
17
+ import { Shield, Loader2, CheckCircle2, ShieldCheck, XCircle } from "lucide-react"
18
+
19
+ export interface SignActionDialogProps {
20
+ open: boolean;
21
+ onOpenChange: (open: boolean) => void;
22
+ deviceName: string;
23
+ assetNumber: string;
24
+ recordType: string;
25
+ recordNumber: string;
26
+ actionLabel: string;
27
+ workSummary: string;
28
+ finalResult?: string;
29
+ proposedDeviceStatus?: string;
30
+ signaturePurpose: string;
31
+ attestationText: string;
32
+ signerName: string;
33
+ signerRole: string;
34
+ onSign: (password: string, comments?: string) => Promise<{ success: boolean; error?: string }>;
35
+ nextStep?: string;
36
+ }
37
+
38
+ export function SignActionDialog({
39
+ open,
40
+ onOpenChange,
41
+ deviceName,
42
+ assetNumber,
43
+ recordType,
44
+ recordNumber,
45
+ actionLabel,
46
+ workSummary,
47
+ finalResult,
48
+ proposedDeviceStatus,
49
+ signaturePurpose,
50
+ attestationText,
51
+ signerName,
52
+ signerRole,
53
+ onSign,
54
+ nextStep,
55
+ }: SignActionDialogProps) {
56
+ const [password, setPassword] = useState("")
57
+ const [comments, setComments] = useState("")
58
+ const [isSubmitting, setIsSubmitting] = useState(false)
59
+ const [error, setError] = useState<string | null>(null)
60
+ const [success, setSuccess] = useState(false)
61
+
62
+ const serverTime = new Date().toLocaleString("en-US", {
63
+ year: "numeric",
64
+ month: "short",
65
+ day: "2-digit",
66
+ hour: "2-digit",
67
+ minute: "2-digit",
68
+ second: "2-digit",
69
+ hour12: true,
70
+ })
71
+
72
+ // Reset state when opened
73
+ React.useEffect(() => {
74
+ if (open) {
75
+ setPassword("")
76
+ setComments("")
77
+ setError(null)
78
+ setSuccess(false)
79
+ setIsSubmitting(false)
80
+ }
81
+ }, [open])
82
+
83
+ const handleSign = async (e: React.FormEvent) => {
84
+ e.preventDefault()
85
+ if (!password) return
86
+
87
+ setIsSubmitting(true)
88
+ setError(null)
89
+
90
+ try {
91
+ const result = await onSign(password, comments)
92
+ if (result.success) {
93
+ setSuccess(true)
94
+ } else {
95
+ setError(result.error || "Failed to sign record. Please verify your credentials.")
96
+ }
97
+ } catch (err) {
98
+ setError("An unexpected error occurred during signing.")
99
+ } finally {
100
+ setIsSubmitting(false)
101
+ }
102
+ }
103
+
104
+ const handleClose = () => {
105
+ onOpenChange(false)
106
+ }
107
+
108
+ return (
109
+ <Dialog open={open} onOpenChange={success ? undefined : onOpenChange}>
110
+ <DialogContent className="max-w-md sm:max-w-lg w-full max-h-[100dvh] overflow-y-auto sm:max-h-[90vh]">
111
+ {success ? (
112
+ <div className="flex flex-col items-center justify-center py-8 px-4 space-y-6 text-center animate-in fade-in zoom-in duration-300">
113
+ <div className="h-16 w-16 rounded-full bg-emerald-100 dark:bg-emerald-950 flex items-center justify-center ring-8 ring-emerald-50 dark:ring-emerald-900/50">
114
+ <CheckCircle2 className="h-8 w-8 text-emerald-600 dark:text-emerald-500" />
115
+ </div>
116
+
117
+ <div className="space-y-2">
118
+ <h2 className="text-xl font-bold tracking-tight text-foreground">
119
+ {actionLabel} Signed Successfully
120
+ </h2>
121
+ <p className="text-sm text-muted-foreground max-w-[280px] mx-auto leading-relaxed">
122
+ Signed by: <span className="font-medium text-foreground">{signerName}</span>, {signerRole}
123
+ <br />
124
+ {serverTime}
125
+ </p>
126
+ </div>
127
+
128
+ <div className="w-full p-3 rounded-lg bg-muted/50 border border-border/50">
129
+ <p className="text-sm font-medium text-foreground">
130
+ Status: <span className="text-primary">{nextStep || 'Complete'}</span>
131
+ </p>
132
+ </div>
133
+
134
+ <Button onClick={handleClose} className="w-full mt-2" variant="outline">
135
+ Close
136
+ </Button>
137
+ </div>
138
+ ) : (
139
+ <>
140
+ <DialogHeader className="space-y-3 pb-2">
141
+ <DialogTitle className="flex items-center gap-2 text-xl">
142
+ <ShieldCheck className="h-5 w-5 text-primary" />
143
+ {actionLabel}
144
+ </DialogTitle>
145
+ <DialogDescription className="sr-only">
146
+ Review and sign the electronic record
147
+ </DialogDescription>
148
+ </DialogHeader>
149
+
150
+ <div className="space-y-4">
151
+ <div className="space-y-1">
152
+ <p className="text-sm font-medium">Device: {deviceName} <span className="text-muted-foreground">• Asset: {assetNumber}</span></p>
153
+ <p className="text-sm text-muted-foreground">Record: {recordType} {recordNumber}</p>
154
+ </div>
155
+
156
+ <Separator />
157
+
158
+ <div className="space-y-2 text-sm">
159
+ <div className="grid grid-cols-[100px_1fr] gap-2">
160
+ <span className="text-muted-foreground">Action:</span>
161
+ <span className="font-medium">{actionLabel}</span>
162
+ </div>
163
+ <div className="grid grid-cols-[100px_1fr] gap-2">
164
+ <span className="text-muted-foreground">Work Summary:</span>
165
+ <span>{workSummary}</span>
166
+ </div>
167
+ {finalResult && (
168
+ <div className="grid grid-cols-[100px_1fr] gap-2">
169
+ <span className="text-muted-foreground">Result:</span>
170
+ <span className="font-medium">{finalResult}</span>
171
+ </div>
172
+ )}
173
+ {proposedDeviceStatus && (
174
+ <div className="grid grid-cols-[100px_1fr] gap-2">
175
+ <span className="text-muted-foreground">Status:</span>
176
+ <span className="font-medium">{proposedDeviceStatus}</span>
177
+ </div>
178
+ )}
179
+ </div>
180
+
181
+ <Separator />
182
+
183
+ <blockquote className="border-l-4 border-primary/50 bg-muted/40 px-4 py-3 text-sm italic text-foreground/90 rounded-r-md">
184
+ &quot;{attestationText}&quot;
185
+ </blockquote>
186
+
187
+ <div className="space-y-1 bg-primary/5 p-3 rounded-md border border-primary/10">
188
+ <p className="text-sm">Signing as: <span className="font-semibold">{signerName}</span>, <span className="text-muted-foreground">{signerRole}</span></p>
189
+ <p className="text-xs text-muted-foreground">Time: {serverTime}</p>
190
+ </div>
191
+
192
+ <Separator />
193
+
194
+ <form onSubmit={handleSign} className="space-y-4 pt-1">
195
+ <div className="space-y-2">
196
+ <Label htmlFor="password">Electronic Signature Password</Label>
197
+ <Input
198
+ id="password"
199
+ type="password"
200
+ value={password}
201
+ onChange={(e) => setPassword(e.target.value)}
202
+ placeholder="Enter your password to sign"
203
+ required
204
+ disabled={isSubmitting}
205
+ />
206
+ {error && (
207
+ <div className="flex items-center gap-1.5 text-sm text-destructive mt-1">
208
+ <XCircle className="h-4 w-4" />
209
+ <p>{error}</p>
210
+ </div>
211
+ )}
212
+ </div>
213
+
214
+ <div className="space-y-2">
215
+ <Label htmlFor="comments">Comments (optional)</Label>
216
+ <Textarea
217
+ id="comments"
218
+ value={comments}
219
+ onChange={(e) => setComments(e.target.value)}
220
+ placeholder="Add any additional comments here..."
221
+ className="resize-none h-20"
222
+ disabled={isSubmitting}
223
+ />
224
+ </div>
225
+
226
+ <div className="pt-2">
227
+ <Button
228
+ type="submit"
229
+ className="w-full bg-primary hover:bg-primary/90 text-primary-foreground font-medium h-11"
230
+ disabled={!password || isSubmitting}
231
+ >
232
+ {isSubmitting ? (
233
+ <>
234
+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />
235
+ Signing Record...
236
+ </>
237
+ ) : (
238
+ <>
239
+ <Shield className="mr-2 h-4 w-4" />
240
+ Sign Record
241
+ </>
242
+ )}
243
+ </Button>
244
+ </div>
245
+ </form>
246
+ </div>
247
+ </>
248
+ )}
249
+ </DialogContent>
250
+ </Dialog>
251
+ )
252
+ }
253
+