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+ Loading +
+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} +
+