diff --git a/src/Components/API/API.tsx b/src/Components/API/API.tsx index 8ed3262..9b49d7c 100644 --- a/src/Components/API/API.tsx +++ b/src/Components/API/API.tsx @@ -2,9 +2,11 @@ import axios from "axios"; import { ActivationType, + EquipmentListType, LoginType, RegisterType, ResetPasswordConfirmType, + EquipmentInstanceListType, } from "../Types/Types"; const instance = axios.create({ @@ -106,6 +108,7 @@ export async function JWTRefreshAPI() { return true; }) .catch(() => { + console.log("Error refreshing token"); return false; }); } @@ -119,7 +122,6 @@ export async function UserAPI() { }) .catch(() => { console.log("Error retrieving user data"); - return false; }); } @@ -128,11 +130,9 @@ export function ActivationAPI(activation: ActivationType) { .post("api/v1/accounts/users/activation/", activation) .then(() => { console.log("Activation Success"); - return true; }) .catch(() => { console.log("Activation failed"); - return false; }); } export function ResetPasswordAPI(email: string) { @@ -140,11 +140,9 @@ export function ResetPasswordAPI(email: string) { .post("api/v1/accounts/users/reset_password/", { email: email }) .then(() => { console.log("Activation Success"); - return true; }) .catch(() => { console.log("Activation failed"); - return false; }); } @@ -153,10 +151,34 @@ export function ResetPasswordConfirmAPI(info: ResetPasswordConfirmType) { .post("api/v1/accounts/users/reset_password_confirm/", info) .then(() => { console.log("Reset Success"); - return true; }) .catch(() => { console.log("Reset failed"); - return false; + }); +} + +// Equipment APIs + +export async function EquipmentsAPI() { + const config = await GetConfig(); + return instance + .get("api/v1/equipments/equipments/", config) + .then((response) => { + return response.data as EquipmentListType; + }) + .catch(() => { + console.log("Error retrieving equipments"); + }); +} + +export async function EquipmentInstancesAPI() { + const config = await GetConfig(); + return instance + .get("api/v1/equipments/equipment_instances/", config) + .then((response) => { + return response.data as EquipmentInstanceListType; + }) + .catch(() => { + console.log("Error retrieving equipments"); }); } diff --git a/src/Components/Header/Header.tsx b/src/Components/Header/Header.tsx index d0189e4..a8e961f 100644 --- a/src/Components/Header/Header.tsx +++ b/src/Components/Header/Header.tsx @@ -38,7 +38,7 @@ export default function Header(props: props) { }} /> -

+

{props.label}

diff --git a/src/Components/Types/Types.tsx b/src/Components/Types/Types.tsx index efcb59a..1991c83 100644 --- a/src/Components/Types/Types.tsx +++ b/src/Components/Types/Types.tsx @@ -26,3 +26,26 @@ export type AddEquipmentType = { name: string; remarks: string; }; + +export type EquipmentType = { + id: number; + name: string; + description: string; + last_updated: string; + last_updated_by: string; + date_added: string; +}; + +export type EquipmentListType = Array; + +export type EquipmentInstanceType = { + id: number; + equipment: string; + status: string; + remarks: string; + last_updated: string; + last_updated_by: string; + date_added: string; +}; + +export type EquipmentInstanceListType = Array; diff --git a/src/Pages/DashboardPage/DashboardPage.tsx b/src/Pages/DashboardPage/DashboardPage.tsx index 72f9e61..609942e 100644 --- a/src/Pages/DashboardPage/DashboardPage.tsx +++ b/src/Pages/DashboardPage/DashboardPage.tsx @@ -1,11 +1,191 @@ import Header from "../../Components/Header/Header"; import styles from "../../styles"; +import { useQueries } from "@tanstack/react-query"; +import { EquipmentsAPI, EquipmentInstancesAPI } from "../../Components/API/API"; +import { CircularProgress } from "@mui/material"; export default function Dashboard() { + const queries = useQueries({ + queries: [ + { + queryKey: ["equipments"], + queryFn: EquipmentsAPI, + }, + { + queryKey: ["equipment_instances"], + queryFn: EquipmentInstancesAPI, + }, + ], + }); + const isLoading = queries.some((result) => result.isLoading); + if (isLoading) { + return ( +
+
+
+ +

+ Loading +

+
+
+ ); + } return (
-

Dashboard Page

+
+
+
+

+ Item Types in System +

+ +

+ {queries[0].data ? queries[0].data.length : 0} +

+
+
+

+ Unique Items in System +

+ +

+ {queries[1].data ? queries[1].data.length : 0} +

+
+
+
+
+

+ Working Items +

+ +

+ {queries[1].data + ? queries[1].data.filter( + (equipment) => equipment.status == "Working" + ).length + : 0} +

+
+
+

+ Broken Items +

+ +

+ {queries[1].data + ? queries[1].data.filter( + (equipment) => equipment.status == "Broken" + ).length + : 0} +

+
+
+
); } diff --git a/src/Pages/LandingPage/LandingPage.tsx b/src/Pages/LandingPage/LandingPage.tsx index 8c1d046..fd5ef05 100644 --- a/src/Pages/LandingPage/LandingPage.tsx +++ b/src/Pages/LandingPage/LandingPage.tsx @@ -10,6 +10,7 @@ import { useSelector } from "react-redux"; import { useNavigate } from "react-router-dom"; import { RootState } from "../../Components/Plugins/Redux/Store/Store"; import ResetPasswordModal from "../../Components/ResetPasswordModal/ResetPasswordModal"; + export default function LandingPage() { const [loginmodalOpen, SetloginmodalOpen] = useState(false); const [registermodalOpen, SetRegisterModalOpen] = useState(false);