From 609490895b8832bc4b23927d1b00deb0c6b150cf Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 17 Jan 2025 14:25:13 -0500 Subject: [PATCH] Fix build errors --- inventory/src/routes/Forecasting.tsx | 105 ++++++++++++++++----------- inventory/tsconfig.tsbuildinfo | 2 +- 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/inventory/src/routes/Forecasting.tsx b/inventory/src/routes/Forecasting.tsx index 78b4905..969fca5 100644 --- a/inventory/src/routes/Forecasting.tsx +++ b/inventory/src/routes/Forecasting.tsx @@ -5,6 +5,8 @@ import { AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; +import { useQuery } from "@tanstack/react-query"; +import config from "@/config"; interface Product { product_id: string; @@ -24,46 +26,67 @@ interface CategoryMetrics { total_sold: number; avgTotalSold: number; avg_price: number; - products: Product[]; + products: string; // This is a JSON string that will be parsed } -{data && ( - - - {data.map((category: CategoryMetrics, index: number) => ( - - -
-
{category.category_name}
-
{category.num_products}
-
{category.avg_daily_sales.toFixed(2)}
-
{category.total_sold}
-
${category.avg_price.toFixed(2)}
-
{category.avgTotalSold.toFixed(2)}
-
-
- -
-
-
Product
-
SKU
-
Stock
-
Total Sold
-
Avg Price
-
- {JSON.parse(category.products).map((product: Product) => ( -
-
{product.name}
-
{product.sku}
-
{product.stock_quantity}
-
{product.total_sold}
-
${product.avg_price.toFixed(2)}
-
- ))} -
-
-
- ))} -
-
-)} \ No newline at end of file +export default function Forecasting() { + const { data, isLoading } = useQuery({ + queryKey: ["forecasting"], + queryFn: async () => { + const response = await fetch(`${config.apiUrl}/analytics/forecasting`, { + credentials: 'include' + }); + if (!response.ok) throw new Error("Failed to fetch forecasting data"); + return response.json(); + }, + }); + + if (isLoading) { + return
Loading forecasting data...
; + } + + return ( +
+ {data && ( + + + {data.map((category: CategoryMetrics) => ( + + +
+
{category.category_name}
+
{category.num_products}
+
{category.avg_daily_sales.toFixed(2)}
+
{category.total_sold}
+
${category.avg_price.toFixed(2)}
+
{category.avgTotalSold.toFixed(2)}
+
+
+ +
+
+
Product
+
SKU
+
Stock
+
Total Sold
+
Avg Price
+
+ {JSON.parse(category.products).map((product: Product) => ( +
+
{product.name}
+
{product.sku}
+
{product.stock_quantity}
+
{product.total_sold}
+
${product.avg_price.toFixed(2)}
+
+ ))} +
+
+
+ ))} +
+
+ )} +
+ ); +} \ No newline at end of file diff --git a/inventory/tsconfig.tsbuildinfo b/inventory/tsconfig.tsbuildinfo index ee8a216..63b006d 100644 --- a/inventory/tsconfig.tsbuildinfo +++ b/inventory/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/app.tsx","./src/config.ts","./src/main.tsx","./src/vite-env.d.ts","./src/components/analytics/categoryperformance.tsx","./src/components/analytics/priceanalysis.tsx","./src/components/analytics/profitanalysis.tsx","./src/components/analytics/stockanalysis.tsx","./src/components/analytics/vendorperformance.tsx","./src/components/auth/requireauth.tsx","./src/components/dashboard/inventoryhealthsummary.tsx","./src/components/dashboard/inventorystats.tsx","./src/components/dashboard/keymetricscharts.tsx","./src/components/dashboard/lowstockalerts.tsx","./src/components/dashboard/overview.tsx","./src/components/dashboard/recentsales.tsx","./src/components/dashboard/salesbycategory.tsx","./src/components/dashboard/trendingproducts.tsx","./src/components/dashboard/vendorperformance.tsx","./src/components/forecasting/columns.tsx","./src/components/layout/appsidebar.tsx","./src/components/layout/mainlayout.tsx","./src/components/products/productdetail.tsx","./src/components/products/productfilters.tsx","./src/components/products/producttable.tsx","./src/components/products/producttableskeleton.tsx","./src/components/products/productviews.tsx","./src/components/settings/calculationsettings.tsx","./src/components/settings/configuration.tsx","./src/components/settings/datamanagement.tsx","./src/components/settings/performancemetrics.tsx","./src/components/settings/stockmanagement.tsx","./src/components/ui/accordion.tsx","./src/components/ui/alert-dialog.tsx","./src/components/ui/alert.tsx","./src/components/ui/avatar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/calendar.tsx","./src/components/ui/card.tsx","./src/components/ui/command.tsx","./src/components/ui/date-range-picker.tsx","./src/components/ui/dialog.tsx","./src/components/ui/drawer.tsx","./src/components/ui/dropdown-menu.tsx","./src/components/ui/input.tsx","./src/components/ui/label.tsx","./src/components/ui/pagination.tsx","./src/components/ui/popover.tsx","./src/components/ui/progress.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/select.tsx","./src/components/ui/separator.tsx","./src/components/ui/sheet.tsx","./src/components/ui/sidebar.tsx","./src/components/ui/skeleton.tsx","./src/components/ui/sonner.tsx","./src/components/ui/switch.tsx","./src/components/ui/table.tsx","./src/components/ui/tabs.tsx","./src/components/ui/toggle-group.tsx","./src/components/ui/toggle.tsx","./src/components/ui/tooltip.tsx","./src/hooks/use-mobile.tsx","./src/lib/utils.ts","./src/pages/analytics.tsx","./src/pages/categories.tsx","./src/pages/dashboard.tsx","./src/pages/forecasting.tsx","./src/pages/login.tsx","./src/pages/orders.tsx","./src/pages/products.tsx","./src/pages/purchaseorders.tsx","./src/pages/settings.tsx","./src/pages/vendors.tsx","./src/routes/forecasting.tsx","./src/types/products.ts"],"errors":true,"version":"5.6.3"} \ No newline at end of file +{"root":["./src/app.tsx","./src/config.ts","./src/main.tsx","./src/vite-env.d.ts","./src/components/analytics/categoryperformance.tsx","./src/components/analytics/priceanalysis.tsx","./src/components/analytics/profitanalysis.tsx","./src/components/analytics/stockanalysis.tsx","./src/components/analytics/vendorperformance.tsx","./src/components/auth/requireauth.tsx","./src/components/dashboard/inventoryhealthsummary.tsx","./src/components/dashboard/inventorystats.tsx","./src/components/dashboard/keymetricscharts.tsx","./src/components/dashboard/lowstockalerts.tsx","./src/components/dashboard/overview.tsx","./src/components/dashboard/recentsales.tsx","./src/components/dashboard/salesbycategory.tsx","./src/components/dashboard/trendingproducts.tsx","./src/components/dashboard/vendorperformance.tsx","./src/components/forecasting/columns.tsx","./src/components/layout/appsidebar.tsx","./src/components/layout/mainlayout.tsx","./src/components/products/productdetail.tsx","./src/components/products/productfilters.tsx","./src/components/products/producttable.tsx","./src/components/products/producttableskeleton.tsx","./src/components/products/productviews.tsx","./src/components/settings/calculationsettings.tsx","./src/components/settings/configuration.tsx","./src/components/settings/datamanagement.tsx","./src/components/settings/performancemetrics.tsx","./src/components/settings/stockmanagement.tsx","./src/components/ui/accordion.tsx","./src/components/ui/alert-dialog.tsx","./src/components/ui/alert.tsx","./src/components/ui/avatar.tsx","./src/components/ui/badge.tsx","./src/components/ui/button.tsx","./src/components/ui/calendar.tsx","./src/components/ui/card.tsx","./src/components/ui/command.tsx","./src/components/ui/date-range-picker.tsx","./src/components/ui/dialog.tsx","./src/components/ui/drawer.tsx","./src/components/ui/dropdown-menu.tsx","./src/components/ui/input.tsx","./src/components/ui/label.tsx","./src/components/ui/pagination.tsx","./src/components/ui/popover.tsx","./src/components/ui/progress.tsx","./src/components/ui/scroll-area.tsx","./src/components/ui/select.tsx","./src/components/ui/separator.tsx","./src/components/ui/sheet.tsx","./src/components/ui/sidebar.tsx","./src/components/ui/skeleton.tsx","./src/components/ui/sonner.tsx","./src/components/ui/switch.tsx","./src/components/ui/table.tsx","./src/components/ui/tabs.tsx","./src/components/ui/toggle-group.tsx","./src/components/ui/toggle.tsx","./src/components/ui/tooltip.tsx","./src/hooks/use-mobile.tsx","./src/lib/utils.ts","./src/pages/analytics.tsx","./src/pages/categories.tsx","./src/pages/dashboard.tsx","./src/pages/forecasting.tsx","./src/pages/login.tsx","./src/pages/orders.tsx","./src/pages/products.tsx","./src/pages/purchaseorders.tsx","./src/pages/settings.tsx","./src/pages/vendors.tsx","./src/routes/forecasting.tsx","./src/types/products.ts"],"version":"5.6.3"} \ No newline at end of file