import React, { useState } from "react"; import TotalProductsIcon from "../../Components/Icons/TotalProductsIcon/TotalProductsIcon"; import LowStockIcon from "../../Components/Icons/LowStockIcon/LowStockIcon"; import StatsIcon from "../../Components/Icons/StatsIcon/StatsIcon"; import LogsIcon from "../../Components/Icons/LogsIcon/LogsIcon"; import "../../index.css"; import styles from "../../styles"; import HomeIcon from "../../Components/Icons/HomeIcon/HomeIcon"; import ColoredCube from "../../Components/ColoredCube/ColoredCube"; import RecentlyAddedIcon from "../../Components/Icons/RecentlyAddedIcon/RecentlyAddedIcon"; import LoginChecker from "../../Components/LoginChecker/LoginChecker"; import { useQuery } from "react-query"; import { GetLogs, GetLowestStockedProduct, GetProducts, } from "../../Components/Api/Api"; import { OldSessionState, ProductLog, SessionTransactions, } from "../../Interfaces/Interfaces"; import { useSelector } from "react-redux"; import LowestStockWidget from "../../Components/DashboardPage/LowestStockWidget/LowestStockWidget"; import RecentlyAddedWidget from "../../Components/DashboardPage/RecentlyAddedWidget/RecentlyAddedWidget"; import TotalProductsWidget from "../../Components/DashboardPage/TotalProductsWidget/TotalProductsWidget"; import SessionStatsWidget from "../../Components/DashboardPage/SessionStatsWidget/SessionStatsWidget"; export default function Dashboard() { const logs = useQuery("logs", GetLogs, { retry: 0 }); const products = useQuery("products", GetProducts, { retry: 0 }); const lowest_stock_product = useQuery( "lowest_stock_product", GetLowestStockedProduct, { retry: 0, } ); const old_session_checked = useSelector( (state: OldSessionState) => state.old_session_checked.value ); if ( logs.isLoading || products.isLoading || lowest_stock_product.isLoading || !old_session_checked ) { return (

Dashboard

Loading dashboard...

); } if (logs.error || products.error || lowest_stock_product.isError) {

Dashboard

Error loading dashboard

; } return (

Dashboard

Recent

Transactions

{logs.data.slice(0, 5).map((log: ProductLog, index: number) => { return (

{log.name}

Quantity: {log.quantity}

Date: {log.history_date}

Transaction ID: {log.history_id}

); })}
); }