@omersx/bemms 0.0.0-stage → 0.1.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.
- package/LICENSE +22 -0
- package/README.md +203 -2
- package/drizzle.config.ts +11 -0
- package/next.config.ts +51 -0
- package/package.json +99 -3
- package/postcss.config.mjs +7 -0
- package/public/hospital_demo_devices.csv +32 -0
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/icons/icon-maskable-512.png +0 -0
- package/public/manifest.webmanifest +31 -0
- package/public/sw.js +177 -0
- package/src/app/(auth)/layout.tsx +20 -0
- package/src/app/(auth)/login/page.tsx +135 -0
- package/src/app/(dashboard)/admin/audit-logs/page.tsx +178 -0
- package/src/app/(dashboard)/admin/data/page.tsx +37 -0
- package/src/app/(dashboard)/admin/departments/[deptId]/edit/page.tsx +206 -0
- package/src/app/(dashboard)/admin/departments/[deptId]/page.tsx +71 -0
- package/src/app/(dashboard)/admin/departments/new/page.tsx +6 -0
- package/src/app/(dashboard)/admin/departments/page.tsx +6 -0
- package/src/app/(dashboard)/admin/general/page.tsx +374 -0
- package/src/app/(dashboard)/admin/hospitals/[hospitalId]/edit/page.tsx +304 -0
- package/src/app/(dashboard)/admin/hospitals/[hospitalId]/page.tsx +94 -0
- package/src/app/(dashboard)/admin/hospitals/new/page.tsx +302 -0
- package/src/app/(dashboard)/admin/hospitals/page.tsx +6 -0
- package/src/app/(dashboard)/admin/layout.tsx +49 -0
- package/src/app/(dashboard)/admin/organizations/[orgId]/edit/page.tsx +172 -0
- package/src/app/(dashboard)/admin/organizations/[orgId]/page.tsx +82 -0
- package/src/app/(dashboard)/admin/organizations/new/page.tsx +150 -0
- package/src/app/(dashboard)/admin/organizations/page.tsx +6 -0
- package/src/app/(dashboard)/admin/page.tsx +258 -0
- package/src/app/(dashboard)/admin/roles/page.tsx +153 -0
- package/src/app/(dashboard)/admin/settings/page.tsx +69 -0
- package/src/app/(dashboard)/admin/users/[userId]/edit/page.tsx +153 -0
- package/src/app/(dashboard)/admin/users/[userId]/page.tsx +317 -0
- package/src/app/(dashboard)/admin/users/invite/page.tsx +3 -0
- package/src/app/(dashboard)/admin/users/new/page.tsx +5 -0
- package/src/app/(dashboard)/admin/users/page.tsx +23 -0
- package/src/app/(dashboard)/dashboard/page.tsx +462 -0
- package/src/app/(dashboard)/departments/[deptId]/page.tsx +39 -0
- package/src/app/(dashboard)/departments/new/page.tsx +330 -0
- package/src/app/(dashboard)/departments/page.tsx +52 -0
- package/src/app/(dashboard)/devices/[id]/edit/page.tsx +131 -0
- package/src/app/(dashboard)/devices/[id]/page.tsx +408 -0
- package/src/app/(dashboard)/devices/[id]/qr/page.tsx +54 -0
- package/src/app/(dashboard)/devices/new/page.tsx +382 -0
- package/src/app/(dashboard)/devices/page.tsx +80 -0
- package/src/app/(dashboard)/engineering-team/page.tsx +41 -0
- package/src/app/(dashboard)/layout.tsx +43 -0
- package/src/app/(dashboard)/maintenance/checklists/page.tsx +57 -0
- package/src/app/(dashboard)/maintenance/page.tsx +231 -0
- package/src/app/(dashboard)/maintenance/plans/page.tsx +142 -0
- package/src/app/(dashboard)/maintenance/tasks/[id]/page.tsx +997 -0
- package/src/app/(dashboard)/maintenance/tasks/page.tsx +119 -0
- package/src/app/(dashboard)/more/page.tsx +310 -0
- package/src/app/(dashboard)/my-department/page.tsx +151 -0
- package/src/app/(dashboard)/notifications/notification-list.tsx +103 -0
- package/src/app/(dashboard)/notifications/page.tsx +59 -0
- package/src/app/(dashboard)/profile/page.tsx +27 -0
- package/src/app/(dashboard)/reports/costs/page.tsx +127 -0
- package/src/app/(dashboard)/reports/history/page.tsx +105 -0
- package/src/app/(dashboard)/reports/inventory/page.tsx +116 -0
- package/src/app/(dashboard)/reports/maintenance/page.tsx +136 -0
- package/src/app/(dashboard)/reports/page.tsx +120 -0
- package/src/app/(dashboard)/reports/tickets/page.tsx +139 -0
- package/src/app/(dashboard)/reports/workload/page.tsx +135 -0
- package/src/app/(dashboard)/rounds/[id]/page.tsx +197 -0
- package/src/app/(dashboard)/rounds/history/page.tsx +82 -0
- package/src/app/(dashboard)/rounds/page.tsx +107 -0
- package/src/app/(dashboard)/scan/[code]/page.tsx +154 -0
- package/src/app/(dashboard)/scan/page.tsx +73 -0
- package/src/app/(dashboard)/team/page.tsx +42 -0
- package/src/app/(dashboard)/tickets/[id]/page.tsx +465 -0
- package/src/app/(dashboard)/tickets/create/page.tsx +722 -0
- package/src/app/(dashboard)/tickets/page.tsx +55 -0
- package/src/app/(dashboard)/tickets/triage/page.tsx +161 -0
- package/src/app/api/admin/data/export/route.ts +316 -0
- package/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/src/app/api/health/route.ts +46 -0
- package/src/app/api/notifications/sse/route.ts +91 -0
- package/src/app/api/notifications/subscribe/route.ts +54 -0
- package/src/app/api/notifications/vapid-key/route.ts +7 -0
- package/src/app/api/reports/export/route.ts +102 -0
- package/src/app/api/tickets/[id]/attachments/route.ts +129 -0
- package/src/app/api/tickets/[id]/live-sync/route.ts +52 -0
- package/src/app/error.tsx +54 -0
- package/src/app/globals.css +89 -0
- package/src/app/layout.tsx +59 -0
- package/src/app/not-found.tsx +32 -0
- package/src/app/page.tsx +5 -0
- package/src/components/admin/add-department-user-dialog.tsx +759 -0
- package/src/components/admin/add-engineer-dialog.tsx +773 -0
- package/src/components/admin/add-user-type-dialog.tsx +89 -0
- package/src/components/admin/audit-log-export.tsx +113 -0
- package/src/components/admin/audit-log-filters.tsx +255 -0
- package/src/components/admin/audit-log-table.tsx +383 -0
- package/src/components/admin/data-management/danger-zone.tsx +301 -0
- package/src/components/admin/data-management/data-management-tabs.tsx +61 -0
- package/src/components/admin/data-management/export-center.tsx +301 -0
- package/src/components/admin/data-management/import-wizard.tsx +558 -0
- package/src/components/admin/settings-forms/features-form.tsx +115 -0
- package/src/components/admin/settings-forms/health-panel.tsx +182 -0
- package/src/components/admin/settings-forms/localization-form.tsx +203 -0
- package/src/components/admin/settings-forms/retention-form.tsx +164 -0
- package/src/components/admin/settings-forms/security-form.tsx +186 -0
- package/src/components/admin/system-settings-tabs.tsx +88 -0
- package/src/components/admin/user-role-dialog.tsx +293 -0
- package/src/components/admin/user-status-dialog.tsx +166 -0
- package/src/components/admin/users-page-client.tsx +514 -0
- package/src/components/dashboard/action-buttons.tsx +93 -0
- package/src/components/dashboard/admin-alerts.tsx +86 -0
- package/src/components/dashboard/availability-alerts.tsx +65 -0
- package/src/components/dashboard/maintenance-due-list.tsx +87 -0
- package/src/components/dashboard/round-widget.tsx +110 -0
- package/src/components/dashboard/stat-card.tsx +38 -0
- package/src/components/dashboard/ticket-list-compact.tsx +86 -0
- package/src/components/departments/department-cards-view.tsx +244 -0
- package/src/components/departments/department-detail-view.tsx +467 -0
- package/src/components/departments/department-visuals.tsx +190 -0
- package/src/components/departments/my-department-view.tsx +333 -0
- package/src/components/devices/change-status-dialog.tsx +146 -0
- package/src/components/devices/device-action-buttons.tsx +125 -0
- package/src/components/devices/device-availability-banner.tsx +59 -0
- package/src/components/devices/device-badges.tsx +55 -0
- package/src/components/devices/device-documents-tab.tsx +93 -0
- package/src/components/devices/device-maintenance-tab.tsx +113 -0
- package/src/components/devices/device-mini-qr.tsx +109 -0
- package/src/components/devices/device-qr-card.tsx +187 -0
- package/src/components/devices/device-signatures-tab.tsx +607 -0
- package/src/components/devices/device-tickets-tab.tsx +139 -0
- package/src/components/devices/device-timelines.tsx +124 -0
- package/src/components/devices/qr-camera-scanner.tsx +167 -0
- package/src/components/devices/qr-code-display.tsx +139 -0
- package/src/components/devices/quick-add-category-dialog.tsx +135 -0
- package/src/components/devices/quick-add-manufacturer-dialog.tsx +212 -0
- package/src/components/devices/transfer-device-dialog.tsx +190 -0
- package/src/components/layout/header.tsx +80 -0
- package/src/components/layout/mobile-nav.tsx +91 -0
- package/src/components/layout/more-item-badge.tsx +15 -0
- package/src/components/layout/nav-badge.tsx +72 -0
- package/src/components/layout/sidebar.tsx +297 -0
- package/src/components/maintenance/maintenance-badges.tsx +579 -0
- package/src/components/maintenance/maintenance-nav.tsx +107 -0
- package/src/components/maintenance/parts-costs-manager.tsx +909 -0
- package/src/components/maintenance/signature-card.tsx +413 -0
- package/src/components/maintenance/task-action-bar.tsx +955 -0
- package/src/components/notifications/notification-bell.tsx +367 -0
- package/src/components/notifications/notification-item.tsx +93 -0
- package/src/components/notifications/notification-preferences.tsx +182 -0
- package/src/components/profile/user-profile-view.tsx +626 -0
- package/src/components/providers/nav-counts-provider.tsx +235 -0
- package/src/components/providers/session-provider.tsx +7 -0
- package/src/components/providers/theme-provider.tsx +124 -0
- package/src/components/pwa/install-prompt.tsx +82 -0
- package/src/components/pwa/sw-register.tsx +43 -0
- package/src/components/reports/export-button.tsx +62 -0
- package/src/components/reports/filter-chips.tsx +47 -0
- package/src/components/reports/summary-cards.tsx +40 -0
- package/src/components/reports/transparency-header.tsx +54 -0
- package/src/components/rounds/department-visit-sheet.tsx +199 -0
- package/src/components/rounds/mention-textarea.tsx +187 -0
- package/src/components/rounds/round-calendar.tsx +233 -0
- package/src/components/rounds/round-department-list.tsx +281 -0
- package/src/components/rounds/round-history-client.tsx +218 -0
- package/src/components/rounds/start-round-card.tsx +184 -0
- package/src/components/shared/confirm-dialog.tsx +67 -0
- package/src/components/shared/data-table.tsx +104 -0
- package/src/components/shared/page-header.tsx +20 -0
- package/src/components/shared/sign-out-button.tsx +52 -0
- package/src/components/shared/status-badge.tsx +42 -0
- package/src/components/shared/table-search.tsx +55 -0
- package/src/components/signatures/sign-action-dialog.tsx +253 -0
- package/src/components/signatures/signature-history.tsx +121 -0
- package/src/components/signatures/signature-status-panel.tsx +164 -0
- package/src/components/team/department-coverage.tsx +141 -0
- package/src/components/team/edit-engineer-dialog.tsx +242 -0
- package/src/components/team/engineer-card.tsx +180 -0
- package/src/components/team/engineer-details-dialog.tsx +432 -0
- package/src/components/team/schedule-calendar.tsx +204 -0
- package/src/components/team/staff-engineer-team-view.tsx +368 -0
- package/src/components/team/team-header-stats.tsx +88 -0
- package/src/components/team/team-page-client.tsx +216 -0
- package/src/components/theme/theme-selector-card.tsx +63 -0
- package/src/components/theme/theme-toggle.tsx +65 -0
- package/src/components/tickets/staff-status-label.tsx +58 -0
- package/src/components/tickets/staff-ticket-card.tsx +109 -0
- package/src/components/tickets/staff-ticket-progress-tracker.tsx +405 -0
- package/src/components/tickets/staff-tickets-view.tsx +182 -0
- package/src/components/tickets/ticket-action-buttons.tsx +873 -0
- package/src/components/tickets/ticket-auto-refresh.tsx +197 -0
- package/src/components/tickets/ticket-badges.tsx +43 -0
- package/src/components/tickets/ticket-card.tsx +197 -0
- package/src/components/tickets/ticket-cards-view.tsx +395 -0
- package/src/components/tickets/ticket-comment-section.tsx +684 -0
- package/src/components/tickets/ticket-dispatch-status.tsx +184 -0
- package/src/components/tickets/ticket-list-auto-refresh.tsx +55 -0
- package/src/components/tickets/ticket-reporter-profile.tsx +235 -0
- package/src/components/tickets/ticket-signatures-panel.tsx +32 -0
- package/src/components/tickets/ticket-timeline.tsx +131 -0
- package/src/components/tickets/ticket-triage-panel.tsx +124 -0
- package/src/components/tickets/tickets-nav.tsx +107 -0
- package/src/components/ui/avatar.tsx +43 -0
- package/src/components/ui/badge.tsx +34 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/card.tsx +77 -0
- package/src/components/ui/checkbox.tsx +31 -0
- package/src/components/ui/dialog.tsx +123 -0
- package/src/components/ui/dropdown-menu.tsx +126 -0
- package/src/components/ui/form.tsx +179 -0
- package/src/components/ui/input.tsx +24 -0
- package/src/components/ui/label.tsx +27 -0
- package/src/components/ui/popover.tsx +34 -0
- package/src/components/ui/progress.tsx +36 -0
- package/src/components/ui/scroll-area.tsx +47 -0
- package/src/components/ui/select.tsx +160 -0
- package/src/components/ui/separator.tsx +25 -0
- package/src/components/ui/sheet.tsx +131 -0
- package/src/components/ui/switch.tsx +30 -0
- package/src/components/ui/table.tsx +121 -0
- package/src/components/ui/tabs.tsx +62 -0
- package/src/components/ui/textarea.tsx +23 -0
- package/src/components/ui/tooltip.tsx +27 -0
- package/src/lib/actions/__tests__/devices.test.ts +176 -0
- package/src/lib/actions/__tests__/signatures.test.ts +303 -0
- package/src/lib/actions/__tests__/tickets.test.ts +243 -0
- package/src/lib/actions/audit-logs.ts +298 -0
- package/src/lib/actions/checklists.ts +429 -0
- package/src/lib/actions/dashboard.ts +358 -0
- package/src/lib/actions/data-management.ts +723 -0
- package/src/lib/actions/departments.ts +369 -0
- package/src/lib/actions/device-categories.ts +117 -0
- package/src/lib/actions/devices.ts +748 -0
- package/src/lib/actions/engineer-rounds.ts +973 -0
- package/src/lib/actions/engineers.ts +285 -0
- package/src/lib/actions/hospitals.ts +148 -0
- package/src/lib/actions/locations.ts +115 -0
- package/src/lib/actions/maintenance-plans.ts +316 -0
- package/src/lib/actions/maintenance-tasks.ts +415 -0
- package/src/lib/actions/manufacturers.ts +132 -0
- package/src/lib/actions/nav-counts.ts +144 -0
- package/src/lib/actions/notifications.ts +136 -0
- package/src/lib/actions/organizations.ts +99 -0
- package/src/lib/actions/qr.ts +147 -0
- package/src/lib/actions/report-history.ts +77 -0
- package/src/lib/actions/reports.ts +192 -0
- package/src/lib/actions/roles.ts +32 -0
- package/src/lib/actions/signature-auth.ts +377 -0
- package/src/lib/actions/signatures.ts +532 -0
- package/src/lib/actions/system-settings.ts +274 -0
- package/src/lib/actions/tickets.ts +1445 -0
- package/src/lib/actions/users.ts +740 -0
- package/src/lib/audit/index.ts +103 -0
- package/src/lib/auth/__tests__/rbac.test.ts +33 -0
- package/src/lib/auth/index.ts +338 -0
- package/src/lib/auth/password.ts +10 -0
- package/src/lib/auth/rbac.ts +103 -0
- package/src/lib/auth/types.ts +57 -0
- package/src/lib/constants/departments.ts +16 -0
- package/src/lib/constants/manufacturers.ts +32 -0
- package/src/lib/db/index.ts +23 -0
- package/src/lib/db/schema/audit-logs.ts +42 -0
- package/src/lib/db/schema/departments.ts +39 -0
- package/src/lib/db/schema/device-categories.ts +38 -0
- package/src/lib/db/schema/devices.ts +195 -0
- package/src/lib/db/schema/engineer-profiles.ts +63 -0
- package/src/lib/db/schema/engineer-rounds.ts +115 -0
- package/src/lib/db/schema/enums.ts +148 -0
- package/src/lib/db/schema/hospitals.ts +34 -0
- package/src/lib/db/schema/index.ts +24 -0
- package/src/lib/db/schema/locations.ts +46 -0
- package/src/lib/db/schema/maintenance-plans.ts +99 -0
- package/src/lib/db/schema/maintenance-records.ts +161 -0
- package/src/lib/db/schema/maintenance-tasks.ts +196 -0
- package/src/lib/db/schema/manufacturers.ts +60 -0
- package/src/lib/db/schema/notifications.ts +48 -0
- package/src/lib/db/schema/organizations.ts +24 -0
- package/src/lib/db/schema/report-history.ts +28 -0
- package/src/lib/db/schema/roles.ts +59 -0
- package/src/lib/db/schema/sessions.ts +46 -0
- package/src/lib/db/schema/signature-events.ts +48 -0
- package/src/lib/db/schema/signature-policies.ts +60 -0
- package/src/lib/db/schema/signatures.ts +87 -0
- package/src/lib/db/schema/tickets.ts +169 -0
- package/src/lib/db/schema/user-assignments.ts +85 -0
- package/src/lib/db/schema/users.ts +39 -0
- package/src/lib/db/seed.ts +131 -0
- package/src/lib/logger/__tests__/logger.test.ts +154 -0
- package/src/lib/logger/formatters.ts +159 -0
- package/src/lib/logger/index.ts +184 -0
- package/src/lib/logger/types.ts +48 -0
- package/src/lib/notifications/create.ts +71 -0
- package/src/lib/notifications/dispatcher.ts +490 -0
- package/src/lib/notifications/index.ts +7 -0
- package/src/lib/notifications/push-sender.ts +128 -0
- package/src/lib/notifications/push.ts +64 -0
- package/src/lib/notifications/triggers.ts +166 -0
- package/src/lib/utils/__tests__/crypto.test.ts +30 -0
- package/src/lib/utils/__tests__/export.test.ts +55 -0
- package/src/lib/utils/__tests__/nav-badge.test.ts +147 -0
- package/src/lib/utils/__tests__/staff-status.test.ts +50 -0
- package/src/lib/utils/attestations.ts +19 -0
- package/src/lib/utils/crypto.ts +18 -0
- package/src/lib/utils/csv-parser.ts +181 -0
- package/src/lib/utils/export.ts +45 -0
- package/src/lib/utils/nav-badge.ts +225 -0
- package/src/lib/utils/sound.ts +152 -0
- package/src/lib/utils/staff-status.ts +115 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validators/__tests__/auth.test.ts +127 -0
- package/src/lib/validators/__tests__/data-management.test.ts +182 -0
- package/src/lib/validators/__tests__/devices-profile.test.ts +129 -0
- package/src/lib/validators/__tests__/devices.test.ts +98 -0
- package/src/lib/validators/__tests__/engineer-rounds.test.ts +170 -0
- package/src/lib/validators/__tests__/maintenance.test.ts +178 -0
- package/src/lib/validators/__tests__/signatures.test.ts +154 -0
- package/src/lib/validators/__tests__/system-settings.test.ts +119 -0
- package/src/lib/validators/__tests__/tickets.test.ts +176 -0
- package/src/lib/validators/__tests__/users.test.ts +92 -0
- package/src/lib/validators/auth.ts +32 -0
- package/src/lib/validators/data-management.ts +67 -0
- package/src/lib/validators/departments.ts +14 -0
- package/src/lib/validators/devices.ts +94 -0
- package/src/lib/validators/engineer-rounds.ts +70 -0
- package/src/lib/validators/hospitals.ts +17 -0
- package/src/lib/validators/locations.ts +15 -0
- package/src/lib/validators/maintenance.ts +211 -0
- package/src/lib/validators/organizations.ts +11 -0
- package/src/lib/validators/reports.ts +31 -0
- package/src/lib/validators/signatures.ts +49 -0
- package/src/lib/validators/system-settings.ts +55 -0
- package/src/lib/validators/tickets.ts +125 -0
- package/src/lib/validators/users.ts +43 -0
- package/src/middleware.ts +45 -0
- package/tailwind.config.ts +76 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useState, useMemo } from "react"
|
|
4
|
+
import Link from "next/link"
|
|
5
|
+
import { TicketCard, TicketItem, getTicketStatusStyle } from "./ticket-card"
|
|
6
|
+
import { TicketPriorityBadge, TicketStatusBadge } from "./ticket-badges"
|
|
7
|
+
import { Button } from "@/components/ui/button"
|
|
8
|
+
import { Input } from "@/components/ui/input"
|
|
9
|
+
import { Badge } from "@/components/ui/badge"
|
|
10
|
+
import {
|
|
11
|
+
Table,
|
|
12
|
+
TableBody,
|
|
13
|
+
TableCell,
|
|
14
|
+
TableHead,
|
|
15
|
+
TableHeader,
|
|
16
|
+
TableRow,
|
|
17
|
+
} from "@/components/ui/table"
|
|
18
|
+
import {
|
|
19
|
+
LayoutGrid,
|
|
20
|
+
Table as TableIcon,
|
|
21
|
+
Search,
|
|
22
|
+
X,
|
|
23
|
+
Inbox,
|
|
24
|
+
Filter,
|
|
25
|
+
} from "lucide-react"
|
|
26
|
+
import { WaitingForEngineerBanner } from "./ticket-dispatch-status"
|
|
27
|
+
import { cn } from "@/lib/utils"
|
|
28
|
+
|
|
29
|
+
interface TicketCardsViewProps {
|
|
30
|
+
tickets: TicketItem[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type StatusCategory = "all" | "new" | "in_progress" | "waiting_parts_vendor" | "resolved" | "closed"
|
|
34
|
+
|
|
35
|
+
export function TicketCardsView({ tickets }: TicketCardsViewProps) {
|
|
36
|
+
const [viewMode, setViewMode] = useState<"cards" | "table">("cards")
|
|
37
|
+
const [statusFilter, setStatusFilter] = useState<StatusCategory>("all")
|
|
38
|
+
const [searchQuery, setSearchQuery] = useState("")
|
|
39
|
+
|
|
40
|
+
// Compute category counts
|
|
41
|
+
const counts = useMemo(() => {
|
|
42
|
+
const res = {
|
|
43
|
+
all: tickets.length,
|
|
44
|
+
new: 0,
|
|
45
|
+
in_progress: 0,
|
|
46
|
+
waiting_parts_vendor: 0,
|
|
47
|
+
resolved: 0,
|
|
48
|
+
closed: 0,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
tickets.forEach((t) => {
|
|
52
|
+
if (["new", "acknowledged", "in_triage"].includes(t.statusCode)) {
|
|
53
|
+
res.new++
|
|
54
|
+
} else if (t.statusCode === "in_progress") {
|
|
55
|
+
res.in_progress++
|
|
56
|
+
} else if (["waiting_parts_vendor", "waiting_requester"].includes(t.statusCode)) {
|
|
57
|
+
res.waiting_parts_vendor++
|
|
58
|
+
} else if (t.statusCode === "resolved") {
|
|
59
|
+
res.resolved++
|
|
60
|
+
} else if (["closed", "cancelled"].includes(t.statusCode)) {
|
|
61
|
+
res.closed++
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return res
|
|
66
|
+
}, [tickets])
|
|
67
|
+
|
|
68
|
+
// Filtered tickets
|
|
69
|
+
const filteredTickets = useMemo(() => {
|
|
70
|
+
return tickets.filter((t) => {
|
|
71
|
+
// 1. Status Filter
|
|
72
|
+
if (statusFilter === "new" && !["new", "acknowledged", "in_triage"].includes(t.statusCode)) {
|
|
73
|
+
return false
|
|
74
|
+
}
|
|
75
|
+
if (statusFilter === "in_progress" && t.statusCode !== "in_progress") {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
statusFilter === "waiting_parts_vendor" &&
|
|
80
|
+
!["waiting_parts_vendor", "waiting_requester"].includes(t.statusCode)
|
|
81
|
+
) {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
if (statusFilter === "resolved" && t.statusCode !== "resolved") {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
if (statusFilter === "closed" && !["closed", "cancelled"].includes(t.statusCode)) {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 2. Search Query
|
|
92
|
+
if (searchQuery.trim()) {
|
|
93
|
+
const query = searchQuery.toLowerCase()
|
|
94
|
+
const matchTitle = t.title?.toLowerCase().includes(query)
|
|
95
|
+
const matchNumber = t.ticketNumber?.toLowerCase().includes(query)
|
|
96
|
+
const matchDevice = t.device?.name?.toLowerCase().includes(query) || t.device?.assetNumber?.toLowerCase().includes(query)
|
|
97
|
+
const matchDept = t.department?.name?.toLowerCase().includes(query) || t.hospital?.name?.toLowerCase().includes(query)
|
|
98
|
+
const matchReporter = t.reportedByUser?.fullName?.toLowerCase().includes(query)
|
|
99
|
+
const matchAssignee = t.assignedEngineer?.fullName?.toLowerCase().includes(query)
|
|
100
|
+
const matchParts = t.waitingReason?.toLowerCase().includes(query)
|
|
101
|
+
|
|
102
|
+
if (!matchTitle && !matchNumber && !matchDevice && !matchDept && !matchReporter && !matchAssignee && !matchParts) {
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return true
|
|
108
|
+
})
|
|
109
|
+
}, [tickets, statusFilter, searchQuery])
|
|
110
|
+
|
|
111
|
+
const filterButtons: Array<{
|
|
112
|
+
id: StatusCategory
|
|
113
|
+
label: string
|
|
114
|
+
count: number
|
|
115
|
+
dotColor?: string
|
|
116
|
+
activeClass: string
|
|
117
|
+
}> = [
|
|
118
|
+
{
|
|
119
|
+
id: "all",
|
|
120
|
+
label: "All Tickets",
|
|
121
|
+
count: counts.all,
|
|
122
|
+
activeClass: "bg-slate-900 text-white dark:bg-slate-100 dark:text-slate-900",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "new",
|
|
126
|
+
label: "New / Unassigned",
|
|
127
|
+
count: counts.new,
|
|
128
|
+
dotColor: "bg-rose-500",
|
|
129
|
+
activeClass: "bg-rose-600 text-white dark:bg-rose-600",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "in_progress",
|
|
133
|
+
label: "In Progress",
|
|
134
|
+
count: counts.in_progress,
|
|
135
|
+
dotColor: "bg-amber-500",
|
|
136
|
+
activeClass: "bg-amber-600 text-white dark:bg-amber-600",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "waiting_parts_vendor",
|
|
140
|
+
label: "Waiting for Parts",
|
|
141
|
+
count: counts.waiting_parts_vendor,
|
|
142
|
+
dotColor: "bg-orange-500",
|
|
143
|
+
activeClass: "bg-orange-600 text-white dark:bg-orange-600",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: "resolved",
|
|
147
|
+
label: "Resolved",
|
|
148
|
+
count: counts.resolved,
|
|
149
|
+
dotColor: "bg-emerald-500",
|
|
150
|
+
activeClass: "bg-emerald-600 text-white dark:bg-emerald-600",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: "closed",
|
|
154
|
+
label: "Closed",
|
|
155
|
+
count: counts.closed,
|
|
156
|
+
dotColor: "bg-slate-400",
|
|
157
|
+
activeClass: "bg-slate-600 text-white dark:bg-slate-600",
|
|
158
|
+
},
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div className="space-y-4">
|
|
163
|
+
{/* Control Bar: Search, Filters, and View Toggle */}
|
|
164
|
+
<div className="flex flex-col sm:flex-row gap-3 items-stretch sm:items-center justify-between">
|
|
165
|
+
{/* Search Input */}
|
|
166
|
+
<div className="relative flex-1 max-w-md">
|
|
167
|
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
168
|
+
<Input
|
|
169
|
+
value={searchQuery}
|
|
170
|
+
onChange={(e) => setSearchQuery(e.target.value)}
|
|
171
|
+
placeholder="Search tickets by title, number, device, department..."
|
|
172
|
+
className="pl-9 pr-8 h-10 text-sm"
|
|
173
|
+
/>
|
|
174
|
+
{searchQuery && (
|
|
175
|
+
<button
|
|
176
|
+
onClick={() => setSearchQuery("")}
|
|
177
|
+
className="absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
|
178
|
+
>
|
|
179
|
+
<X className="w-4 h-4" />
|
|
180
|
+
</button>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
{/* View Toggle */}
|
|
185
|
+
<div className="flex items-center gap-1 self-end sm:self-auto bg-muted/60 p-1 rounded-lg border border-border/60">
|
|
186
|
+
<Button
|
|
187
|
+
variant={viewMode === "cards" ? "default" : "ghost"}
|
|
188
|
+
size="sm"
|
|
189
|
+
onClick={() => setViewMode("cards")}
|
|
190
|
+
className="h-8 gap-1.5 text-xs px-3"
|
|
191
|
+
>
|
|
192
|
+
<LayoutGrid className="w-3.5 h-3.5" />
|
|
193
|
+
<span>Cards</span>
|
|
194
|
+
</Button>
|
|
195
|
+
<Button
|
|
196
|
+
variant={viewMode === "table" ? "default" : "ghost"}
|
|
197
|
+
size="sm"
|
|
198
|
+
onClick={() => setViewMode("table")}
|
|
199
|
+
className="h-8 gap-1.5 text-xs px-3"
|
|
200
|
+
>
|
|
201
|
+
<TableIcon className="w-3.5 h-3.5" />
|
|
202
|
+
<span>Table</span>
|
|
203
|
+
</Button>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
{/* Status Filter Pills */}
|
|
208
|
+
<div className="flex items-center gap-2 overflow-x-auto pb-1 scrollbar-none">
|
|
209
|
+
{filterButtons.map((btn) => {
|
|
210
|
+
const isActive = statusFilter === btn.id
|
|
211
|
+
return (
|
|
212
|
+
<button
|
|
213
|
+
key={btn.id}
|
|
214
|
+
onClick={() => setStatusFilter(btn.id)}
|
|
215
|
+
className={cn(
|
|
216
|
+
"inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-xs font-medium transition-all whitespace-nowrap border shrink-0",
|
|
217
|
+
isActive
|
|
218
|
+
? `${btn.activeClass} border-transparent shadow-sm`
|
|
219
|
+
: "bg-background border-border hover:bg-muted text-muted-foreground hover:text-foreground"
|
|
220
|
+
)}
|
|
221
|
+
>
|
|
222
|
+
{btn.dotColor && (
|
|
223
|
+
<span
|
|
224
|
+
className={cn(
|
|
225
|
+
"w-2 h-2 rounded-full",
|
|
226
|
+
isActive ? "bg-white" : btn.dotColor
|
|
227
|
+
)}
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
<span>{btn.label}</span>
|
|
231
|
+
<span
|
|
232
|
+
className={cn(
|
|
233
|
+
"px-1.5 py-0.2 rounded-full text-[11px] font-mono",
|
|
234
|
+
isActive
|
|
235
|
+
? "bg-white/20 text-white"
|
|
236
|
+
: "bg-muted text-muted-foreground"
|
|
237
|
+
)}
|
|
238
|
+
>
|
|
239
|
+
{btn.count}
|
|
240
|
+
</span>
|
|
241
|
+
</button>
|
|
242
|
+
)
|
|
243
|
+
})}
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
{/* Filter summary when search or non-all filter is active */}
|
|
247
|
+
{(statusFilter !== "all" || searchQuery) && (
|
|
248
|
+
<div className="flex items-center justify-between text-xs text-muted-foreground px-1">
|
|
249
|
+
<span>
|
|
250
|
+
Showing <strong>{filteredTickets.length}</strong> of {tickets.length} tickets
|
|
251
|
+
{statusFilter !== "all" ? ` in ${filterButtons.find(b => b.id === statusFilter)?.label}` : ""}
|
|
252
|
+
{searchQuery ? ` matching "${searchQuery}"` : ""}
|
|
253
|
+
</span>
|
|
254
|
+
<button
|
|
255
|
+
onClick={() => {
|
|
256
|
+
setStatusFilter("all")
|
|
257
|
+
setSearchQuery("")
|
|
258
|
+
}}
|
|
259
|
+
className="text-primary hover:underline font-medium"
|
|
260
|
+
>
|
|
261
|
+
Clear all filters
|
|
262
|
+
</button>
|
|
263
|
+
</div>
|
|
264
|
+
)}
|
|
265
|
+
|
|
266
|
+
{/* Empty State */}
|
|
267
|
+
{filteredTickets.length === 0 ? (
|
|
268
|
+
<div className="rounded-xl border border-dashed border-border bg-card p-12 text-center">
|
|
269
|
+
<Inbox className="w-10 h-10 text-muted-foreground/60 mx-auto mb-3" />
|
|
270
|
+
<h3 className="font-semibold text-base mb-1">No matching tickets</h3>
|
|
271
|
+
<p className="text-sm text-muted-foreground max-w-sm mx-auto mb-4">
|
|
272
|
+
{searchQuery
|
|
273
|
+
? `No tickets found matching "${searchQuery}". Try a different search term or clear filters.`
|
|
274
|
+
: "No tickets found in this status category."}
|
|
275
|
+
</p>
|
|
276
|
+
<Button
|
|
277
|
+
variant="outline"
|
|
278
|
+
size="sm"
|
|
279
|
+
onClick={() => {
|
|
280
|
+
setStatusFilter("all")
|
|
281
|
+
setSearchQuery("")
|
|
282
|
+
}}
|
|
283
|
+
>
|
|
284
|
+
Reset Filters
|
|
285
|
+
</Button>
|
|
286
|
+
</div>
|
|
287
|
+
) : viewMode === "cards" ? (
|
|
288
|
+
/* Cards Grid View */
|
|
289
|
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
290
|
+
{filteredTickets.map((ticket) => (
|
|
291
|
+
<TicketCard key={ticket.id} ticket={ticket} />
|
|
292
|
+
))}
|
|
293
|
+
</div>
|
|
294
|
+
) : (
|
|
295
|
+
/* Table View with Status Accent Rails */
|
|
296
|
+
<div className="rounded-lg border bg-card overflow-hidden shadow-sm">
|
|
297
|
+
<Table>
|
|
298
|
+
<TableHeader>
|
|
299
|
+
<TableRow className="bg-muted/40">
|
|
300
|
+
<TableHead className="w-[140px]">Ticket #</TableHead>
|
|
301
|
+
<TableHead>Title</TableHead>
|
|
302
|
+
<TableHead>Device</TableHead>
|
|
303
|
+
<TableHead className="hidden md:table-cell">Department</TableHead>
|
|
304
|
+
<TableHead>Priority</TableHead>
|
|
305
|
+
<TableHead>Status</TableHead>
|
|
306
|
+
<TableHead className="hidden lg:table-cell">Assigned To</TableHead>
|
|
307
|
+
<TableHead className="hidden sm:table-cell text-right">Date</TableHead>
|
|
308
|
+
</TableRow>
|
|
309
|
+
</TableHeader>
|
|
310
|
+
<TableBody>
|
|
311
|
+
{filteredTickets.map((ticket) => {
|
|
312
|
+
const style = getTicketStatusStyle(ticket.statusCode)
|
|
313
|
+
return (
|
|
314
|
+
<TableRow
|
|
315
|
+
key={ticket.id}
|
|
316
|
+
className={cn(
|
|
317
|
+
"transition-colors border-l-4 hover:bg-muted/40",
|
|
318
|
+
style.rail
|
|
319
|
+
)}
|
|
320
|
+
>
|
|
321
|
+
<TableCell className="font-mono text-xs font-semibold">
|
|
322
|
+
<Link
|
|
323
|
+
href={`/tickets/${ticket.id}`}
|
|
324
|
+
className="text-primary hover:underline"
|
|
325
|
+
>
|
|
326
|
+
{ticket.ticketNumber}
|
|
327
|
+
</Link>
|
|
328
|
+
</TableCell>
|
|
329
|
+
<TableCell>
|
|
330
|
+
<Link
|
|
331
|
+
href={`/tickets/${ticket.id}`}
|
|
332
|
+
className="font-medium hover:underline line-clamp-1 text-sm text-foreground"
|
|
333
|
+
>
|
|
334
|
+
{ticket.title}
|
|
335
|
+
</Link>
|
|
336
|
+
{ticket.statusCode === "waiting_parts_vendor" && ticket.waitingReason && (
|
|
337
|
+
<span className="text-[11px] text-orange-700 dark:text-orange-300 block truncate">
|
|
338
|
+
📦 On Order: {ticket.waitingReason}
|
|
339
|
+
</span>
|
|
340
|
+
)}
|
|
341
|
+
</TableCell>
|
|
342
|
+
<TableCell className="text-sm">
|
|
343
|
+
<span className="font-medium text-foreground block truncate">
|
|
344
|
+
{ticket.device?.name || "—"}
|
|
345
|
+
</span>
|
|
346
|
+
{ticket.device?.assetNumber && (
|
|
347
|
+
<span className="text-[11px] text-muted-foreground font-mono">
|
|
348
|
+
{ticket.device.assetNumber}
|
|
349
|
+
</span>
|
|
350
|
+
)}
|
|
351
|
+
</TableCell>
|
|
352
|
+
<TableCell className="hidden md:table-cell text-xs text-muted-foreground">
|
|
353
|
+
<span className="block truncate">
|
|
354
|
+
{ticket.hospital?.name ? `${ticket.hospital.name} / ` : ""}
|
|
355
|
+
{ticket.department?.name || "—"}
|
|
356
|
+
</span>
|
|
357
|
+
</TableCell>
|
|
358
|
+
<TableCell>
|
|
359
|
+
<TicketPriorityBadge priority={ticket.priorityCode} />
|
|
360
|
+
</TableCell>
|
|
361
|
+
<TableCell>
|
|
362
|
+
<TicketStatusBadge status={ticket.statusCode} />
|
|
363
|
+
</TableCell>
|
|
364
|
+
<TableCell className="hidden lg:table-cell text-xs">
|
|
365
|
+
{ticket.assignedEngineer?.fullName ? (
|
|
366
|
+
<span className="font-medium text-foreground">
|
|
367
|
+
{ticket.assignedEngineer.fullName}
|
|
368
|
+
</span>
|
|
369
|
+
) : ["new", "acknowledged", "in_triage"].includes(ticket.statusCode) ? (
|
|
370
|
+
<WaitingForEngineerBanner
|
|
371
|
+
compact
|
|
372
|
+
reportedAt={ticket.reportedAt || ticket.createdAt || new Date()}
|
|
373
|
+
reportedImpact={ticket.reportedImpact || undefined}
|
|
374
|
+
/>
|
|
375
|
+
) : (
|
|
376
|
+
<span className="text-rose-600 dark:text-rose-400 font-semibold">
|
|
377
|
+
Unassigned
|
|
378
|
+
</span>
|
|
379
|
+
)}
|
|
380
|
+
</TableCell>
|
|
381
|
+
<TableCell className="hidden sm:table-cell text-right text-xs text-muted-foreground whitespace-nowrap">
|
|
382
|
+
{new Date(
|
|
383
|
+
ticket.reportedAt || ticket.createdAt || Date.now()
|
|
384
|
+
).toLocaleDateString()}
|
|
385
|
+
</TableCell>
|
|
386
|
+
</TableRow>
|
|
387
|
+
)
|
|
388
|
+
})}
|
|
389
|
+
</TableBody>
|
|
390
|
+
</Table>
|
|
391
|
+
</div>
|
|
392
|
+
)}
|
|
393
|
+
</div>
|
|
394
|
+
)
|
|
395
|
+
}
|