phase-0: scaffold backend and frontend shell

This commit is contained in:
Atharv1705
2026-11-12 12:12:15 +05:30
commit cb2f48620c
67 changed files with 9125 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
+48
View File
@@ -0,0 +1,48 @@
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { AppShell } from "@/components/layout/AppShell";
import { DataTableDemoPage } from "@/pages/DataTableDemoPage";
import {
DashboardPage,
AssetsPage,
ComplaintsPage,
PMPage,
CalibrationPage,
ContractsPage,
InsurancePage,
DemoEquipmentPage,
VisitsPage,
ReportsPage,
NotificationsPage,
SettingsPage,
} from "@/pages/stubs";
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: 1, staleTime: 30_000 } },
});
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<Routes>
<Route element={<AppShell />}>
<Route path="/" element={<DashboardPage />} />
<Route path="/assets" element={<AssetsPage />} />
<Route path="/complaints" element={<ComplaintsPage />} />
<Route path="/pm" element={<PMPage />} />
<Route path="/calibration" element={<CalibrationPage />} />
<Route path="/contracts" element={<ContractsPage />} />
<Route path="/insurance" element={<InsurancePage />} />
<Route path="/demo-equipment" element={<DemoEquipmentPage />} />
<Route path="/visits" element={<VisitsPage />} />
<Route path="/reports" element={<ReportsPage />} />
<Route path="/notifications" element={<NotificationsPage />} />
<Route path="/settings" element={<SettingsPage />} />
<Route path="/demo" element={<DataTableDemoPage />} />
</Route>
</Routes>
</BrowserRouter>
</QueryClientProvider>
);
}
+39
View File
@@ -0,0 +1,39 @@
const BASE_URL = "/api";
export class ApiError extends Error {
constructor(
public status: number,
public detail: string,
public code?: string
) {
super(detail);
}
}
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
const token = sessionStorage.getItem("access_token");
const headers: Record<string, string> = {
"Content-Type": "application/json",
...(options.headers as Record<string, string>),
};
if (token) headers["Authorization"] = `Bearer ${token}`;
const res = await fetch(`${BASE_URL}${path}`, { ...options, headers });
if (!res.ok) {
const body = await res.json().catch(() => ({ detail: res.statusText }));
throw new ApiError(res.status, body.detail ?? res.statusText, body.code);
}
if (res.status === 204) return undefined as T;
return res.json();
}
export const api = {
get: <T>(path: string) => request<T>(path),
post: <T>(path: string, data?: unknown) =>
request<T>(path, { method: "POST", body: data ? JSON.stringify(data) : undefined }),
patch: <T>(path: string, data: unknown) =>
request<T>(path, { method: "PATCH", body: JSON.stringify(data) }),
put: <T>(path: string, data: unknown) =>
request<T>(path, { method: "PUT", body: JSON.stringify(data) }),
delete: <T>(path: string) => request<T>(path, { method: "DELETE" }),
};
+4
View File
@@ -0,0 +1,4 @@
import { api } from "./client";
export const fetchHealth = () =>
api.get<{ status: string; service: string; version: string }>("/health");
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

@@ -0,0 +1,33 @@
import { describe, it, expect } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { ColumnDef } from "@tanstack/react-table";
import { DataTable } from "./DataTable";
interface RowItem {
code: string;
name: string;
}
const columns: ColumnDef<RowItem, unknown>[] = [
{ accessorKey: "code", header: "Code", enableColumnFilter: true },
{ accessorKey: "name", header: "Name", enableColumnFilter: true },
];
const data: RowItem[] = [
{ code: "A-001", name: "Ventilator" },
{ code: "A-002", name: "Monitor" },
];
describe("DataTable", () => {
it("renders rows and filters globally", () => {
render(<DataTable data={data} columns={columns} globalFilterPlaceholder="Search..." />);
expect(screen.getByText("Ventilator")).toBeInTheDocument();
expect(screen.getByText("Monitor")).toBeInTheDocument();
const searchInput = screen.getByPlaceholderText("Search...");
fireEvent.change(searchInput, { target: { value: "Ventilator" } });
expect(screen.getByText("Ventilator")).toBeInTheDocument();
expect(screen.queryByText("Monitor")).not.toBeInTheDocument();
});
});
@@ -0,0 +1,266 @@
import {
useReactTable,
getCoreRowModel,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
flexRender,
ColumnDef,
SortingState,
ColumnFiltersState,
VisibilityState,
PaginationState,
FilterFn,
} from "@tanstack/react-table";
import { useState, useMemo } from "react";
import { ChevronUp, ChevronDown, ChevronsUpDown, Download, Eye, Search } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
interface DataTableProps<TData> {
data: TData[];
columns: ColumnDef<TData, unknown>[];
loading?: boolean;
emptyMessage?: string;
emptyAction?: React.ReactNode;
globalFilterPlaceholder?: string;
onRowClick?: (row: TData) => void;
exportFilename?: string;
}
function exportToCsv<TData>(data: TData[], filename: string) {
if (!data.length) return;
const headers = Object.keys(data[0] as object);
const rows = data.map((row) =>
headers.map((h) => JSON.stringify((row as Record<string, unknown>)[h] ?? "")).join(",")
);
const csv = [headers.join(","), ...rows].join("\n");
const blob = new Blob([csv], { type: "text/csv" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${filename}.csv`;
a.click();
URL.revokeObjectURL(url);
}
export function DataTable<TData>({
data,
columns,
loading = false,
emptyMessage = "No records found.",
emptyAction,
globalFilterPlaceholder = "Search...",
onRowClick,
exportFilename = "export",
}: DataTableProps<TData>) {
const [sorting, setSorting] = useState<SortingState>([]);
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
const [globalFilter, setGlobalFilter] = useState("");
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 20 });
const [showColVis, setShowColVis] = useState(false);
const globalFilterFn: FilterFn<TData> = (row, _columnId, filterValue: string) => {
const search = String(filterValue ?? "").toLowerCase();
return Object.values(row.original as Record<string, unknown>).some((v) =>
String(v ?? "").toLowerCase().includes(search)
);
};
const table = useReactTable({
data,
columns,
state: { sorting, columnFilters, columnVisibility, globalFilter, pagination },
onSortingChange: setSorting,
onColumnFiltersChange: setColumnFilters,
onColumnVisibilityChange: setColumnVisibility,
onGlobalFilterChange: setGlobalFilter,
onPaginationChange: setPagination,
globalFilterFn,
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getSortedRowModel: getSortedRowModel(),
getPaginationRowModel: getPaginationRowModel(),
});
const visibleRows = table.getRowModel().rows;
const filteredRows = table.getFilteredRowModel().rows;
const allFilteredData = useMemo(
() => filteredRows.map((r) => r.original),
[filteredRows]
);
return (
<div className="space-y-3">
{/* Toolbar */}
<div className="flex items-center gap-2 flex-wrap">
<div className="relative flex-1 min-w-48">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
<input
value={globalFilter}
onChange={(e) => setGlobalFilter(e.target.value)}
placeholder={globalFilterPlaceholder}
className="w-full pl-9 pr-4 py-1.5 text-sm border border-gray-200 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="relative">
<Button variant="outline" size="sm" onClick={() => setShowColVis(!showColVis)}>
<Eye className="h-4 w-4 mr-1" /> Columns
</Button>
{showColVis && (
<div className="absolute right-0 mt-1 w-48 bg-white border border-gray-200 rounded-md shadow-lg z-20 p-2">
{table.getAllLeafColumns().map((col) => (
<label key={col.id} className="flex items-center gap-2 px-2 py-1 hover:bg-gray-50 rounded cursor-pointer text-sm">
<input
type="checkbox"
checked={col.getIsVisible()}
onChange={col.getToggleVisibilityHandler()}
className="rounded"
/>
{String(col.columnDef.header ?? col.id)}
</label>
))}
</div>
)}
</div>
<Button variant="outline" size="sm" onClick={() => exportToCsv(allFilteredData, exportFilename)}>
<Download className="h-4 w-4 mr-1" /> CSV (current view)
</Button>
</div>
{/* Table */}
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead className="bg-gray-50 border-b border-gray-200">
{table.getHeaderGroups().map((hg) => (
<tr key={hg.id}>
{hg.headers.map((header) => (
<th key={header.id} className="text-left font-medium text-gray-600 px-4 py-3">
{header.isPlaceholder ? null : (
<div className="space-y-1">
{/* Sortable header */}
<button
type="button"
className={cn(
"flex items-center gap-1 hover:text-gray-900 font-medium",
header.column.getCanSort() ? "cursor-pointer select-none" : "cursor-default"
)}
onClick={header.column.getToggleSortingHandler()}
>
{flexRender(header.column.columnDef.header, header.getContext())}
{header.column.getCanSort() && (
header.column.getIsSorted() === "asc" ? (
<ChevronUp className="h-3 w-3" />
) : header.column.getIsSorted() === "desc" ? (
<ChevronDown className="h-3 w-3" />
) : (
<ChevronsUpDown className="h-3 w-3 opacity-30" />
)
)}
</button>
{/* Per-column filter */}
{header.column.getCanFilter() && (
<input
value={(header.column.getFilterValue() as string) ?? ""}
onChange={(e) => header.column.setFilterValue(e.target.value)}
placeholder="Filter..."
className="w-full px-2 py-0.5 text-xs border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-blue-400"
onClick={(e) => e.stopPropagation()}
/>
)}
</div>
)}
</th>
))}
</tr>
))}
</thead>
<tbody className="divide-y divide-gray-100">
{loading ? (
[...Array(5)].map((_, i) => (
<tr key={i}>
{columns.map((_, j) => (
<td key={j} className="px-4 py-3">
<div className="h-4 bg-gray-100 rounded animate-pulse" />
</td>
))}
</tr>
))
) : visibleRows.length === 0 ? (
<tr>
<td colSpan={columns.length} className="px-4 py-12 text-center">
<div className="text-gray-400 space-y-2">
<p>{emptyMessage}</p>
{emptyAction}
</div>
</td>
</tr>
) : (
visibleRows.map((row) => (
<tr
key={row.id}
className={cn(
"hover:bg-blue-50/50 transition-colors",
onRowClick && "cursor-pointer"
)}
onClick={() => onRowClick?.(row.original)}
>
{row.getVisibleCells().map((cell) => (
<td key={cell.id} className="px-4 py-3 text-gray-700">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
))
)}
</tbody>
</table>
</div>
{/* Pagination */}
{!loading && visibleRows.length > 0 && (
<div className="flex items-center justify-between px-4 py-3 border-t border-gray-200 bg-gray-50 text-sm text-gray-600">
<span>
{filteredRows.length} record{filteredRows.length !== 1 ? "s" : ""}
{globalFilter || columnFilters.length ? " (filtered)" : ""}
</span>
<div className="flex items-center gap-2">
<select
value={pagination.pageSize}
onChange={(e) => table.setPageSize(Number(e.target.value))}
className="border border-gray-200 rounded px-2 py-1 text-xs"
>
{[10, 20, 50, 100].map((s) => (
<option key={s} value={s}>
{s} / page
</option>
))}
</select>
<button
type="button"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
className="px-2 py-1 rounded border border-gray-200 disabled:opacity-40 hover:bg-white"
>
←
</button>
<span className="text-xs">
Page {pagination.pageIndex + 1} / {table.getPageCount()}
</span>
<button
type="button"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
className="px-2 py-1 rounded border border-gray-200 disabled:opacity-40 hover:bg-white"
>
→
</button>
</div>
</div>
)}
</div>
</div>
);
}
@@ -0,0 +1 @@
export { DataTable } from "./DataTable";
@@ -0,0 +1,17 @@
import { Outlet } from "react-router-dom";
import { Sidebar } from "./Sidebar";
import { TopBar } from "./TopBar";
export function AppShell() {
return (
<div className="flex min-h-screen bg-gray-50">
<Sidebar />
<div className="flex-1 flex flex-col min-w-0">
<TopBar />
<main className="flex-1 p-6 overflow-auto">
<Outlet />
</main>
</div>
</div>
);
}
@@ -0,0 +1,80 @@
import { NavLink } from "react-router-dom";
import {
LayoutDashboard,
Package,
AlertCircle,
Wrench,
FlaskConical,
FileText,
Shield,
Truck,
Building2,
BarChart3,
Bell,
Settings,
ChevronRight,
} from "lucide-react";
import { cn } from "@/lib/utils";
const NAV_ITEMS = [
{ to: "/", label: "Dashboard", icon: LayoutDashboard, phase: 6 },
{ to: "/assets", label: "Assets", icon: Package, phase: 2 },
{ to: "/complaints", label: "Complaints", icon: AlertCircle, phase: 3 },
{ to: "/pm", label: "Preventive Maintenance", icon: Wrench, phase: 4 },
{ to: "/calibration", label: "Calibration", icon: FlaskConical, phase: 4 },
{ to: "/contracts", label: "Contracts & Warranty", icon: FileText, phase: 5 },
{ to: "/insurance", label: "Insurance", icon: Shield, phase: 5 },
{ to: "/demo-equipment", label: "Demo Equipment", icon: Truck, phase: 5 },
{ to: "/visits", label: "Department Visits", icon: Building2, phase: 5 },
{ to: "/reports", label: "Reports", icon: BarChart3, phase: 7 },
{ to: "/notifications", label: "Notifications", icon: Bell, phase: 6 },
{ to: "/settings", label: "Settings", icon: Settings, phase: 1, adminOnly: true },
];
export function Sidebar() {
return (
<aside 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="bg-white rounded-lg p-2">
<img
src="/logo.jpg"
alt="Poona Hospital and Research Centre"
className="w-full h-16 object-contain"
/>
</div>
<div className="text-xs text-blue-200 text-center">
Asset Management &amp; Maintenance
</div>
</div>
{/* Navigation */}
<nav className="flex-1 px-2 py-4 space-y-0.5 overflow-y-auto">
{NAV_ITEMS.map(({ to, label, icon: Icon }) => (
<NavLink
key={to}
to={to}
end={to === "/"}
className={({ isActive }) =>
cn(
"flex items-center gap-3 px-3 py-2.5 rounded-md text-sm transition-colors group",
isActive
? "bg-blue-700 text-white"
: "text-blue-100 hover:bg-blue-700/50 hover:text-white"
)
}
>
<Icon className="h-4 w-4 shrink-0" />
<span className="flex-1 truncate">{label}</span>
<ChevronRight className="h-3 w-3 opacity-0 group-hover:opacity-50" />
</NavLink>
))}
</nav>
{/* Footer */}
<div className="px-4 py-3 border-t border-blue-700 text-xs text-blue-300">
Phase 0 — Scaffold
</div>
</aside>
);
}
+40
View File
@@ -0,0 +1,40 @@
import { Search, Bell, ChevronDown, User } from "lucide-react";
import { cn } from "@/lib/utils";
interface TopBarProps {
title?: string;
}
export function TopBar({ title }: TopBarProps) {
return (
<header className="h-14 bg-white border-b border-gray-200 flex items-center px-4 gap-4 sticky top-0 z-10">
{/* Page title */}
{title && <h1 className="font-semibold text-gray-800 text-sm truncate mr-auto">{title}</h1>}
{/* Global search placeholder */}
<div className={cn("relative ml-auto", title ? "" : "flex-1 max-w-md")}>
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
<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"
/>
</div>
{/* Notification bell placeholder */}
<button className="relative p-2 rounded-md hover:bg-gray-100 text-gray-500">
<Bell className="h-5 w-5" />
<span className="absolute top-1 right-1 h-2 w-2 rounded-full bg-red-500" />
</button>
{/* User menu placeholder */}
<button className="flex items-center gap-2 px-3 py-1.5 rounded-md hover:bg-gray-100 text-sm text-gray-700">
<div className="h-7 w-7 rounded-full bg-[#1e3a8a] flex items-center justify-center text-white text-xs font-bold">
<User className="h-4 w-4" />
</div>
<span className="hidden sm:block">Admin</span>
<ChevronDown className="h-4 w-4 text-gray-400" />
</button>
</header>
);
}
+30
View File
@@ -0,0 +1,30 @@
import { cn } from "@/lib/utils";
interface BadgeProps {
variant?: "default" | "success" | "warning" | "danger" | "info" | "outline";
className?: string;
children: React.ReactNode;
}
const variantClasses = {
default: "bg-gray-100 text-gray-800",
success: "bg-green-100 text-green-800",
warning: "bg-yellow-100 text-yellow-800",
danger: "bg-red-100 text-red-800",
info: "bg-blue-100 text-blue-800",
outline: "border border-gray-300 text-gray-700 bg-white",
};
export function Badge({ variant = "default", className, children }: BadgeProps) {
return (
<span
className={cn(
"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",
variantClasses[variant],
className
)}
>
{children}
</span>
);
}
+49
View File
@@ -0,0 +1,49 @@
import { cn } from "@/lib/utils";
import { ButtonHTMLAttributes, forwardRef } from "react";
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: "default" | "outline" | "ghost" | "danger" | "success";
size?: "sm" | "md" | "lg";
loading?: boolean;
}
const variantClasses = {
default: "bg-[#1e3a8a] text-white hover:bg-[#1e3480] focus:ring-blue-500",
outline: "border border-gray-300 bg-white text-gray-700 hover:bg-gray-50 focus:ring-blue-500",
ghost: "text-gray-600 hover:bg-gray-100 focus:ring-gray-400",
danger: "bg-red-600 text-white hover:bg-red-700 focus:ring-red-500",
success: "bg-green-600 text-white hover:bg-green-700 focus:ring-green-500",
};
const sizeClasses = {
sm: "px-3 py-1.5 text-sm",
md: "px-4 py-2 text-sm",
lg: "px-6 py-3 text-base",
};
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ variant = "default", size = "md", loading, className, children, disabled, ...props }, ref) => (
<button
ref={ref}
disabled={disabled || loading}
className={cn(
"inline-flex items-center justify-center rounded-md font-medium transition-colors",
"focus:outline-none focus:ring-2 focus:ring-offset-1",
"disabled:opacity-50 disabled:cursor-not-allowed",
variantClasses[variant],
sizeClasses[size],
className
)}
{...props}
>
{loading && (
<svg className="animate-spin -ml-1 mr-2 h-4 w-4" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
</svg>
)}
{children}
</button>
)
);
Button.displayName = "Button";
+21
View File
@@ -0,0 +1,21 @@
import { create } from "zustand";
interface AuthState {
user: { id: number; email: string; name: string; role: string } | null;
token: string | null;
setAuth: (user: AuthState["user"], token: string) => void;
logout: () => void;
}
export const useAuthStore = create<AuthState>((set) => ({
user: null,
token: sessionStorage.getItem("access_token"),
setAuth: (user, token) => {
sessionStorage.setItem("access_token", token);
set({ user, token });
},
logout: () => {
sessionStorage.removeItem("access_token");
set({ user: null, token: null });
},
}));
+12
View File
@@ -0,0 +1,12 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--brand: #1e3a8a;
}
body {
@apply bg-gray-50 text-gray-900 antialiased;
}
}
+55
View File
@@ -0,0 +1,55 @@
import { format, formatDistanceToNow } from "date-fns";
import { toZonedTime } from "date-fns-tz";
// Kolkata offset: +05:30
const KOLKATA_TZ = "Asia/Kolkata";
export function formatDateTime(isoString: string | null | undefined): string {
if (!isoString) return "—";
try {
const d = toZonedTime(new Date(isoString), KOLKATA_TZ);
return format(d, "dd-MMM-yyyy HH:mm");
} catch {
return "—";
}
}
export function formatDate(isoString: string | null | undefined): string {
if (!isoString) return "—";
try {
const d = toZonedTime(new Date(isoString), KOLKATA_TZ);
return format(d, "dd-MMM-yyyy");
} catch {
return "—";
}
}
export function formatDuration(minutes: number | null | undefined): string {
if (minutes == null) return "—";
const d = Math.floor(minutes / 1440);
const h = Math.floor((minutes % 1440) / 60);
const m = minutes % 60;
const parts: string[] = [];
if (d) parts.push(`${d}d`);
if (h) parts.push(`${h}h`);
if (m || !parts.length) parts.push(`${m}m`);
return parts.join(" ");
}
export function formatINR(amount: number | null | undefined): string {
if (amount == null) return "—";
return new Intl.NumberFormat("en-IN", {
style: "currency",
currency: "INR",
maximumFractionDigits: 0,
}).format(amount);
}
export function formatRelative(isoString: string | null | undefined): string {
if (!isoString) return "—";
try {
return formatDistanceToNow(new Date(isoString), { addSuffix: true });
} catch {
return "—";
}
}
+16
View File
@@ -0,0 +1,16 @@
export type Role = "system_admin" | "biomedical" | "department_user" | "management" | "coordinator";
export const ROLE_LABELS: Record<Role, string> = {
system_admin: "System Administrator",
biomedical: "Biomedical / Maintenance",
department_user: "Department User",
management: "Management",
coordinator: "Coordinator",
};
// Full permission matrix will be added in Phase 1
export function can(role: Role | undefined, _capability: string): boolean {
if (!role) return false;
if (role === "system_admin") return true;
return false; // placeholder
}
+6
View File
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
+10
View File
@@ -0,0 +1,10 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
+66
View File
@@ -0,0 +1,66 @@
import { DataTable } from "@/components/DataTable";
import { ColumnDef } from "@tanstack/react-table";
import { Badge } from "@/components/ui/badge";
interface MockAsset {
code: string;
name: string;
department: string;
status: string;
category: string;
}
const MOCK_DATA: MockAsset[] = [
{ code: "PHRC-ICU-0001", name: "Ventilator", department: "ICU", status: "In Service", category: "Life Support" },
{ code: "PHRC-ICU-0002", name: "Patient Monitor", department: "ICU", status: "Under Repair", category: "Monitoring" },
{ code: "PHRC-OT-0001", name: "Anaesthesia Machine", department: "Operation Theatre", status: "In Service", category: "Life Support" },
{ code: "PHRC-RAD-0001", name: "CT Scanner", department: "Radiology", status: "In Service", category: "Imaging" },
{ code: "PHRC-RAD-0002", name: "X-Ray Unit", department: "Radiology", status: "Out of Service", category: "Imaging" },
{ code: "PHRC-EM-0001", name: "Defibrillator", department: "Emergency", status: "In Service", category: "Life Support" },
{ code: "PHRC-PATH-0001", name: "Centrifuge", department: "Pathology", status: "In Service", category: "Laboratory" },
{ code: "PHRC-DIAL-0001", name: "Dialysis Machine", department: "Dialysis", status: "In Service", category: "Dialysis" },
];
const STATUS_VARIANTS: Record<string, "success" | "danger" | "warning" | "outline"> = {
"In Service": "success",
"Under Repair": "danger",
"Out of Service": "warning",
Condemned: "outline",
};
const columns: ColumnDef<MockAsset, unknown>[] = [
{ accessorKey: "code", header: "Asset Code", enableColumnFilter: true },
{ accessorKey: "name", header: "Equipment Name", enableColumnFilter: true },
{ accessorKey: "category", header: "Category", enableColumnFilter: true },
{ accessorKey: "department", header: "Department", enableColumnFilter: true },
{
accessorKey: "status",
header: "Status",
enableColumnFilter: true,
cell: ({ getValue }) => {
const v = getValue() as string;
return <Badge variant={STATUS_VARIANTS[v] ?? "default"}>{v}</Badge>;
},
},
];
export function DataTableDemoPage() {
return (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-bold text-gray-900">Phase 0 — DataTable Demo</h1>
<p className="text-gray-500 mt-1 text-sm">
Mock asset data demonstrating column filters, sort, pagination, column visibility, and CSV export.
Every list in the app will use this component.
</p>
</div>
<DataTable
data={MOCK_DATA}
columns={columns}
globalFilterPlaceholder="Search assets..."
exportFilename="assets-demo"
emptyMessage="No assets found."
/>
</div>
);
}
+75
View File
@@ -0,0 +1,75 @@
// Stub pages — replaced phase by phase
import { Link } from "react-router-dom";
interface StubProps {
title: string;
phase: number;
description?: string;
children?: React.ReactNode;
}
function StubPage({ title, phase, description, children }: StubProps) {
return (
<div className="max-w-lg mx-auto mt-16 text-center">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-blue-50 mb-4">
<span className="text-2xl">🏗️</span>
</div>
<h2 className="text-xl font-semibold text-gray-800 mb-2">{title}</h2>
{description && <p className="text-gray-500 text-sm mb-4">{description}</p>}
<div className="inline-flex items-center gap-2 bg-amber-50 border border-amber-200 text-amber-700 px-4 py-2 rounded-full text-sm font-medium">
Coming in Phase {phase}
</div>
{children}
</div>
);
}
export const DashboardPage = () => (
<StubPage title="Dashboard" phase={6} description="KPI cards, charts, and needs-attention panel.">
<div className="mt-6">
<Link
to="/demo"
className="inline-flex items-center gap-1 text-sm font-medium text-[#1e3a8a] hover:underline"
>
Open Phase 0 DataTable Demo →
</Link>
</div>
</StubPage>
);
export const AssetsPage = () => (
<StubPage title="Asset Register" phase={2} description="60+ assets with column filters and detail tabs." />
);
export const ComplaintsPage = () => (
<StubPage
title="Breakdown & Complaint Register"
phase={3}
description="Full complaint lifecycle with response time and downtime tracking."
/>
);
export const PMPage = () => (
<StubPage title="Preventive Maintenance" phase={4} description="PM schedules and calendar view." />
);
export const CalibrationPage = () => (
<StubPage title="Calibration" phase={4} description="Calibration plans and records with due-date alerts." />
);
export const ContractsPage = () => (
<StubPage title="Contracts & Warranty" phase={5} description="AMC/CMC contracts and warranty tracking." />
);
export const InsurancePage = () => (
<StubPage title="Insurance" phase={5} description="Insurance policies with expiry alerts." />
);
export const DemoEquipmentPage = () => (
<StubPage title="Demo Equipment Register" phase={5} description="Demo equipment tracking with overdue returns." />
);
export const VisitsPage = () => (
<StubPage title="Department Visits" phase={5} description="Daily department visit reports." />
);
export const ReportsPage = () => (
<StubPage title="Reports & Exports" phase={7} description="8 reports with Excel export." />
);
export const NotificationsPage = () => (
<StubPage title="Notifications" phase={6} description="In-app alerts and notification centre." />
);
export const SettingsPage = () => (
<StubPage title="Settings" phase={1} description="Configurable lead days, downtime rules, and system settings." />
);
+1
View File
@@ -0,0 +1 @@
import "@testing-library/jest-dom";
+57
View File
@@ -0,0 +1,57 @@
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { Sidebar } from "@/components/layout/Sidebar";
import { DashboardPage } from "@/pages/stubs";
import { DataTableDemoPage } from "@/pages/DataTableDemoPage";
describe("Phase 0 Frontend Smoke Tests", () => {
it("renders Sidebar with Poona Hospital logo, subtitle, and all 12 navigation links", () => {
render(
<MemoryRouter>
<Sidebar />
</MemoryRouter>
);
const logo = screen.getByAltText("Poona Hospital and Research Centre") as HTMLImageElement;
expect(logo).toBeInTheDocument();
expect(logo.getAttribute("src")).toBe("/logo.jpg");
expect(screen.getByText("Asset Management & Maintenance")).toBeInTheDocument();
const labels = [
"Dashboard",
"Assets",
"Complaints",
"Preventive Maintenance",
"Calibration",
"Contracts & Warranty",
"Insurance",
"Demo Equipment",
"Department Visits",
"Reports",
"Notifications",
"Settings",
];
for (const label of labels) {
expect(screen.getByText(label)).toBeInTheDocument();
}
});
it("renders DashboardPage with clickable link to /demo", () => {
render(
<MemoryRouter>
<DashboardPage />
</MemoryRouter>
);
const link = screen.getByRole("link", { name: /Open Phase 0 DataTable Demo/i });
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute("href", "/demo");
});
it("renders DataTableDemoPage with mock rows", () => {
render(<DataTableDemoPage />);
expect(screen.getByText("Phase 0 — DataTable Demo")).toBeInTheDocument();
expect(screen.getByText("PHRC-ICU-0001")).toBeInTheDocument();
expect(screen.getByText("CT Scanner")).toBeInTheDocument();
});
});
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />