From c321d916b5cfd2f41cb7313269b7dc1704197974 Mon Sep 17 00:00:00 2001 From: tonym Date: Fri, 23 Jan 2026 00:05:07 -0600 Subject: [PATCH] fix: Show alerts below stats normally, fix usage cost calculation - Alerts shown below QuickStats without hover reveal - Alerts also listed after usage analytics section - Usage cost now shows cost of material consumed (unit cost * usage) instead of all-time purchase total which was misleading Co-Authored-By: Claude Opus 4.5 --- .../src/pages/home/components/AlertCards.tsx | 46 ++----------------- .../pages/home/components/UsageAnalytics.tsx | 9 ++-- client/src/pages/home/index.tsx | 5 +- 3 files changed, 15 insertions(+), 45 deletions(-) diff --git a/client/src/pages/home/components/AlertCards.tsx b/client/src/pages/home/components/AlertCards.tsx index c75528d..2c7b8cd 100644 --- a/client/src/pages/home/components/AlertCards.tsx +++ b/client/src/pages/home/components/AlertCards.tsx @@ -1,7 +1,6 @@ -import { ExclamationCircleOutlined, PrinterOutlined, DashboardOutlined, WarningOutlined } from "@ant-design/icons"; +import { ExclamationCircleOutlined, PrinterOutlined, DashboardOutlined } from "@ant-design/icons"; import { useList, useTranslate } from "@refinedev/core"; -import { Badge, Card, Col, Row, theme, Typography } from "antd"; -import { useState } from "react"; +import { Badge, Card, Col, Row, theme } from "antd"; import { Link } from "react-router"; import { ISpool } from "../../spools/model"; import { IPrintJob } from "../../spools/model"; @@ -41,13 +40,12 @@ function AlertCard({ icon, label, count, to, color, loading }: AlertCardProps) { } interface AlertCardsProps { - reveal?: boolean; + compact?: boolean; } -export function AlertCards({ reveal }: AlertCardsProps) { +export function AlertCards({ compact }: AlertCardsProps) { const t = useTranslate(); const { token } = useToken(); - const [hovered, setHovered] = useState(false); // Low stock spools const { result: lowStockResult, query: lowStockQuery } = useList({ @@ -111,42 +109,8 @@ export function AlertCards({ reveal }: AlertCardsProps) { if (visibleAlerts.length === 0) return null; - const totalAlertCount = visibleAlerts.reduce((sum, a) => sum + a.count, 0); - - if (reveal) { - return ( -
setHovered(true)} - onMouseLeave={() => setHovered(false)} - style={{ marginTop: 8 }} - > - - - {totalAlertCount} {totalAlertCount === 1 ? "alert" : "alerts"} - -
- - {visibleAlerts.map((alert, i) => ( - - ))} - -
-
- ); - } - return ( - + {visibleAlerts.map((alert, i) => ( ))} diff --git a/client/src/pages/home/components/UsageAnalytics.tsx b/client/src/pages/home/components/UsageAnalytics.tsx index 219f2ae..7c9b3b7 100644 --- a/client/src/pages/home/components/UsageAnalytics.tsx +++ b/client/src/pages/home/components/UsageAnalytics.tsx @@ -122,18 +122,21 @@ export function UsageAnalytics() {
{materialData.map((m) => { const costInfo = costData?.cost_by_material?.find((c) => c.material === m.material); + // Calculate cost of material used based on unit cost (cost per gram) + const costPerGram = costInfo && costInfo.total_weight > 0 ? costInfo.total_cost / costInfo.total_weight : null; + const usageCost = costPerGram != null ? costPerGram * m.weight_used : null; return ( {m.material}
- {t("home.analytics.used")}: {m.weight_used >= 1000 ? `${(m.weight_used / 1000).toFixed(2)} kg` : `${m.weight_used.toFixed(0)} g`} + {m.weight_used >= 1000 ? `${(m.weight_used / 1000).toFixed(2)} kg` : `${m.weight_used.toFixed(0)} g`} - {costInfo && ( + {usageCost != null && ( <>
- {t("home.analytics.spent")}: {currencyFormatter.format(costInfo.total_cost)} + {currencyFormatter.format(usageCost)} )} diff --git a/client/src/pages/home/index.tsx b/client/src/pages/home/index.tsx index 88d56c6..11905de 100644 --- a/client/src/pages/home/index.tsx +++ b/client/src/pages/home/index.tsx @@ -134,7 +134,7 @@ export const Home: React.FC = () => { - + @@ -171,6 +171,9 @@ export const Home: React.FC = () => { {/* Usage analytics & insights */} + + {/* Alerts */} + ); };