import type { ReactNode } from "react";
import { useNavigate } from "react-router-dom";
import AddIcon from "@mui/icons-material/Add";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
import FolderOpenOutlinedIcon from "@mui/icons-material/FolderOpenOutlined";
import ScheduleOutlinedIcon from "@mui/icons-material/ScheduleOutlined";
import {
Alert,
Box,
CircularProgress,
Paper,
Stack,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Typography,
} from "@mui/material";
import { useDashboardStats } from "@/domain/dashboard/use-cases/use-dashboard-stats";
const INVOICE_STATUSES = ["Draft", "Challenged", "Pending Approval", "Approved", "Paid"] as const;
const PRIORITY_LEVELS = [5, 4, 3, 2, 1] as const;
interface KpiCardProps {
title: string;
description?: string;
value?: string | number;
icon: ReactNode;
color: "success" | "primary" | "info" | "warning";
onClick: () => void;
loading?: boolean;
}
function KpiCard({ title, description, value, icon, color, onClick, loading }: KpiCardProps) {
const colorMap = {
success: "success.main",
primary: "primary.main",
info: "info.main",
warning: "warning.main",
} as const;
return (
{icon}
{title}
{value !== undefined && (
{loading ? "..." : typeof value === "number" ? value.toLocaleString() : value}
)}
{description && (
{description}
)}
);
}
export default function DashboardPage() {
const navigate = useNavigate();
const { data: stats, isLoading, isFetching, error } = useDashboardStats();
const formatStat = (value: number | undefined) => (isLoading ? undefined : (value ?? 0));
return (
Dashboard
{isFetching && !isLoading && }
{error && (
{error instanceof Error ? error.message : "Failed to load dashboard stats"}
)}
}
color="success"
onClick={() => navigate("/workorders/new")}
/>
}
color="primary"
loading={isLoading}
onClick={() => navigate("/workorders")}
/>
}
color="info"
loading={isLoading}
onClick={() => navigate("/workorders")}
/>
}
color="warning"
loading={isLoading}
onClick={() => navigate("/workorders")}
/>
Priority Analysis
Age of open Work Orders by Priority
Priority
Total
0-14 Days
15-29 Days
30-59 Days
60+ Days
{PRIORITY_LEVELS.map((priority) => (
{priority}
—
—
—
—
—
))}
Invoice Analysis
Status
Count
Amount
{INVOICE_STATUSES.map((status) => (
{status}
0
$0.00
))}
);
}