Commit 8b7a15fc authored by ReemyHasan's avatar ReemyHasan

Dashboard card stats

parent 37dd1624
import MenuIcon from "@/src/components/assets/custom-ant-icons/menu-icon"; import MenuIcon from "@/src/components/assets/custom-ant-icons/menu-icon";
import React from "react"; import React from "react";
import UsersIcon from "@/src/components/assets/custom-ant-icons/sidebar/users-icon"; import UsersIcon from "@/src/components/assets/custom-ant-icons/sidebar/users-icon";
import { FontColorsOutlined } from "@ant-design/icons"; import { ExclamationOutlined, FontColorsOutlined } from "@ant-design/icons";
interface Props { interface Props {
statSubtitle: string; statSubtitle: string;
statTitle: string; statTitle: string;
...@@ -49,7 +49,13 @@ export default function CardStats({ ...@@ -49,7 +49,13 @@ export default function CardStats({
<FontColorsOutlined <FontColorsOutlined
style={{ fontSize: "19px", color: "#000f24" }} style={{ fontSize: "19px", color: "#000f24" }}
/> />
) : null} ) : statIconName == "traps" ? (
<ExclamationOutlined
style={{ fontSize: "30px", color: "#fff" }}
className={"ExclamationCircleOutlined "}
/>
): null
}
{/* <i className={statIconName}></i> */} {/* <i className={statIconName}></i> */}
</div> </div>
</div> </div>
......
...@@ -8,33 +8,83 @@ import { TranslationFiles } from "@/src/data/core"; ...@@ -8,33 +8,83 @@ import { TranslationFiles } from "@/src/data/core";
import CardUsers from "./card-users"; import CardUsers from "./card-users";
import CardSocialTraffic from './card-socialTraffics' import CardSocialTraffic from './card-socialTraffics'
import CardStats from './card-stats' import CardStats from './card-stats'
import { getAdminsCount, getUsersCount } from "@/src/services/user-service";
import {getTrapsCount, getErrorTrapCount} from "@/src/services/traps-service";
import { useCookies } from "react-cookie";
const DashboardComponent = () => { const DashboardComponent = () => {
const { t } = useTranslation(TranslationFiles.COMMON); const { t } = useTranslation(TranslationFiles.COMMON);
const [cookies] = useCookies([]);
const [userCount, setUserCount] = useState();
const [adminCount, setAdminCount] = useState([]);
const [trapCount, setTrapCount] = useState([]);
const [errorTrapCount, setErrorTrapCount] = useState([]);
useEffect(() => {
async function fetchAdminCount() {
try {
const response1 = await getAdminsCount(cookies["token"], cookies["role"]);
setAdminCount(response1);
} catch (error) {
console.log("error"+error);
}
}
async function fetchUserCount() {
try {
const response2 = await getUsersCount(cookies["token"], cookies["role"]);
setUserCount(response2)
} catch (error) {
console.log("error1"+error);
}
}
async function fetchTrapsCount() {
try {
const response2 = await getTrapsCount(cookies["token"]);
setTrapCount(response2)
} catch (error) {
console.log("error1"+error);
}
}
async function fetchErrorTrapsCount() {
try {
const response2 = await getErrorTrapCount(cookies["token"]);
setErrorTrapCount(response2)
} catch (error) {
console.log("error1"+error);
}
}
fetchAdminCount();
fetchUserCount();
fetchTrapsCount();
fetchErrorTrapsCount();
}, []);
return ( return (
<> <>
<div className="flex flex-wrap"> <div className="flex flex-wrap">
<div className="w-full lg:w-6/12 xl:w-3/12 px-4"> <div className="w-full lg:w-6/12 xl:w-3/12 px-4">
<CardStats <CardStats
statSubtitle="TRAFFIC" statSubtitle="Traps"
statTitle="350,897" statTitle={trapCount !== undefined ? trapCount : "..."}
statArrow="up" statArrow="up"
statPercent="3.48" statPercent={`${(errorTrapCount/(trapCount+errorTrapCount))}`}
statPercentColor="text-emerald-500" statPercentColor="text-red-500"
statDescripiron="Since last month" statDescripiron="error Traps"
statIconName="far fa-chart-bar" statIconName="traps"
statIconColor="bg-red-500" statIconColor="bg-red-600"
/> />
</div> </div>
<div className="w-full lg:w-6/12 xl:w-3/12 px-4"> <div className="w-full lg:w-6/12 xl:w-3/12 px-4">
<CardStats <CardStats
statSubtitle="USERS" statSubtitle="USERS"
statTitle="2,356" statTitle={userCount !== undefined ? userCount : "..."}
statArrow="down" statArrow="down"
statPercent="3.48" statPercent={`${(userCount/(userCount+adminCount))}`}
statPercentColor="text-red-500" statPercentColor={
statDescripiron="Since last month" userCount !== undefined && adminCount !== undefined
? parseFloat(userCount) / (userCount + adminCount) >= 0.5
? "text-emerald-500" // Set the color for percent > 0.5
: "text-red-500" // Set the color for percent <= 0.5
: "text-gray-500" // Default color if counts are not available
}
statDescripiron="users in the system"
statIconName="group" statIconName="group"
statIconColor="primary-blue-600" statIconColor="primary-blue-600"
/> />
...@@ -43,11 +93,17 @@ const DashboardComponent = () => { ...@@ -43,11 +93,17 @@ const DashboardComponent = () => {
<div className="w-full lg:w-6/12 xl:w-3/12 px-4"> <div className="w-full lg:w-6/12 xl:w-3/12 px-4">
<CardStats <CardStats
statSubtitle="ADMINS" statSubtitle="ADMINS"
statTitle="924" statTitle={adminCount !== undefined ? adminCount : "..."}
statArrow="down" statArrow="down"
statPercent="1.10" statPercent={`${(adminCount/(userCount+adminCount))}`}
statPercentColor="text-orange-500" statPercentColor={
statDescripiron="Since last month" userCount !== undefined && adminCount !== undefined
? parseFloat(adminCount) / (userCount + adminCount) >= 0.5
? "text-emerald-500" // Set the color for percent > 0.5
: "text-red-500" // Set the color for percent <= 0.5
: "text-gray-500" // Default color if counts are not available
}
statDescripiron="admins in the system"
statIconName="admin" statIconName="admin"
statIconColor="secondary-color-yellow" statIconColor="secondary-color-yellow"
/> />
......
...@@ -38,3 +38,31 @@ export const getSeverityStatistics = async (token:any) => { ...@@ -38,3 +38,31 @@ export const getSeverityStatistics = async (token:any) => {
console.log(error); console.log(error);
} }
}; };
export const getTrapsCount = async (token:any) => {
try {
const response = await axios.get(TrapURL+ "/getTrapCount",{
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log("response: "+response);
return response.data;
} catch (error) {
console.log(error);
}
};
export const getErrorTrapCount = async (token:any) => {
try {
const response = await axios.get(TrapURL+ "/getErrorTrapCount",{
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log("response: "+response);
return response.data;
} catch (error) {
console.log(error);
}
};
\ No newline at end of file
...@@ -64,6 +64,35 @@ export const getAllUsers = async (token:any, role:any) => { ...@@ -64,6 +64,35 @@ export const getAllUsers = async (token:any, role:any) => {
} }
}; };
export const getAdminsCount = async (token:any, role:any) => {
if(role=="admin"){
try {
const response = await axios.get(UserURL + `getAdminCount`,{
headers: {
Authorization: `Bearer ${token}`,
},
});
return response.data;
} catch (error) {
message.error("Error: " + error);
}
}
};
export const getUsersCount = async (token:any, role:any) => {
if(role=="admin"){
try {
const response = await axios.get(UserURL + `getUsersCount`,{
headers: {
Authorization: `Bearer ${token}`,
},
});
return response.data;
} catch (error) {
message.error("Error: " + error);
}
}
};
export const deleteUser = async (id: any, token:any,role:any) => { export const deleteUser = async (id: any, token:any,role:any) => {
if(role=="admin"){ if(role=="admin"){
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment