+
+ {onClose && (
+
+ )}

onClose?.()}
className={({ isActive }) =>
cn(
- "flex items-center gap-3 px-3 py-2.5 rounded-md text-sm transition-colors group",
+ "flex items-center gap-3 px-3 py-2.5 rounded-md text-sm transition-colors group focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white",
isActive
? "bg-blue-700 text-white"
: "text-blue-100 hover:bg-blue-700/50 hover:text-white"
@@ -125,8 +147,29 @@ export function Sidebar() {
{/* Footer */}
- Phase 1 — Foundation
+ Poona Hospital AMS • v1.0
);
+
+ // When controlled by AppShell, hide desktop rail on small screens and render slide-over drawer when open
+ if (mobileOpen === undefined) {
+ return asideContent;
+ }
+
+ return (
+ <>
+
{asideContent}
+ {mobileOpen && (
+
+ )}
+ >
+ );
}
diff --git a/frontend/src/components/layout/TopBar.tsx b/frontend/src/components/layout/TopBar.tsx
index 9a16eec..7ce395e 100644
--- a/frontend/src/components/layout/TopBar.tsx
+++ b/frontend/src/components/layout/TopBar.tsx
@@ -14,6 +14,10 @@ import {
AlertTriangle,
Info,
Clock,
+ Menu,
+ X,
+ Package,
+ AlertCircle,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { formatDate, formatRelative } from "@/lib/format";
@@ -21,14 +25,17 @@ import { ROLE_LABELS } from "@/lib/permissions";
import { useAuthStore } from "@/hooks/useAuth";
import { settingsApi } from "@/api/settings";
import { notificationsApi, type NotificationItem } from "@/api/notifications";
+import { searchApi } from "@/api/search";
import { Badge } from "@/components/ui/badge";
+import { AssetStatusBadge, CallStatusBadge } from "@/components/StatusBadge";
import { toast } from "@/components/ToastProvider";
interface TopBarProps {
title?: string;
+ onMenuClick?: () => void;
}
-export function TopBar({ title }: TopBarProps) {
+export function TopBar({ title, onMenuClick }: TopBarProps) {
const navigate = useNavigate();
const queryClient = useQueryClient();
const { user, demoAsOfDate, setDemoAsOfDate, logout } = useAuthStore();
@@ -39,26 +46,72 @@ export function TopBar({ title }: TopBarProps) {
const [savingDate, setSavingDate] = useState(false);
const [runningAlerts, setRunningAlerts] = useState(false);
+ const [searchInput, setSearchInput] = useState("");
+ const [debouncedQuery, setDebouncedQuery] = useState("");
+ const [searchOpen, setSearchOpen] = useState(false);
+
const bellContainerRef = useRef
(null);
+ const searchContainerRef = useRef(null);
+ const userMenuRef = useRef(null);
const seenIdsRef = useRef | null>(null);
useEffect(() => {
setDateInput(demoAsOfDate ?? "");
}, [demoAsOfDate]);
+ useEffect(() => {
+ const trimmed = searchInput.trim();
+ if (trimmed.length < 2) {
+ setDebouncedQuery("");
+ return;
+ }
+ const timer = window.setTimeout(() => {
+ setDebouncedQuery(trimmed);
+ }, 200);
+ return () => window.clearTimeout(timer);
+ }, [searchInput]);
+
useEffect(() => {
function handleOutside(e: MouseEvent) {
+ const target = e.target as Node;
if (
bellContainerRef.current &&
- !bellContainerRef.current.contains(e.target as Node)
+ !bellContainerRef.current.contains(target)
) {
setBellOpen(false);
}
+ if (
+ searchContainerRef.current &&
+ !searchContainerRef.current.contains(target)
+ ) {
+ setSearchOpen(false);
+ }
+ if (userMenuRef.current && !userMenuRef.current.contains(target)) {
+ setMenuOpen(false);
+ }
+ }
+ function handleKeyDown(e: KeyboardEvent) {
+ if (e.key === "Escape") {
+ setSearchOpen(false);
+ setBellOpen(false);
+ setMenuOpen(false);
+ }
}
document.addEventListener("mousedown", handleOutside);
- return () => document.removeEventListener("mousedown", handleOutside);
+ document.addEventListener("keydown", handleKeyDown);
+ return () => {
+ document.removeEventListener("mousedown", handleOutside);
+ document.removeEventListener("keydown", handleKeyDown);
+ };
}, []);
+ const searchQuery = useQuery({
+ queryKey: ["global-search", debouncedQuery, user?.id],
+ queryFn: () => searchApi.query(debouncedQuery),
+ enabled: Boolean(user) && debouncedQuery.length >= 2,
+ staleTime: 10_000,
+ });
+
const isAdmin = user?.role === "system_admin";
const bellQuery = useQuery({
@@ -178,6 +231,18 @@ export function TopBar({ title }: TopBarProps) {
return (
+ {/* Mobile nav toggle */}
+ {onMenuClick && (
+
+ )}
+
{/* Page title */}
{title && (
@@ -185,14 +250,151 @@ export function TopBar({ title }: TopBarProps) {
)}
- {/* Global search placeholder */}
-
-
+ {/* Live Global Quick Search */}
+
+
{
+ const val = e.target.value;
+ setSearchInput(val);
+ setSearchOpen(val.trim().length >= 2);
+ }}
+ onFocus={() => {
+ if (searchInput.trim().length >= 2) {
+ setSearchOpen(true);
+ }
+ }}
+ placeholder="Search assets, complaints..."
+ className="w-full pl-9 pr-8 py-1.5 text-sm border border-gray-200 rounded-md bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white"
/>
+ {searchInput && (
+
+ )}
+
+ {searchOpen && searchInput.trim().length >= 2 && (
+
+ {searchQuery.isFetching && !searchQuery.data ? (
+
+ Searching assets & complaints...
+
+ ) : searchQuery.isError ? (
+
+ Unable to load search results.
+
+ ) : (
+ (() => {
+ const assets = searchQuery.data?.assets ?? [];
+ const complaints = searchQuery.data?.complaints ?? [];
+ if (assets.length === 0 && complaints.length === 0) {
+ return (
+
+ No matching assets or complaints found.
+
+ );
+ }
+ return (
+ <>
+ {assets.length > 0 && (
+
+
+
+ Assets ({assets.length})
+
+ {assets.map((asset) => (
+
+ ))}
+
+ )}
+
+ {complaints.length > 0 && (
+
+
+
+ Complaints ({complaints.length})
+
+ {complaints.map((c) => (
+
+ ))}
+
+ )}
+ >
+ );
+ })()
+ )}
+
+ )}
{/* Active Demo Date Pill */}
@@ -254,8 +456,9 @@ export function TopBar({ title }: TopBarProps) {
{/* User menu */}
-
+
);
}
diff --git a/frontend/src/pages/InsurancePage.tsx b/frontend/src/pages/InsurancePage.tsx
index 33905aa..c713d63 100644
--- a/frontend/src/pages/InsurancePage.tsx
+++ b/frontend/src/pages/InsurancePage.tsx
@@ -25,6 +25,8 @@ import { ExpiryChip } from "@/components/StatusBadge";
import { AssetPicker } from "@/components/AssetPicker";
import { Attachments } from "@/components/Attachments";
import { InsuranceDrawer } from "@/components/InsuranceDrawer";
+import { ConfirmDialog } from "@/components/ConfirmDialog";
+import { toast } from "@/components/ToastProvider";
const inputCls =
"w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500";
@@ -55,6 +57,7 @@ export function InsurancePage() {
label: string;
} | null>(null);
const [attachPolicy, setAttachPolicy] = useState
(null);
+ const [deleteTarget, setDeleteTarget] = useState(null);
const deptsQuery = useQuery({
queryKey: ["departments", "active-only"],
@@ -82,8 +85,13 @@ export function InsurancePage() {
const deleteMutation = useMutation({
mutationFn: (id: number) => insuranceApi.remove(id),
onSuccess: () => {
+ setDeleteTarget(null);
qc.invalidateQueries({ queryKey: ["insurance"] });
qc.invalidateQueries({ queryKey: ["assets"] });
+ toast.success("Insurance policy deleted");
+ },
+ onError: (err) => {
+ toast.error(err instanceof ApiError ? err.detail : "Failed to delete insurance policy");
},
});
@@ -208,11 +216,7 @@ export function InsurancePage() {
size="sm"
variant="ghost"
className="text-red-600 hover:text-red-700"
- onClick={() => {
- if (window.confirm(`Delete policy ${row.original.policy_no}?`)) {
- deleteMutation.mutate(row.original.id);
- }
- }}
+ onClick={() => setDeleteTarget(row.original)}
aria-label={`Delete policy ${row.original.policy_no}`}
>
@@ -347,6 +351,19 @@ export function InsurancePage() {
/>
)}
+
+ !o && setDeleteTarget(null)}
+ title="Delete Insurance Policy"
+ message={`Are you sure you want to delete policy ${deleteTarget?.policy_no ?? ""}?`}
+ confirmLabel="Delete"
+ variant="danger"
+ loading={deleteMutation.isPending}
+ onConfirm={() => {
+ if (deleteTarget) deleteMutation.mutate(deleteTarget.id);
+ }}
+ />
);
}
diff --git a/frontend/src/test/phase8-polish.test.tsx b/frontend/src/test/phase8-polish.test.tsx
new file mode 100644
index 0000000..c085f3b
--- /dev/null
+++ b/frontend/src/test/phase8-polish.test.tsx
@@ -0,0 +1,201 @@
+import { describe, it, expect, beforeEach, vi } from "vitest";
+import { render, screen, fireEvent, waitFor } from "@testing-library/react";
+import { MemoryRouter, Routes, Route, useLocation } from "react-router-dom";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { TopBar } from "@/components/layout/TopBar";
+import { AuditLogsPage } from "@/pages/AuditLogsPage";
+import { ConfirmDialog } from "@/components/ConfirmDialog";
+import { ToastProvider } from "@/components/ToastProvider";
+import { useAuthStore } from "@/hooks/useAuth";
+import * as searchModule from "@/api/search";
+import * as auditModule from "@/api/audit";
+import * as mastersModule from "@/api/masters";
+import * as notificationsModule from "@/api/notifications";
+
+function LocationEcho() {
+ const loc = useLocation();
+ return {loc.pathname}
;
+}
+
+function renderWithProviders(ui: React.ReactNode, initialEntries = ["/"]) {
+ const qc = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ return render(
+
+
+ {ui}
+
+
+ );
+}
+
+describe("Phase 8 Frontend Polish", () => {
+ beforeEach(() => {
+ vi.restoreAllMocks();
+ useAuthStore.setState({
+ user: {
+ id: 1,
+ name: "System Admin",
+ email: "admin@poona.demo",
+ role: "system_admin",
+ department_id: null,
+ department_name: null,
+ is_active: true,
+ },
+ token: "test-token",
+ demoAsOfDate: null,
+ hydrating: false,
+ });
+ });
+
+ it("TopBar global quick search displays grouped Assets and Complaints and navigates on click", async () => {
+ vi.spyOn(notificationsModule.notificationsApi, "list").mockResolvedValue({
+ items: [],
+ total: 0,
+ unread_count: 0,
+ unread_calibration_count: 0,
+ });
+ const searchSpy = vi
+ .spyOn(searchModule.searchApi, "query")
+ .mockResolvedValue({
+ assets: [
+ {
+ id: 42,
+ asset_code: "PHRC-ICU-0042",
+ name: "Drager Ventilator",
+ serial_no: "SN-9901",
+ department_name: "ICU",
+ status: "in_service",
+ },
+ ],
+ complaints: [
+ {
+ id: 17,
+ complaint_no: "CMP-2026-0017",
+ asset_code: "PHRC-ICU-0042",
+ asset_name: "Drager Ventilator",
+ department_name: "ICU",
+ call_status: "open",
+ priority: "high",
+ },
+ ],
+ });
+
+ renderWithProviders(
+ <>
+
+
+
+ } />
+ Asset Detail View } />
+
Complaint Detail View}
+ />
+
+ >
+ );
+
+ const searchInput = screen.getByLabelText("Search assets and complaints");
+ fireEvent.change(searchInput, { target: { value: "Ventilator" } });
+
+ await waitFor(() => {
+ expect(searchSpy).toHaveBeenCalledWith("Ventilator");
+ expect(screen.getByText("Assets (1)")).toBeInTheDocument();
+ expect(screen.getByText("Complaints (1)")).toBeInTheDocument();
+ expect(screen.getByText("Drager Ventilator")).toBeInTheDocument();
+ expect(screen.getByText("CMP-2026-0017")).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText("Drager Ventilator"));
+
+ await waitFor(() => {
+ expect(screen.getByTestId("current-location")).toHaveTextContent(
+ "/assets/42"
+ );
+ expect(screen.getByText("Asset Detail View")).toBeInTheDocument();
+ });
+ });
+
+ it("AuditLogsPage renders filter controls, audit log rows, and opens JSON changes modal", async () => {
+ vi.spyOn(mastersModule.usersApi, "list").mockResolvedValue({
+ items: [
+ {
+ id: 1,
+ name: "System Admin",
+ email: "admin@poona.demo",
+ role: "system_admin",
+ department_id: null,
+ department_name: null,
+ is_active: true,
+ },
+ ],
+ total: 1,
+ });
+
+ vi.spyOn(auditModule.auditApi, "list").mockResolvedValue({
+ items: [
+ {
+ id: 101,
+ entity_type: "asset",
+ entity_id: 55,
+ action: "update",
+ changes_json: JSON.stringify({
+ status: { old: "in_service", new: "under_repair" },
+ }),
+ by_user_id: 1,
+ by_user_name: "System Admin",
+ at: "2026-11-12T08:30:00Z",
+ },
+ ],
+ total: 1,
+ });
+
+ renderWithProviders(
);
+
+ await waitFor(() => {
+ expect(
+ screen.getByRole("heading", { name: "Audit Log" })
+ ).toBeInTheDocument();
+ expect(screen.getByLabelText("Filter by Entity Type")).toBeInTheDocument();
+ expect(screen.getByLabelText("Filter by User")).toBeInTheDocument();
+ expect(screen.getByLabelText("Filter by Action")).toBeInTheDocument();
+ expect(screen.getByText("#55")).toBeInTheDocument();
+ expect(screen.getByText("asset")).toBeInTheDocument();
+ });
+
+ const jsonBtn = screen.getByLabelText("View JSON changes for audit entry 101");
+ fireEvent.click(jsonBtn);
+
+ await waitFor(() => {
+ expect(
+ screen.getByText(/Audit Entry #101 — asset #55/i)
+ ).toBeInTheDocument();
+ expect(screen.getByText(/"under_repair"/)).toBeInTheDocument();
+ });
+ });
+
+ it("ConfirmDialog renders danger warning and invokes onConfirm", () => {
+ const onConfirm = vi.fn();
+ const onOpenChange = vi.fn();
+
+ render(
+
+ );
+
+ expect(screen.getByText("Delete Contract")).toBeInTheDocument();
+ expect(screen.getByText("This action cannot be undone.")).toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole("button", { name: "Delete" }));
+ expect(onConfirm).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/frontend/src/test/smoke.test.tsx b/frontend/src/test/smoke.test.tsx
index c48e607..46b95ef 100644
--- a/frontend/src/test/smoke.test.tsx
+++ b/frontend/src/test/smoke.test.tsx
@@ -49,11 +49,13 @@ describe("Phase 1 Frontend Smoke Tests", () => {
"Reports",
"Notifications",
"Masters",
+ "Audit Log",
"Settings",
];
for (const label of labels) {
expect(screen.getByText(label)).toBeInTheDocument();
}
+ expect(screen.getByText("Poona Hospital AMS • v1.0")).toBeInTheDocument();
});
it("hides Masters, Settings, and Department Visits for department_user and coordinator", () => {
@@ -74,6 +76,7 @@ describe("Phase 1 Frontend Smoke Tests", () => {
);
expect(screen.queryByText("Masters")).not.toBeInTheDocument();
+ expect(screen.queryByText("Audit Log")).not.toBeInTheDocument();
expect(screen.queryByText("Settings")).not.toBeInTheDocument();
expect(screen.queryByText("Department Visits")).not.toBeInTheDocument();
expect(screen.getByText("Assets")).toBeInTheDocument();
@@ -95,6 +98,7 @@ describe("Phase 1 Frontend Smoke Tests", () => {
);
expect(screen.queryByText("Masters")).not.toBeInTheDocument();
+ expect(screen.queryByText("Audit Log")).not.toBeInTheDocument();
expect(screen.queryByText("Settings")).not.toBeInTheDocument();
expect(screen.queryByText("Department Visits")).not.toBeInTheDocument();
expect(screen.getByText("Contracts & Warranty")).toBeInTheDocument();
diff --git a/frontend/tsconfig.tsbuildinfo b/frontend/tsconfig.tsbuildinfo
index 12acecd..fd8e243 100644
--- a/frontend/tsconfig.tsbuildinfo
+++ b/frontend/tsconfig.tsbuildinfo
@@ -1 +1 @@
-{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/assets.ts","./src/api/attachments.ts","./src/api/auth.ts","./src/api/calibration.ts","./src/api/client.ts","./src/api/complaints.ts","./src/api/dashboard.ts","./src/api/health.ts","./src/api/masters.ts","./src/api/notifications.ts","./src/api/phase5.ts","./src/api/pm.ts","./src/api/reports.ts","./src/api/settings.ts","./src/components/assetformmodal.tsx","./src/components/assetpicker.tsx","./src/components/attachments.tsx","./src/components/calibrationmodals.tsx","./src/components/calibrationremindermodal.tsx","./src/components/insurancedrawer.tsx","./src/components/pmmodals.tsx","./src/components/raisecomplaintmodal.tsx","./src/components/statusbadge.tsx","./src/components/toastprovider.tsx","./src/components/datatable/datatable.test.tsx","./src/components/datatable/datatable.tsx","./src/components/datatable/index.ts","./src/components/layout/appshell.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/topbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/dialog.tsx","./src/hooks/useauth.ts","./src/lib/format.ts","./src/lib/permissions.ts","./src/lib/utils.ts","./src/pages/accessdeniedpage.tsx","./src/pages/assetdetailpage.tsx","./src/pages/assetspage.tsx","./src/pages/calibrationpage.tsx","./src/pages/complaintdetailpage.tsx","./src/pages/complaintspage.tsx","./src/pages/contractspage.tsx","./src/pages/dashboardpage.tsx","./src/pages/datatabledemopage.tsx","./src/pages/demoequipmentpage.tsx","./src/pages/insurancepage.tsx","./src/pages/loginpage.tsx","./src/pages/masterspage.tsx","./src/pages/notificationspage.tsx","./src/pages/pmpage.tsx","./src/pages/reportdetailpage.tsx","./src/pages/reportspage.tsx","./src/pages/settingspage.tsx","./src/pages/visitspage.tsx","./src/pages/stubs.tsx","./src/test/asset-picker.test.tsx","./src/test/attachments.test.tsx","./src/test/calibration-page.test.tsx","./src/test/complaint-detail.test.tsx","./src/test/login.test.tsx","./src/test/permissions.test.ts","./src/test/phase5-modules.test.tsx","./src/test/phase6-modules.test.tsx","./src/test/pm-page.test.tsx","./src/test/reports.test.tsx","./src/test/setup.ts","./src/test/smoke.test.tsx"],"version":"5.6.3"}
\ No newline at end of file
+{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts","./src/api/assets.ts","./src/api/attachments.ts","./src/api/audit.ts","./src/api/auth.ts","./src/api/calibration.ts","./src/api/client.ts","./src/api/complaints.ts","./src/api/dashboard.ts","./src/api/health.ts","./src/api/masters.ts","./src/api/notifications.ts","./src/api/phase5.ts","./src/api/pm.ts","./src/api/reports.ts","./src/api/search.ts","./src/api/settings.ts","./src/components/assetformmodal.tsx","./src/components/assetpicker.tsx","./src/components/attachments.tsx","./src/components/calibrationmodals.tsx","./src/components/calibrationremindermodal.tsx","./src/components/confirmdialog.tsx","./src/components/insurancedrawer.tsx","./src/components/pmmodals.tsx","./src/components/raisecomplaintmodal.tsx","./src/components/statusbadge.tsx","./src/components/toastprovider.tsx","./src/components/datatable/datatable.test.tsx","./src/components/datatable/datatable.tsx","./src/components/datatable/index.ts","./src/components/layout/appshell.tsx","./src/components/layout/sidebar.tsx","./src/components/layout/topbar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/dialog.tsx","./src/hooks/useauth.ts","./src/lib/format.ts","./src/lib/permissions.ts","./src/lib/utils.ts","./src/pages/accessdeniedpage.tsx","./src/pages/assetdetailpage.tsx","./src/pages/assetspage.tsx","./src/pages/auditlogspage.tsx","./src/pages/calibrationpage.tsx","./src/pages/complaintdetailpage.tsx","./src/pages/complaintspage.tsx","./src/pages/contractspage.tsx","./src/pages/dashboardpage.tsx","./src/pages/datatabledemopage.tsx","./src/pages/demoequipmentpage.tsx","./src/pages/insurancepage.tsx","./src/pages/loginpage.tsx","./src/pages/masterspage.tsx","./src/pages/notificationspage.tsx","./src/pages/pmpage.tsx","./src/pages/reportdetailpage.tsx","./src/pages/reportspage.tsx","./src/pages/settingspage.tsx","./src/pages/visitspage.tsx","./src/pages/stubs.tsx","./src/test/asset-picker.test.tsx","./src/test/attachments.test.tsx","./src/test/calibration-page.test.tsx","./src/test/complaint-detail.test.tsx","./src/test/login.test.tsx","./src/test/permissions.test.ts","./src/test/phase5-modules.test.tsx","./src/test/phase6-modules.test.tsx","./src/test/phase8-polish.test.tsx","./src/test/pm-page.test.tsx","./src/test/reports.test.tsx","./src/test/setup.ts","./src/test/smoke.test.tsx"],"version":"5.6.3"}
\ No newline at end of file