Implemented signalR in project wiget in dashboard
This commit is contained in:
parent
200ef5ae0a
commit
9e4c67984c
@ -1,8 +1,33 @@
|
|||||||
import React from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { useDashboardProjectsCardData } from "../../hooks/useDashboard_Data";
|
import { useDashboardProjectsCardData } from "../../hooks/useDashboard_Data";
|
||||||
|
import eventBus from "../../services/eventBus";
|
||||||
|
import GlobalRepository from "../../repositories/GlobalRepository";
|
||||||
|
|
||||||
const Projects = () => {
|
const Projects = () => {
|
||||||
const { projectsCardData } = useDashboardProjectsCardData();
|
const { projectsCardData } = useDashboardProjectsCardData();
|
||||||
|
const [projectData, setProjectsData] = useState(projectsCardData);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setProjectsData(projectsCardData);
|
||||||
|
}, [projectsCardData]);
|
||||||
|
|
||||||
|
const handler = useCallback(
|
||||||
|
async (msg) => {
|
||||||
|
try {
|
||||||
|
const response =
|
||||||
|
await GlobalRepository.getDashboardProjectsCardData();
|
||||||
|
setProjectsData(response.data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[GlobalRepository]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
eventBus.on("project", handler);
|
||||||
|
return () => eventBus.off("project", handler);
|
||||||
|
}, [handler]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
||||||
@ -15,13 +40,13 @@ const Projects = () => {
|
|||||||
<div className="d-flex justify-content-around align-items-start mt-n2">
|
<div className="d-flex justify-content-around align-items-start mt-n2">
|
||||||
<div>
|
<div>
|
||||||
<h4 className="mb-0 fw-bold">
|
<h4 className="mb-0 fw-bold">
|
||||||
{projectsCardData.totalProjects?.toLocaleString()}
|
{projectData.totalProjects?.toLocaleString()}
|
||||||
</h4>
|
</h4>
|
||||||
<small className="text-muted">Total</small>
|
<small className="text-muted">Total</small>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h4 className="mb-0 fw-bold">
|
<h4 className="mb-0 fw-bold">
|
||||||
{projectsCardData.ongoingProjects?.toLocaleString()}
|
{projectData.ongoingProjects?.toLocaleString()}
|
||||||
</h4>
|
</h4>
|
||||||
<small className="text-muted">Ongoing</small>
|
<small className="text-muted">Ongoing</small>
|
||||||
</div>
|
</div>
|
||||||
@ -30,4 +55,4 @@ const Projects = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Projects;
|
export default Projects;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user