phase-8: polish, global search, audit log, packaging, and demo docs

This commit is contained in:
Atharv1705
2026-11-12 15:01:18 +05:30
parent 0b0f550eff
commit 0a2db8454d
34 changed files with 1804 additions and 88 deletions
+69
View File
@@ -0,0 +1,69 @@
import { AlertTriangle } from "lucide-react";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
export interface ConfirmDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
message: string;
confirmLabel?: string;
cancelLabel?: string;
variant?: "danger" | "default";
loading?: boolean;
onConfirm: () => void | Promise<void>;
}
export function ConfirmDialog({
open,
onOpenChange,
title,
message,
confirmLabel = "Confirm",
cancelLabel = "Cancel",
variant = "danger",
loading = false,
onConfirm,
}: ConfirmDialogProps) {
return (
<Modal
open={open}
onOpenChange={(next) => {
if (!loading) onOpenChange(next);
}}
title={title}
description={message}
className="max-w-md"
>
<div className="space-y-5">
{variant === "danger" && (
<div className="flex items-start gap-3 rounded-md border border-red-200 bg-red-50 px-3.5 py-2.5 text-xs text-red-800">
<AlertTriangle className="h-4 w-4 shrink-0 text-red-600 mt-0.5" />
<span>This action cannot be undone.</span>
</div>
)}
<div className="flex items-center justify-end gap-2 pt-1">
<Button
type="button"
variant="outline"
size="sm"
disabled={loading}
onClick={() => onOpenChange(false)}
>
{cancelLabel}
</Button>
<Button
type="button"
variant={variant === "danger" ? "danger" : "default"}
size="sm"
loading={loading}
onClick={() => void onConfirm()}
>
{confirmLabel}
</Button>
</div>
</div>
</Modal>
);
}
+8 -2
View File
@@ -1,14 +1,20 @@
import { useState } from "react";
import { Outlet } from "react-router-dom";
import { Sidebar } from "./Sidebar";
import { TopBar } from "./TopBar";
import { CalibrationReminderModal } from "@/components/CalibrationReminderModal";
export function AppShell() {
const [mobileNavOpen, setMobileNavOpen] = useState(false);
return (
<div className="flex min-h-screen bg-gray-50">
<Sidebar />
<Sidebar
mobileOpen={mobileNavOpen}
onClose={() => setMobileNavOpen(false)}
/>
<div className="flex-1 flex flex-col min-w-0">
<TopBar />
<TopBar onMenuClick={() => setMobileNavOpen(true)} />
<main className="flex-1 p-6 overflow-auto">
<Outlet />
</main>
+49 -6
View File
@@ -12,8 +12,10 @@ import {
BarChart3,
Bell,
Database,
History,
Settings,
ChevronRight,
X,
type LucideIcon,
} from "lucide-react";
import { cn } from "@/lib/utils";
@@ -71,10 +73,16 @@ const NAV_ITEMS: NavItem[] = [
},
{ to: "/notifications", label: "Notifications", icon: Bell },
{ to: "/masters", label: "Masters", icon: Database, capability: "manage_admin" },
{ to: "/audit-logs", label: "Audit Log", icon: History, capability: "manage_admin" },
{ to: "/settings", label: "Settings", icon: Settings, capability: "manage_admin" },
];
export function Sidebar() {
interface SidebarProps {
mobileOpen?: boolean;
onClose?: () => void;
}
export function Sidebar({ mobileOpen, onClose }: SidebarProps = {}) {
const user = useAuthStore((s) => s.user);
const role = user?.role;
@@ -84,10 +92,23 @@ export function Sidebar() {
return true;
});
return (
<aside className="w-56 lg:w-64 shrink-0 min-h-screen bg-[#1e3a8a] text-white flex flex-col">
const asideContent = (
<aside
aria-label="Primary Navigation"
className="w-56 lg:w-64 shrink-0 min-h-screen bg-[#1e3a8a] text-white flex flex-col"
>
{/* Logo */}
<div className="px-4 py-4 border-b border-blue-700 space-y-2">
<div className="px-4 py-4 border-b border-blue-700 space-y-2 relative">
{onClose && (
<button
type="button"
onClick={onClose}
aria-label="Close navigation menu"
className="md:hidden absolute right-2 top-2 p-1 rounded text-blue-200 hover:text-white hover:bg-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white"
>
<X className="h-4 w-4" />
</button>
)}
<div className="bg-white rounded-lg p-2">
<img
src="/logo.jpg"
@@ -107,9 +128,10 @@ export function Sidebar() {
key={to}
to={to}
end={to === "/"}
onClick={() => 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 */}
<div className="px-4 py-3 border-t border-blue-700 text-xs text-blue-300">
Phase 1 — Foundation
Poona Hospital AMS • v1.0
</div>
</aside>
);
// When controlled by AppShell, hide desktop rail on small screens and render slide-over drawer when open
if (mobileOpen === undefined) {
return asideContent;
}
return (
<>
<div className="hidden md:flex shrink-0">{asideContent}</div>
{mobileOpen && (
<div className="fixed inset-0 z-40 flex md:hidden">
<div
className="fixed inset-0 bg-black/40"
onClick={onClose}
aria-hidden="true"
/>
<div className="relative z-50 flex">{asideContent}</div>
</div>
)}
</>
);
}
+216 -11
View File
@@ -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<HTMLDivElement>(null);
const searchContainerRef = useRef<HTMLDivElement>(null);
const userMenuRef = useRef<HTMLDivElement>(null);
const seenIdsRef = useRef<Set<number> | 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 (
<header className="min-h-14 bg-white border-b border-gray-200 flex items-center flex-wrap px-4 py-2 gap-3 sticky top-0 z-10">
{/* Mobile nav toggle */}
{onMenuClick && (
<button
type="button"
onClick={onMenuClick}
aria-label="Open navigation menu"
className="md:hidden p-1.5 rounded-md text-gray-600 hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
>
<Menu className="h-5 w-5" />
</button>
)}
{/* Page title */}
{title && (
<h1 className="font-semibold text-gray-800 text-sm truncate mr-auto">
@@ -185,14 +250,151 @@ export function TopBar({ title }: TopBarProps) {
</h1>
)}
{/* Global search placeholder */}
<div className={cn("relative", title ? "" : "flex-1 max-w-xs sm:max-w-sm")}>
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
{/* Live Global Quick Search */}
<div
ref={searchContainerRef}
className={cn("relative", title ? "w-64 sm:w-80" : "flex-1 max-w-xs sm:max-w-md")}
>
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<input
type="text"
placeholder="Search assets, complaints... (Phase 8)"
className="w-full pl-9 pr-4 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"
aria-label="Search assets and complaints"
value={searchInput}
onChange={(e) => {
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 && (
<button
type="button"
aria-label="Clear search"
onClick={() => {
setSearchInput("");
setDebouncedQuery("");
setSearchOpen(false);
}}
className="absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-gray-400 hover:text-gray-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
>
<X className="h-3.5 w-3.5" />
</button>
)}
{searchOpen && searchInput.trim().length >= 2 && (
<div
role="listbox"
aria-label="Global search results"
className="absolute left-0 right-0 mt-1.5 bg-white border border-gray-200 rounded-lg shadow-xl z-30 max-h-96 overflow-y-auto divide-y divide-gray-100"
>
{searchQuery.isFetching && !searchQuery.data ? (
<div className="px-4 py-6 text-center text-xs text-gray-500">
Searching assets &amp; complaints...
</div>
) : searchQuery.isError ? (
<div className="px-4 py-5 text-center text-xs text-red-600">
Unable to load search results.
</div>
) : (
(() => {
const assets = searchQuery.data?.assets ?? [];
const complaints = searchQuery.data?.complaints ?? [];
if (assets.length === 0 && complaints.length === 0) {
return (
<div className="px-4 py-6 text-center text-xs text-gray-500">
No matching assets or complaints found.
</div>
);
}
return (
<>
{assets.length > 0 && (
<div className="py-1.5">
<div className="px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-gray-500 flex items-center gap-1.5">
<Package className="h-3.5 w-3.5 text-[#1e3a8a]" />
Assets ({assets.length})
</div>
{assets.map((asset) => (
<button
key={`asset-${asset.id}`}
type="button"
role="option"
onClick={() => {
setSearchOpen(false);
navigate(`/assets/${asset.id}`);
}}
className="w-full text-left px-3 py-2 hover:bg-blue-50/70 focus-visible:outline-none focus-visible:bg-blue-50 flex items-center justify-between gap-2 transition-colors"
>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="font-mono text-xs font-semibold text-[#1e3a8a]">
{asset.asset_code}
</span>
<span className="text-xs font-medium text-gray-900 truncate">
{asset.name}
</span>
</div>
<div className="text-[11px] text-gray-500 truncate mt-0.5">
{asset.department_name ?? "No Dept"}
{asset.serial_no ? ` • SN: ${asset.serial_no}` : ""}
</div>
</div>
<AssetStatusBadge status={asset.status} />
</button>
))}
</div>
)}
{complaints.length > 0 && (
<div className="py-1.5">
<div className="px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-gray-500 flex items-center gap-1.5">
<AlertCircle className="h-3.5 w-3.5 text-red-600" />
Complaints ({complaints.length})
</div>
{complaints.map((c) => (
<button
key={`complaint-${c.id}`}
type="button"
role="option"
onClick={() => {
setSearchOpen(false);
navigate(`/complaints/${c.id}`);
}}
className="w-full text-left px-3 py-2 hover:bg-blue-50/70 focus-visible:outline-none focus-visible:bg-blue-50 flex items-center justify-between gap-2 transition-colors"
>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="font-mono text-xs font-semibold text-gray-900">
{c.complaint_no}
</span>
<span className="text-xs text-gray-700 truncate">
{c.asset_code
? `${c.asset_code}${c.asset_name ? ` — ${c.asset_name}` : ""}`
: c.asset_name ?? "Equipment"}
</span>
</div>
<div className="text-[11px] text-gray-500 truncate mt-0.5">
{c.department_name ?? "—"} • Priority: {c.priority}
</div>
</div>
<CallStatusBadge status={c.call_status} />
</button>
))}
</div>
)}
</>
);
})()
)}
</div>
)}
</div>
{/* Active Demo Date Pill */}
@@ -254,8 +456,9 @@ export function TopBar({ title }: TopBarProps) {
<button
type="button"
onClick={() => setBellOpen((o) => !o)}
className="relative p-2 rounded-md hover:bg-gray-100 text-gray-600"
className="relative p-2 rounded-md hover:bg-gray-100 text-gray-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
aria-label="Notifications"
aria-expanded={bellOpen}
>
<Bell className="h-5 w-5" />
{unreadCount > 0 && (
@@ -348,11 +551,13 @@ export function TopBar({ title }: TopBarProps) {
</div>
{/* User menu */}
<div className="relative">
<div ref={userMenuRef} className="relative">
<button
type="button"
onClick={() => setMenuOpen((o) => !o)}
className="flex items-center gap-2 px-2.5 py-1.5 rounded-md hover:bg-gray-100 text-sm text-gray-700"
aria-label="User menu"
aria-expanded={menuOpen}
className="flex items-center gap-2 px-2.5 py-1.5 rounded-md hover:bg-gray-100 text-sm text-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
>
<div className="h-7 w-7 rounded-full bg-[#1e3a8a] flex items-center justify-center text-white text-xs font-bold shrink-0">
<User className="h-4 w-4" />