Compare commits

..

No commits in common. "10ee3796d3cd3fdc3b4809048cd02d06ddba403a" and "28c226904e066c8538bf24cb52190451fafd0162" have entirely different histories.

9 changed files with 68 additions and 85 deletions

View File

@ -28,7 +28,6 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
employee,
error,
loading: empLoading,
refetch
} = useEmployeeProfile(employeeId);
useEffect(() => {
@ -130,12 +129,7 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
.min(1, { message: "Phone Number is required" })
.regex(mobileNumberRegex, { message: "Invalid phone number " }),
jobRoleId: z.string().min(1, { message: "Role is required" }),
} );
useEffect( () =>
{
refetch()
},[])
});
const {
register,

View File

@ -14,7 +14,6 @@ import {
} from "../../../utils/constants";
import { useParams } from "react-router-dom";
import ProgressBar from "../../common/ProgressBar";
import {formatNumber} from "../../../utils/dateUtils";
const WorkArea = ({ workArea, floor, forBuilding }) => {
const selectedProject = useSelector((store) => store.localVariables.projectId);
@ -104,14 +103,15 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
{workArea.areaName}
</span>
</div>
{ProjectTaskList?.length > 0 && (
<div className="col-2">
<ProgressBar
completedWork={formatNumber(workArea?.completedWork)}
plannedWork={formatNumber(workArea?.plannedWork)}
completedWork={workAreaStatus.completed}
plannedWork={workAreaStatus.planned}
className="m-0 text-info"
/>
</div>
)}
</div>
</button>
</p>

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import moment from "moment";
import { formatNumber, getDateDifferenceInDays } from "../../utils/dateUtils";
import { getDateDifferenceInDays } from "../../utils/dateUtils";
import { useNavigate } from "react-router-dom";
import { useProjectDetails, useUpdateProject } from "../../hooks/useProjects";
import ManageProjectInfo from "./ManageProjectInfo";
@ -223,7 +223,7 @@ const ProjectCard = ({ projectData, recall }) => {
</div>
<div className="d-flex justify-content-between align-items-center mb-2">
<small className="text-body">
Task: {formatNumber(projectInfo.completedWork)} / {formatNumber(projectInfo.plannedWork)}
Task: {projectInfo.completedWork} / {projectInfo.plannedWork}
</small>
<small className="text-body">
{Math.floor(

View File

@ -403,7 +403,7 @@ export const useCreateJobRole = (onSuccessCallback) => {
onSuccess: (data) => {
showToast("JobRole added successfully.", "success");
queryClient.invalidateQueries({queryKey:["masterData", "Job Role"]});
queryClient.invalidateQueries(["masterData", "Job Role"]);
if (onSuccessCallback) onSuccessCallback(data);
},
@ -427,7 +427,7 @@ export const useCreateApplicationRole = (onSuccessCallback) =>
},
onSuccess: ( data ) =>
{
queryClient.invalidateQueries( {queryKey:[ "masterData", "Application Role" ]} )
queryClient.invalidateQueries( [ "masterData", "Application Role" ] )
showToast( "Application Role added successfully", "success" );
if(onSuccessCallback) onSuccessCallback(data)
},
@ -476,7 +476,7 @@ export const useCreateActivity = (onSuccessCallback) =>
},
onSuccess: ( data ) =>
{
queryClient.invalidateQueries( {queryKey:[ "masterData", "Activity" ]} )
queryClient.invalidateQueries( [ "masterData", "Activity" ] )
showToast( "Activity added successfully", "success" );
if(onSuccessCallback) onSuccessCallback(data)
},
@ -526,7 +526,7 @@ export const useCreateWorkCategory = (onSuccessCallback) =>
},
onSuccess: ( data ) =>
{
queryClient.invalidateQueries({queryKey: [ "masterData", "Work Category" ]} )
queryClient.invalidateQueries( [ "masterData", "Work Category" ] )
showToast( "Work Category added successfully", "success" );
if(onSuccessCallback) onSuccessCallback(data)
},
@ -577,7 +577,7 @@ export const useCreateContactCategory = (onSuccessCallback) =>
},
onSuccess: ( data ) =>
{
queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Category" ]} )
queryClient.invalidateQueries( [ "masterData", "Contact Category" ] )
showToast( "Contact Category added successfully", "success" );
if(onSuccessCallback) onSuccessCallback(data)
},
@ -628,7 +628,7 @@ export const useCreateContactTag = (onSuccessCallback) =>
},
onSuccess: ( data ) =>
{
queryClient.invalidateQueries( {queryKey:[ "masterData", "Contact Tag" ]} )
queryClient.invalidateQueries( [ "masterData", "Contact Tag" ] )
showToast( "Contact Tag added successfully", "success" );
if(onSuccessCallback) onSuccessCallback(data)
},

View File

@ -152,11 +152,11 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
export const useEmployeeProfile = ( employeeId ) =>
{
const isEnabled = !!employeeId;
const {
data = null,
isLoading: loading,
error,
refetch
} = useQuery({
queryKey: ['employeeProfile', employeeId],
queryFn: async () => {
@ -171,7 +171,6 @@ export const useEmployeeProfile = ( employeeId ) =>
employee: data,
loading,
error,
refetch
};
};
@ -191,11 +190,11 @@ export const useUpdateEmployee = () =>
const id = variables.id || variables.employeeId;
const isAllEmployee = variables.IsAllEmployee;
// Cache invalidation
queryClient.invalidateQueries( {queryKey:[ 'allEmployee', isAllEmployee ] });
queryClient.invalidateQueries( [ 'allEmployee', isAllEmployee ] );
// queryClient.invalidateQueries(['employeeProfile', id]);
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
// queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject']} );
// queryClient.invalidateQueries( [ 'employeeListByProject' ,selectedProject] );
showToast( `Employee ${ id ? 'updated' : 'created' } successfully`, 'success' );
},
onError: (error) => {
@ -221,7 +220,7 @@ export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing })
// queryClient.invalidateQueries( ['allEmployee',false]);
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
queryClient.invalidateQueries( [ 'employeeListByProject' ,selectedProject] );
setIsDeleteModalOpen(false);
},

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { cacheData,getCachedData } from "../slices/apiDataManager";
import { MasterRespository } from "../repositories/MastersRepository";
import { useQuery } from "@tanstack/react-query";
export const useMasterRole =()=>{
@ -43,55 +43,40 @@ export const useMasterRole =()=>{
return {masterRole,loading}
}
// export const useFeatures =()=> {
// const [masterFeatures, setMasterFeatures] = useState([]);
// const [loading, setLoading] = useState(true);
// const [error, setError] = useState("");
export const useFeatures =()=> {
const [masterFeatures, setMasterFeatures] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState("");
// const fetchData = async () => {
const fetchData = async () => {
// try {
// const features_cache = getCachedData("masterFeatures");
// if (!features_cache) {
// MasterRespository.getFeatures()
// .then((response) => {
// setMasterFeatures(response.data);
try {
const features_cache = getCachedData("masterFeatures");
if (!features_cache) {
MasterRespository.getFeatures()
.then((response) => {
setMasterFeatures(response.data);
// cacheData("features", response.data);
// setLoading(false)
// })
// .catch((error) => {
// setError("Failed to fetch data.");
// });
// }else{
// if (!masterFeatures.length) setMasterFeatures(features_cache);
// }
// } catch (err) {
// setError("Failed to fetch data.");
// } finally {
// setLoading(false);
// }
// };
cacheData("features", response.data);
setLoading(false)
})
.catch((error) => {
setError("Failed to fetch data.");
});
}else{
if (!masterFeatures.length) setMasterFeatures(features_cache);
}
} catch (err) {
setError("Failed to fetch data.");
} finally {
setLoading(false);
}
};
// useEffect(()=>{
// fetchData();
// },[])
useEffect(()=>{
fetchData();
},[])
// return{masterFeatures,loading}
// }
// -----------------Query- -------------------------
export const useFeatures = () => {
const {data=[],isLoading,error} = useQuery({
queryKey: ["masterFeatures"],
queryFn: async () => {
const response = await MasterRespository.getFeatures();
return response.data;
},
} );
return {
masterFeatures:data,loading:isLoading,error
}
};
return{masterFeatures,loading}
}

View File

@ -360,8 +360,7 @@ export const useCreateProject = ({ onSuccessCallback }) => {
},
onSuccess: (data) => {
// Invalidate the cache
queryClient.invalidateQueries( {queryKey: [ 'ProjectsList' ]} );
queryClient.invalidateQueries({queryKey:['basicProjectNameList']});
queryClient.invalidateQueries(['ProjectsList']);
// Emit event for consumers (like useProjects or others)
eventBus.emit("project", {
@ -398,9 +397,8 @@ export const useUpdateProject = ({ onSuccessCallback }) => {
{
const { projectId } = variables;
queryClient.invalidateQueries({queryKey:["ProjectsList"]});
queryClient.invalidateQueries( {queryKey: [ "projectinfo", projectId ]} );
queryClient.invalidateQueries({queryKey:['basicProjectNameList']});
queryClient.invalidateQueries(["ProjectsList"]);
queryClient.invalidateQueries(["projectinfo", projectId]);
eventBus.emit("project", {
keyword: "Update_Project",
@ -439,7 +437,7 @@ export const useManageProjectInfra = ( {onSuccessCallback} ) =>
onSuccess: ( data, variables ) =>
{
const { projectId } = variables;
queryClient.invalidateQueries({queryKey:["ProjectInfra", projectId]});
queryClient.invalidateQueries(["ProjectInfra", projectId]);
if (onSuccessCallback) onSuccessCallback(data,variables);
},
onError: (error) => {
@ -467,7 +465,7 @@ export const useManageProjectAllocation = ({
return response.data;
},
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({queryKey:['empListByProjectAllocated']});
queryClient.invalidateQueries(['empListByProjectAllocated']);
if (variables?.added) {
showToast('Employee Assigned Successfully', 'success');
@ -501,7 +499,7 @@ export const useManageTask = ({onSuccessCallback}) =>
mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ),
onSuccess: ( data, variables ) =>
{
queryClient.invalidateQueries({ queryKey: ["WorkItems"] })
queryClient.invalidateQueries(["WorkItems"])
if (onSuccessCallback) onSuccessCallback(data);
},
onError: (error) =>
@ -525,7 +523,7 @@ export const useDeleteProjectTask = (onSuccessCallback) => {
onSuccess: ( _, variables ) =>
{
showToast("Task deleted successfully", "success");
queryClient.invalidateQueries({queryKey:[ "WorkItems",variables.workAreaId]});
queryClient.invalidateQueries([ "WorkItems",variables.workAreaId]);
if (onSuccessCallback) onSuccessCallback();
},
onError: (error) => {

View File

@ -178,7 +178,7 @@ export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
},
onSuccess: ( _, variables ) =>
{
queryClient.invalidateQueries({queryKey:["taskList"]});
queryClient.invalidateQueries(["taskList"]);
showToast( "Task Assigned Successfully.", "success" );
if (onSuccessCallback) onSuccessCallback(variables);
},

View File

@ -39,7 +39,7 @@ const EmployeeList = () => {
const { employees, loading, setLoading, error, recallEmployeeData } =
useEmployeesAllOrByProjectId(
showAllEmployees ? null : selectedProjectId,
showAllEmployees ? null : selectedProjectId, // Use selectedProjectId here
showInactive
);
@ -68,18 +68,25 @@ const EmployeeList = () => {
const navigate = useNavigate();
/**
* Applies the search filter to a given array of employee data.
* @param {Array} data - The array of employee objects to filter.
* @param {string} text - The search text.
* @returns {Array} The filtered array.
*/
const applySearchFilter = (data, text) => {
if (!text) {
return data;
}
const lowercasedText = text.toLowerCase().trim();
const lowercasedText = text.toLowerCase().trim(); // Ensure search text is trimmed and lowercase
return data.filter((item) => {
// **IMPROVED FULL NAME CONSTRUCTION**
const firstName = item.firstName || "";
const middleName = item.middleName || "";
const lastName = item.lastName || "";
// Join parts, then trim any excess spaces if a middle name is missing
const fullName = `${firstName} ${middleName} ${lastName}`.toLowerCase().trim().replace(/\s+/g, ' ');
const email = item.email ? item.email.toLowerCase() : "";