added signalr events

This commit is contained in:
Pramod Mahajan 2025-07-09 10:42:04 +05:30
parent cb7df469c2
commit 87edce4c3d
4 changed files with 48 additions and 38 deletions

View File

@ -11,7 +11,7 @@ import {
getCachedData, getCachedData,
} from "../../../slices/apiDataManager"; } from "../../../slices/apiDataManager";
const InfraTable = ({ buildings, projectId, signalRHandler }) => { const InfraTable = ({ buildings, projectId}) => {
const [projectBuilding, setProjectBuilding] = useState([]); const [projectBuilding, setProjectBuilding] = useState([]);
const [expandedBuildings, setExpandedBuildings] = useState([]); const [expandedBuildings, setExpandedBuildings] = useState([]);
const [showFloorModal, setShowFloorModal] = useState(false); const [showFloorModal, setShowFloorModal] = useState(false);
@ -113,34 +113,34 @@ const InfraTable = ({ buildings, projectId, signalRHandler }) => {
} }
}, [buildings]); }, [buildings]);
const handler = useCallback( // const handler = useCallback(
(msg) => { // (msg) => {
if (msg.projectIds.some((item) => item == projectId)) { // if (msg.projectIds.some((item) => item == projectId)) {
try { // try {
ProjectRepository.getProjectByprojectId(projectId) // ProjectRepository.getProjectByprojectId(projectId)
.then((response) => { // .then((response) => {
cacheData("projectInfo", { // cacheData("projectInfo", {
projectId: projectId, // projectId: projectId,
data: response.data, // data: response.data,
}); // });
setProjectBuilding(response?.data?.buildings); // setProjectBuilding(response?.data?.buildings);
signalRHandler?.(response?.data); // signalRHandler?.(response?.data);
showToast(msg.message, "info"); // showToast(msg.message, "info");
}) // })
.catch((error) => { // .catch((error) => {
console.error(error); // console.error(error);
}); // });
} catch (e) { // } catch (e) {
console.error(e); // console.error(e);
} // }
} // }
}, // },
[buildings] // [buildings]
); // );
useEffect(() => { // useEffect(() => {
eventBus.on("infra", handler); // eventBus.on("infra", handler);
return () => eventBus.off("infra", handler); // return () => eventBus.off("infra", handler);
}, [handler]); // }, [handler]);
return ( return (
<div> <div>

View File

@ -42,12 +42,12 @@ const ProjectInfra = ( {data, onDataChange, eachSiteEngineer} ) =>
setProject(projectInfra); setProject(projectInfra);
}, [data, projects_Details]); }, [data, projects_Details]);
useEffect(() => { // useEffect(() => {
if (reloadedData) { // if (reloadedData) {
refetch(); // refetch();
dispatch(refreshData(false)); // dispatch(refreshData(false));
} // }
}, [reloadedData]); // }, [reloadedData]);
const signalRHandler = (response) => { const signalRHandler = (response) => {
setProject(response); setProject(response);
@ -130,7 +130,7 @@ const ProjectInfra = ( {data, onDataChange, eachSiteEngineer} ) =>
buildings={projectInfra} buildings={projectInfra}
projectId={projectId} projectId={projectId}
// handleFloor={submitData} // handleFloor={submitData}
signalRHandler ={signalRHandler} // signalRHandler ={signalRHandler}
/> />
)} )}
{!isLoading && projectInfra?.length == 0 && <div className="mt-5"><p>No Infra Avaiable</p></div>} {!isLoading && projectInfra?.length == 0 && <div className="mt-5"><p>No Infra Avaiable</p></div>}

View File

@ -194,6 +194,7 @@ export const useUpdateEmployee = () =>
queryClient.invalidateQueries( {queryKey:[ 'allEmployee', isAllEmployee ] }); queryClient.invalidateQueries( {queryKey:[ 'allEmployee', isAllEmployee ] });
// queryClient.invalidateQueries(['employeeProfile', id]); // queryClient.invalidateQueries(['employeeProfile', id]);
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} ); queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
queryClient.removeQueries( {queryKey: [ "empListByProjectAllocated" ]} );
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject']} ); // queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject']} );
showToast( `Employee ${ id ? 'updated' : 'created' } successfully`, 'success' ); showToast( `Employee ${ id ? 'updated' : 'created' } successfully`, 'success' );

View File

@ -79,8 +79,17 @@ export function startSignalR(loggedUser) {
} }
// if created or updated infra // if created or updated infra
if (data.keyword == "Infra") { if (data.keyword == "Infra") {
clearCacheKey("projectInfo"); queryClient.removeQueries({queryKey:["ProjectInfra"]})
eventBus.emit("infra", data); // eventBus.emit("infra", data);
}
if (data.keyword == "Task_Report") {
queryClient.removeQueries({queryKey:["Infra"]})
// eventBus.emit("infra", data);
}
if ( data.keyword == "WorkItem" )
{
queryClient.removeQueries({queryKey:["WorkItems"]})
} }
// if created or updated Employee // if created or updated Employee